• Home
  • Raw
  • Download

Lines Matching refs:handle

396 static void destroy_ring(pcap_t *handle);
397 static int create_ring(pcap_t *handle, int *status);
398 static int prepare_tpacket_socket(pcap_t *handle);
474 static int enter_rfmon_mode(pcap_t *handle, int sock_fd,
478 static int iface_ethtool_get_ts_info(const char *device, pcap_t *handle,
482 static int iface_get_offload(pcap_t *handle);
487 static int fix_program(pcap_t *handle, struct sock_fprog *fcode,
490 static int set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode);
491 static int reset_kernel_filter(pcap_t *handle);
502 pcap_t *handle; in pcap_create_interface() local
504 handle = pcap_create_common(ebuf, sizeof (struct pcap_linux)); in pcap_create_interface()
505 if (handle == NULL) in pcap_create_interface()
508 handle->activate_op = pcap_activate_linux; in pcap_create_interface()
509 handle->can_set_rfmon_op = pcap_can_set_rfmon_linux; in pcap_create_interface()
515 if (iface_ethtool_get_ts_info(device, handle, ebuf) == -1) { in pcap_create_interface()
516 pcap_close(handle); in pcap_create_interface()
530 handle->tstamp_precision_count = 2; in pcap_create_interface()
531 handle->tstamp_precision_list = malloc(2 * sizeof(u_int)); in pcap_create_interface()
532 if (handle->tstamp_precision_list == NULL) { in pcap_create_interface()
535 pcap_close(handle); in pcap_create_interface()
538 handle->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO; in pcap_create_interface()
539 handle->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO; in pcap_create_interface()
542 return handle; in pcap_create_interface()
595 get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path, in get_mac80211_phydev() argument
605 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in get_mac80211_phydev()
620 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in get_mac80211_phydev()
670 nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device) in nl80211_init() argument
676 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in nl80211_init()
682 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in nl80211_init()
689 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in nl80211_init()
697 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in nl80211_init()
720 del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
724 add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, argument
727 struct pcap_linux *handlep = handle->priv;
732 ifindex = iface_get_id(sock_fd, device, handle->errbuf);
738 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
770 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
798 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
816 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
821 del_mon_if(handle, sock_fd, state, device, mondevice);
827 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
835 del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state, argument
842 ifindex = iface_get_id(sock_fd, mondevice, handle->errbuf);
848 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
859 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
867 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
881 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
889 enter_rfmon_mode_mac80211(pcap_t *handle, int sock_fd, const char *device) argument
891 struct pcap_linux *handlep = handle->priv;
901 ret = get_mac80211_phydev(handle, device, phydev_path, PATH_MAX);
917 ret = nl80211_init(handle, &nlstate, device);
927 ret = add_mon_if(handle, sock_fd, &nlstate, device, mondevice);
945 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
965 if (!pcap_do_addexit(handle)) {
970 del_mon_if(handle, sock_fd, &nlstate, device,
982 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
985 del_mon_if(handle, sock_fd, &nlstate, device,
992 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
995 del_mon_if(handle, sock_fd, &nlstate, device,
1015 pcap_add_to_pcaps_to_close(handle);
1052 static int pcap_protocol(pcap_t *handle) argument
1056 protocol = handle->opt.protocol;
1064 pcap_can_set_rfmon_linux(pcap_t *handle) argument
1075 if (strcmp(handle->opt.device, "any") == 0) {
1095 ret = get_mac80211_phydev(handle, handle->opt.device, phydev_path,
1114 sock_fd = socket(PF_PACKET, SOCK_RAW, pcap_protocol(handle));
1116 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1121 if (is_bonding_device(sock_fd, handle->opt.device)) {
1130 strlcpy(ireq.ifr_ifrn.ifrn_name, handle->opt.device,
1141 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1224 static void pcap_cleanup_linux( pcap_t *handle ) argument
1226 struct pcap_linux *handlep = handle->priv;
1255 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
1268 if (ioctl(handle->fd, SIOCSIFFLAGS,
1283 ret = nl80211_init(handle, &nlstate, handlep->device);
1285 ret = del_mon_if(handle, handle->fd, &nlstate,
1293 handlep->mondevice, handle->errbuf);
1319 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) != -1) {
1323 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1)
1334 if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) {
1350 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1) {
1364 pcap_remove_from_pcaps_to_close(handle);
1375 pcap_cleanup_live_common(handle);
1475 pcap_activate_linux(pcap_t *handle) argument
1477 struct pcap_linux *handlep = handle->priv;
1483 device = handle->opt.device;
1509 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
1510 handle->snapshot = MAXIMUM_SNAPLEN;
1512 handle->inject_op = pcap_inject_linux;
1513 handle->setfilter_op = pcap_setfilter_linux;
1514 handle->setdirection_op = pcap_setdirection_linux;
1515 handle->set_datalink_op = pcap_set_datalink_linux;
1516 handle->getnonblock_op = pcap_getnonblock_fd;
1517 handle->setnonblock_op = pcap_setnonblock_fd;
1518 handle->cleanup_op = pcap_cleanup_linux;
1519 handle->read_op = pcap_read_linux;
1520 handle->stats_op = pcap_stats_linux;
1528 if (handle->opt.promisc) {
1529 handle->opt.promisc = 0;
1531 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1539 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1545 handlep->timeout = handle->opt.timeout;
1552 if (handle->opt.promisc)
1564 ret = activate_new(handle);
1579 switch (activate_mmap(handle, &status)) {
1615 if ((ret = activate_old(handle)) != 1) {
1629 if (handle->opt.buffer_size != 0) {
1633 if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
1634 &handle->opt.buffer_size,
1635 sizeof(handle->opt.buffer_size)) == -1) {
1636 pcap_fmt_errmsg_for_errno(handle->errbuf,
1645 handle->buffer = malloc(handle->bufsize + handle->offset);
1646 if (!handle->buffer) {
1647 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1657 handle->selectable_fd = handle->fd;
1662 pcap_cleanup_linux(handle);
1672 pcap_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *user) argument
1678 return pcap_read_packet(handle, callback, user);
1682 pcap_set_datalink_linux(pcap_t *handle, int dlt) argument
1684 handle->linktype = dlt;
1694 linux_check_direction(const pcap_t *handle, const struct sockaddr_ll *sll) argument
1696 struct pcap_linux *handlep = handle->priv;
1721 handle->direction != PCAP_D_OUT)
1727 if (handle->direction == PCAP_D_IN)
1734 if (handle->direction == PCAP_D_OUT)
1746 pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) argument
1748 struct pcap_linux *handlep = handle->priv;
1804 bp = (u_char *)handle->buffer + handle->offset;
1815 iov.iov_len = handle->bufsize - offset;
1823 if (handle->break_loop) {
1829 handle->break_loop = 0;
1834 packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC);
1838 handle->fd, bp + offset,
1839 handle->bufsize - offset, MSG_TRUNC,
1860 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1865 pcap_fmt_errmsg_for_errno(handle->errbuf,
1895 if (!linux_check_direction(handle, &from))
2024 if (caplen > handle->snapshot)
2025 caplen = handle->snapshot;
2028 if (handlep->filter_in_userland && handle->fcode.bf_insns) {
2029 if (bpf_filter_with_aux_data(handle->fcode.bf_insns, bp,
2040 if (handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) {
2041 if (ioctl(handle->fd, SIOCGSTAMPNS, &pcap_header.ts) == -1) {
2042 pcap_fmt_errmsg_for_errno(handle->errbuf,
2049 if (ioctl(handle->fd, SIOCGSTAMP, &pcap_header.ts) == -1) {
2050 pcap_fmt_errmsg_for_errno(handle->errbuf,
2112 pcap_inject_linux(pcap_t *handle, const void *buf, size_t size) argument
2114 struct pcap_linux *handlep = handle->priv;
2124 strlcpy(handle->errbuf,
2138 strlcpy(handle->errbuf,
2146 ret = send(handle->fd, buf, size, 0);
2148 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2164 pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats) argument
2166 struct pcap_linux *handlep = handle->priv;
2195 if (handle->opt.promisc)
2206 if (getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS,
2270 pcap_fmt_errmsg_for_errno(handle->errbuf,
2826 pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter, argument
2836 if (!handle)
2839 strlcpy(handle->errbuf, "setfilter: No filter specified",
2844 handlep = handle->priv;
2848 if (install_bpf_program(handle, filter) < 0)
2862 if (handle->fcode.bf_len > USHRT_MAX) {
2890 switch (fix_program(handle, &fcode, is_mmapped)) {
2943 if ((err = set_kernel_filter(handle, &fcode)) == 0)
2975 if (reset_kernel_filter(handle) == -1) {
2976 pcap_fmt_errmsg_for_errno(handle->errbuf,
2998 pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter) argument
3000 return pcap_setfilter_linux_common(handle, filter, 0);
3009 pcap_setdirection_linux(pcap_t *handle, pcap_direction_t d) argument
3012 struct pcap_linux *handlep = handle->priv;
3015 handle->direction = d;
3023 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3126 static void map_arphrd_to_dlt(pcap_t *handle, int sock_fd, int arptype, argument
3147 handle->linktype = DLT_RAW;
3173 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
3177 if (handle->dlt_list != NULL) {
3178 handle->dlt_list[0] = DLT_EN10MB;
3179 handle->dlt_list[1] = DLT_DOCSIS;
3180 handle->dlt_count = 2;
3187 handle->linktype = DLT_EN10MB;
3188 handle->offset = 2;
3192 handle->linktype = DLT_EN3MB;
3196 handle->linktype = DLT_AX25_KISS;
3200 handle->linktype = DLT_PRONET;
3204 handle->linktype = DLT_CHAOS;
3217 handle->linktype = DLT_LINUX_SLL;
3225 handle->linktype = DLT_IEEE802;
3226 handle->offset = 2;
3230 handle->linktype = DLT_ARCNET_LINUX;
3237 handle->linktype = DLT_FDDI;
3238 handle->offset = 3;
3282 handle->linktype = DLT_LINUX_SLL;
3284 handle->linktype = -1;
3291 handle->linktype = DLT_IEEE802_11;
3298 handle->linktype = DLT_PRISM_HEADER;
3305 handle->linktype = DLT_IEEE802_11_RADIO;
3329 handle->linktype = DLT_LINUX_SLL;
3347 handle->linktype = DLT_RAW;
3355 handle->linktype = DLT_C_HDLC;
3382 handle->linktype = DLT_RAW;
3389 handle->linktype = DLT_FRELAY;
3393 handle->linktype = DLT_LTALK;
3412 handle->linktype = DLT_IP_OVER_FC;
3477 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 3);
3481 if (handle->dlt_list != NULL) {
3482 handle->dlt_list[0] = DLT_FC_2;
3483 handle->dlt_list[1] = DLT_FC_2_WITH_FRAME_DELIMS;
3484 handle->dlt_list[2] = DLT_IP_OVER_FC;
3485 handle->dlt_count = 3;
3487 handle->linktype = DLT_FC_2;
3495 handle->linktype = DLT_LINUX_IRDA;
3510 handle->linktype = DLT_LINUX_LAPD;
3521 handle->linktype = DLT_RAW;
3528 handle->linktype = DLT_IEEE802_15_4_NOFCS;
3535 handle->linktype = DLT_NETLINK;
3550 handle->linktype = DLT_VSOCK;
3554 handle->linktype = -1;
3569 activate_new(pcap_t *handle) argument
3572 struct pcap_linux *handlep = handle->priv;
3573 const char *device = handle->opt.device;
3575 int protocol = pcap_protocol(handle);
3606 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3636 handlep->lo_ifindex = iface_get_id(sock_fd, "lo", handle->errbuf);
3642 handle->offset = 0;
3653 if (handle->opt.rfmon) {
3660 err = enter_rfmon_mode(handle, sock_fd, device);
3684 arptype = iface_get_arptype(sock_fd, device, handle->errbuf);
3689 map_arphrd_to_dlt(handle, sock_fd, arptype, device, 1);
3690 if (handle->linktype == -1 ||
3691 handle->linktype == DLT_LINUX_SLL ||
3692 handle->linktype == DLT_LINUX_IRDA ||
3693 handle->linktype == DLT_LINUX_LAPD ||
3694 handle->linktype == DLT_NETLINK ||
3695 (handle->linktype == DLT_EN10MB &&
3708 pcap_fmt_errmsg_for_errno(handle->errbuf,
3714 pcap_fmt_errmsg_for_errno(handle->errbuf,
3736 if (handle->dlt_list != NULL) {
3737 free(handle->dlt_list);
3738 handle->dlt_list = NULL;
3739 handle->dlt_count = 0;
3742 if (handle->linktype == -1) {
3749 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3762 if (handle->linktype != DLT_LINUX_IRDA &&
3763 handle->linktype != DLT_LINUX_LAPD &&
3764 handle->linktype != DLT_NETLINK)
3765 handle->linktype = DLT_LINUX_SLL;
3769 handle->errbuf);
3776 handle->errbuf, protocol)) != 1) {
3787 if (handle->opt.rfmon) {
3799 handle->linktype = DLT_LINUX_SLL;
3833 if (!is_any_device && handle->opt.promisc) {
3839 pcap_fmt_errmsg_for_errno(handle->errbuf,
3852 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3857 handle->offset += VLAN_TAG_LEN;
3875 if (handle->snapshot < SLL_HDR_LEN + 1)
3876 handle->snapshot = SLL_HDR_LEN + 1;
3878 handle->bufsize = handle->snapshot;
3884 switch (handle->linktype) {
3908 if (handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) {
3912 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "setsockopt: unable to set SO_TIMESTAMPNS");
3922 handle->fd = sock_fd;
3936 handle->bpf_codegen_flags |= BPF_SPECIAL_VLAN_HANDLING;
3964 activate_mmap(pcap_t *handle, int *status) argument
3966 struct pcap_linux *handlep = handle->priv;
3973 handlep->oneshot_buffer = malloc(handle->snapshot);
3975 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3981 if (handle->opt.buffer_size == 0) {
3983 handle->opt.buffer_size = 2*1024*1024;
3985 ret = prepare_tpacket_socket(handle);
3991 ret = create_ring(handle, status);
4021 handle->read_op = pcap_read_linux_mmap_v1;
4024 handle->read_op = pcap_read_linux_mmap_v1_64;
4028 handle->read_op = pcap_read_linux_mmap_v2;
4033 handle->read_op = pcap_read_linux_mmap_v3;
4037 handle->cleanup_op = pcap_cleanup_linux_mmap;
4038 handle->setfilter_op = pcap_setfilter_linux_mmap;
4039 handle->setnonblock_op = pcap_setnonblock_mmap;
4040 handle->getnonblock_op = pcap_getnonblock_mmap;
4041 handle->oneshot_callback = pcap_oneshot_mmap;
4042 handle->selectable_fd = handle->fd;
4047 activate_mmap(pcap_t *handle _U_, int *status _U_)
4064 init_tpacket(pcap_t *handle, int version, const char *version_str) argument
4066 struct pcap_linux *handlep = handle->priv;
4074 if (getsockopt(handle->fd, SOL_PACKET, PACKET_HDRLEN, &val, &len) < 0) {
4079 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4087 if (setsockopt(handle->fd, SOL_PACKET, PACKET_VERSION, &val,
4089 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4097 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, &val,
4099 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4148 prepare_tpacket_socket(pcap_t *handle) argument
4150 struct pcap_linux *handlep = handle->priv;
4167 if (!handle->opt.immediate) {
4168 ret = init_tpacket(handle, TPACKET_V3, "TPACKET_V3");
4189 ret = init_tpacket(handle, TPACKET_V2, "TPACKET_V2");
4230 pcap_fmt_errmsg_for_errno(handle->errbuf,
4267 create_ring(pcap_t *handle, int *status) argument
4269 struct pcap_linux *handlep = handle->priv;
4328 frame_size = handle->snapshot;
4329 if (handle->linktype == DLT_EN10MB) {
4334 mtu = iface_get_mtu(handle->fd, handle->opt.device,
4335 handle->errbuf);
4340 offload = iface_get_offload(handle);
4359 if (getsockopt(handle->fd, SOL_SOCKET, SO_TYPE, &sk_type,
4361 pcap_fmt_errmsg_for_errno(handle->errbuf,
4368 if (getsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE,
4376 pcap_fmt_errmsg_for_errno(handle->errbuf,
4423 req.tp_frame_nr = (handle->opt.buffer_size + req.tp_frame_size - 1)/req.tp_frame_size;
4442 req.tp_frame_nr = (handle->opt.buffer_size + req.tp_frame_size - 1)/req.tp_frame_size;
4446 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4484 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER ||
4485 handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER_UNSYNCED) {
4499 strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
4502 if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) {
4536 pcap_fmt_errmsg_for_errno(handle->errbuf,
4548 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER) {
4562 if (setsockopt(handle->fd, SOL_PACKET, PACKET_TIMESTAMP,
4564 pcap_fmt_errmsg_for_errno(handle->errbuf,
4590 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
4614 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4623 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
4625 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4629 destroy_ring(handle);
4635 handle->cc = req.tp_frame_nr;
4636 handle->buffer = malloc(handle->cc * sizeof(union thdr *));
4637 if (!handle->buffer) {
4638 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4641 destroy_ring(handle);
4647 handle->offset = 0;
4650 for (j=0; j<frames_per_block; ++j, ++handle->offset) {
4651 RING_GET_CURRENT_FRAME(handle) = base;
4656 handle->bufsize = req.tp_frame_size;
4657 handle->offset = 0;
4663 destroy_ring(pcap_t *handle) argument
4665 struct pcap_linux *handlep = handle->priv;
4671 (void)setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
4704 pcap_t *handle = sp->pd; local
4705 struct pcap_linux *handlep = handle->priv;
4713 pcap_cleanup_linux_mmap( pcap_t *handle ) argument
4715 struct pcap_linux *handlep = handle->priv;
4717 destroy_ring(handle);
4722 pcap_cleanup_linux(handle);
4727 pcap_getnonblock_mmap(pcap_t *handle) argument
4729 struct pcap_linux *handlep = handle->priv;
4736 pcap_setnonblock_mmap(pcap_t *handle, int nonblock) argument
4738 struct pcap_linux *handlep = handle->priv;
4744 if (pcap_setnonblock_fd(handle, nonblock) == -1)
4773 pcap_get_ring_frame_status(pcap_t *handle, int offset) argument
4775 struct pcap_linux *handlep = handle->priv;
4778 h.raw = RING_GET_FRAME_AT(handle, offset);
4808 static int pcap_wait_for_frames_mmap(pcap_t *handle) argument
4810 struct pcap_linux *handlep = handle->priv;
4815 pollinfo.fd = handle->fd;
4829 pcap_fmt_errmsg_for_errno(handle->errbuf,
4841 pcap_snprintf(handle->errbuf,
4852 if (recv(handle->fd, &c, sizeof c,
4865 pcap_snprintf(handle->errbuf,
4869 pcap_fmt_errmsg_for_errno(handle->errbuf,
4876 pcap_snprintf(handle->errbuf,
4883 if (handle->break_loop) {
4884 handle->break_loop = 0;
4893 pcap_t *handle, argument
4906 struct pcap_linux *handlep = handle->priv;
4913 if (tp_mac + tp_snaplen > handle->bufsize) {
4914 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4917 tp_mac, tp_snaplen, handle->bufsize);
4956 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4975 if (handlep->filter_in_userland && handle->fcode.bf_insns) {
4981 if (bpf_filter_with_aux_data(handle->fcode.bf_insns,
4989 if (!linux_check_direction(handle, sll))
5044 if (pcaphdr.caplen > (bpf_u_int32)handle->snapshot)
5045 pcaphdr.caplen = handle->snapshot;
5054 pcap_read_linux_mmap_v1(pcap_t *handle, int max_packets, pcap_handler callback, argument
5057 struct pcap_linux *handlep = handle->priv;
5063 h.raw = RING_GET_CURRENT_FRAME(handle);
5069 ret = pcap_wait_for_frames_mmap(handle);
5082 h.raw = RING_GET_CURRENT_FRAME(handle);
5087 handle,
5125 if (++handle->offset >= handle->cc)
5126 handle->offset = 0;
5129 if (handle->break_loop) {
5130 handle->break_loop = 0;
5138 pcap_read_linux_mmap_v1_64(pcap_t *handle, int max_packets, pcap_handler callback, argument
5141 struct pcap_linux *handlep = handle->priv;
5147 h.raw = RING_GET_CURRENT_FRAME(handle);
5153 ret = pcap_wait_for_frames_mmap(handle);
5166 h.raw = RING_GET_CURRENT_FRAME(handle);
5171 handle,
5209 if (++handle->offset >= handle->cc)
5210 handle->offset = 0;
5213 if (handle->break_loop) {
5214 handle->break_loop = 0;
5223 pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback, argument
5226 struct pcap_linux *handlep = handle->priv;
5232 h.raw = RING_GET_CURRENT_FRAME(handle);
5238 ret = pcap_wait_for_frames_mmap(handle);
5251 h.raw = RING_GET_CURRENT_FRAME(handle);
5256 handle,
5264handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? h.h2->tp_nsec : h.h2->tp_nsec / 1000,
5294 if (++handle->offset >= handle->cc)
5295 handle->offset = 0;
5298 if (handle->break_loop) {
5299 handle->break_loop = 0;
5309 pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback, argument
5312 struct pcap_linux *handlep = handle->priv;
5320 h.raw = RING_GET_CURRENT_FRAME(handle);
5326 ret = pcap_wait_for_frames_mmap(handle);
5332 h.raw = RING_GET_CURRENT_FRAME(handle);
5347 h.raw = RING_GET_CURRENT_FRAME(handle);
5367 while (packets_to_read-- && !handle->break_loop) {
5370 handle,
5378handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? tp3_hdr->tp_nsec : tp3_hdr->tp_nsec /…
5414 if (++handle->offset >= handle->cc)
5415 handle->offset = 0;
5421 if (handle->break_loop) {
5422 handle->break_loop = 0;
5435 pcap_setfilter_linux_mmap(pcap_t *handle, struct bpf_program *filter) argument
5437 struct pcap_linux *handlep = handle->priv;
5447 ret = pcap_setfilter_linux_common(handle, filter, 1);
5467 offset = handle->offset;
5469 offset = handle->cc - 1;
5470 for (n=0; n < handle->cc; ++n) {
5472 offset = handle->cc - 1;
5473 if (pcap_get_ring_frame_status(handle, offset) != TP_STATUS_KERNEL)
5505 handlep->blocks_to_filter_in_userland = handle->cc - n;
5650 enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device) argument
5710 struct pcap_linux *handlep = handle->priv;
5725 err = has_wext(sock_fd, device, handle->errbuf);
5752 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5765 pcap_fmt_errmsg_for_errno(handle->errbuf,
5775 pcap_fmt_errmsg_for_errno(handle->errbuf,
5781 pcap_fmt_errmsg_for_errno(handle->errbuf,
5976 if (!pcap_do_addexit(handle)) {
6019 pcap_add_to_pcaps_to_close(handle);
6036 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
6045 pcap_fmt_errmsg_for_errno(handle->errbuf,
6065 pcap_fmt_errmsg_for_errno(handle->errbuf,
6150 pcap_fmt_errmsg_for_errno(handle->errbuf,
6226 pcap_fmt_errmsg_for_errno(handle->errbuf,
6234 if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) {
6256 pcap_add_to_pcaps_to_close(handle);
6266 enter_rfmon_mode(pcap_t *handle, int sock_fd, const char *device) argument
6273 ret = enter_rfmon_mode_mac80211(handle, sock_fd, device);
6281 ret = enter_rfmon_mode_wext(handle, sock_fd, device);
6314 iface_set_all_ts_types(pcap_t *handle) argument
6318 handle->tstamp_type_count = NUM_SOF_TIMESTAMPING_TYPES;
6319 handle->tstamp_type_list = malloc(NUM_SOF_TIMESTAMPING_TYPES * sizeof(u_int));
6321 handle->tstamp_type_list[i] = sof_ts_type_map[i].pcap_tstamp_val;
6329 iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf) argument
6345 handle->tstamp_type_list = NULL;
6377 iface_set_all_ts_types(handle);
6387 handle->tstamp_type_list = NULL;
6416 handle->tstamp_type_list = NULL;
6425 handle->tstamp_type_count = num_ts_types;
6427 handle->tstamp_type_list = malloc(num_ts_types * sizeof(u_int));
6430 handle->tstamp_type_list[j] = sof_ts_type_map[i].pcap_tstamp_val;
6435 handle->tstamp_type_list = NULL;
6441 iface_ethtool_get_ts_info(const char *device, pcap_t *handle, char *ebuf _U_) argument
6451 handle->tstamp_type_list = NULL;
6459 iface_set_all_ts_types(handle);
6477 iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname) argument
6483 strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
6487 if (ioctl(handle->fd, SIOCETHTOOL, &ifr) == -1) {
6497 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
6499 handle->opt.device, cmdname);
6506 iface_get_offload(pcap_t *handle) argument
6511 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GTSO, "ETHTOOL_GTSO");
6519 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GUFO, "ETHTOOL_GUFO");
6532 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGSO, "ETHTOOL_GGSO");
6540 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
6553 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGRO, "ETHTOOL_GGRO");
6564 iface_get_offload(pcap_t *handle _U_)
6585 activate_old(pcap_t *handle) argument
6587 struct pcap_linux *handlep = handle->priv;
6591 const char *device = handle->opt.device;
6597 handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
6598 if (handle->fd == -1) {
6600 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
6625 …strlcpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel syste…
6629 if (iface_bind_old(handle->fd, device, handle->errbuf) == -1)
6635 arptype = iface_get_arptype(handle->fd, device, handle->errbuf);
6643 map_arphrd_to_dlt(handle, handle->fd, arptype, device, 0);
6644 if (handle->linktype == -1) {
6645 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
6652 if (handle->opt.promisc) {
6655 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
6656 pcap_fmt_errmsg_for_errno(handle->errbuf,
6673 if (!pcap_do_addexit(handle)) {
6683 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1) {
6684 pcap_fmt_errmsg_for_errno(handle->errbuf,
6694 pcap_add_to_pcaps_to_close(handle);
6748 mtu = iface_get_mtu(handle->fd, device, handle->errbuf);
6751 handle->bufsize = MAX_LINKHEADER_SIZE + mtu;
6752 if (handle->bufsize < (u_int)handle->snapshot)
6753 handle->bufsize = (u_int)handle->snapshot;
6761 handle->bufsize = (u_int)handle->snapshot;
6768 handle->offset = 0;
6869 fix_program(pcap_t *handle, struct sock_fprog *fcode, int is_mmapped) argument
6871 struct pcap_linux *handlep = handle->priv;
6882 prog_size = sizeof(*handle->fcode.bf_insns) * handle->fcode.bf_len;
6883 len = handle->fcode.bf_len;
6886 pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
6890 memcpy(f, handle->fcode.bf_insns, prog_size);
7008 set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode) argument
7046 if (setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
7061 save_mode = fcntl(handle->fd, F_GETFL, 0);
7063 pcap_fmt_errmsg_for_errno(handle->errbuf,
7068 if (fcntl(handle->fd, F_SETFL, save_mode | O_NONBLOCK) < 0) {
7069 pcap_fmt_errmsg_for_errno(handle->errbuf,
7074 while (recv(handle->fd, &drain, sizeof drain, MSG_TRUNC) >= 0)
7084 (void)fcntl(handle->fd, F_SETFL, save_mode);
7085 (void)reset_kernel_filter(handle);
7086 pcap_fmt_errmsg_for_errno(handle->errbuf,
7091 if (fcntl(handle->fd, F_SETFL, save_mode) == -1) {
7092 pcap_fmt_errmsg_for_errno(handle->errbuf,
7102 ret = setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
7122 if (reset_kernel_filter(handle) == -1) {
7123 pcap_fmt_errmsg_for_errno(handle->errbuf,
7135 reset_kernel_filter(pcap_t *handle) argument
7146 ret = setsockopt(handle->fd, SOL_SOCKET, SO_DETACH_FILTER,