Lines Matching full:handle
247 static void destroy_ring(pcap_t *handle);
248 static int create_ring(pcap_t *handle);
249 static int prepare_tpacket_socket(pcap_t *handle);
320 static int enter_rfmon_mode(pcap_t *handle, int sock_fd,
322 static int iface_get_ts_types(const char *device, pcap_t *handle,
324 static int iface_get_offload(pcap_t *handle);
326 static int fix_program(pcap_t *handle, struct sock_fprog *fcode);
327 static int fix_offset(pcap_t *handle, struct bpf_insn *p);
328 static int set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode);
329 static int reset_kernel_filter(pcap_t *handle);
336 static int iface_dsa_get_proto_info(const char *device, pcap_t *handle);
341 pcap_t *handle;
343 handle = PCAP_CREATE_COMMON(ebuf, struct pcap_linux);
344 if (handle == NULL)
347 handle->activate_op = pcap_activate_linux;
348 handle->can_set_rfmon_op = pcap_can_set_rfmon_linux;
353 if (iface_get_ts_types(device, handle, ebuf) == -1) {
354 pcap_close(handle);
366 handle->tstamp_precision_list = malloc(2 * sizeof(u_int));
367 if (handle->tstamp_precision_list == NULL) {
370 pcap_close(handle);
373 handle->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
374 handle->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
375 handle->tstamp_precision_count = 2;
378 * Start out with the breakloop handle not open; we don't
381 struct pcap_linux *handlep = handle->priv;
384 return handle;
439 * return 1; if not, return 0. On an error, fill in handle->errbuf and
443 get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path,
453 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
468 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
485 nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device)
491 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
492 "%s: failed to allocate netlink handle", device);
497 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
504 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
512 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
535 del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
539 add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
542 struct pcap_linux *handlep = handle->priv;
547 ifindex = iface_get_id(sock_fd, device, handle->errbuf);
553 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
583 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
607 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
625 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
630 del_mon_if(handle, sock_fd, state, device, mondevice);
636 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
644 del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
651 ifindex = iface_get_id(sock_fd, mondevice, handle->errbuf);
657 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
668 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
676 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
690 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
698 static int pcap_protocol(pcap_t *handle)
702 protocol = handle->opt.protocol;
710 pcap_can_set_rfmon_linux(pcap_t *handle)
717 if (strcmp(handle->opt.device, "any") == 0) {
732 ret = get_mac80211_phydev(handle, handle->opt.device, phydev_path,
790 static void pcap_cleanup_linux( pcap_t *handle )
792 struct pcap_linux *handlep = handle->priv;
805 ret = nl80211_init(handle, &nlstate, handlep->device);
807 ret = del_mon_if(handle, handle->fd, &nlstate,
815 handlep->mondevice, handle->errbuf);
824 pcapint_remove_from_pcaps_to_close(handle);
827 if (handle->fd != -1) {
832 destroy_ring(handle);
853 pcapint_cleanup_live_common(handle);
944 static void pcap_breakloop_linux(pcap_t *handle)
946 pcapint_breakloop_common(handle);
947 struct pcap_linux *handlep = handle->priv;
967 set_vlan_offset(pcap_t *handle)
969 struct pcap_linux *handlep = handle->priv;
971 switch (handle->linktype) {
996 * Get a handle for a live capture from the given device. You can
1004 pcap_activate_linux(pcap_t *handle)
1006 struct pcap_linux *handlep = handle->priv;
1013 device = handle->opt.device;
1036 handle->errbuf[0] = '\0';
1049 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
1050 handle->snapshot = MAXIMUM_SNAPLEN;
1054 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1067 if (handle->opt.promisc) {
1068 handle->opt.promisc = 0;
1070 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1077 handlep->timeout = handle->opt.timeout;
1085 if (handle->opt.promisc)
1092 ret = setup_socket(handle, is_any_device);
1096 * and handle->errbuf has been set to an appropriate
1104 * We got a warning; return that, as handle->errbuf
1116 if (!handle->opt.nonblock) {
1122 pcapint_fmt_errmsg_for_errno(handle->errbuf,
1133 ret = setup_mmapped(handle);
1140 * PCAP_ERROR, handle->errbuf contains
1148 * We got a warning; return that, as handle->errbuf
1162 if ((ret = iface_bind(handle->fd, handlep->ifindex,
1163 handle->errbuf, pcap_protocol(handle))) != 0) {
1168 handle->inject_op = pcap_inject_linux;
1169 handle->setfilter_op = pcap_setfilter_linux;
1170 handle->setdirection_op = pcap_setdirection_linux;
1171 handle->set_datalink_op = pcap_set_datalink_linux;
1172 handle->setnonblock_op = pcap_setnonblock_linux;
1173 handle->getnonblock_op = pcap_getnonblock_linux;
1174 handle->cleanup_op = pcap_cleanup_linux;
1175 handle->stats_op = pcap_stats_linux;
1176 handle->breakloop_op = pcap_breakloop_linux;
1181 handle->read_op = pcap_read_linux_mmap_v2;
1185 handle->read_op = pcap_read_linux_mmap_v3;
1189 handle->oneshot_callback = pcapint_oneshot_linux;
1190 handle->selectable_fd = handle->fd;
1195 pcap_cleanup_linux(handle);
1200 pcap_set_datalink_linux(pcap_t *handle, int dlt)
1202 handle->linktype = dlt;
1208 set_vlan_offset(handle);
1219 linux_check_direction(const pcap_t *handle, const struct sockaddr_ll *sll)
1221 struct pcap_linux *handlep = handle->priv;
1249 handle->direction != PCAP_D_OUT)
1255 if (handle->direction == PCAP_D_IN)
1262 if (handle->direction == PCAP_D_OUT)
1275 device_still_exists(pcap_t *handle)
1277 struct pcap_linux *handlep = handle->priv;
1294 if (getsockname(handle->fd, (struct sockaddr *) &addr, &addr_len) == -1) {
1298 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1316 pcap_inject_linux(pcap_t *handle, const void *buf, int size)
1318 struct pcap_linux *handlep = handle->priv;
1325 pcapint_strlcpy(handle->errbuf,
1339 pcapint_strlcpy(handle->errbuf,
1345 ret = (int)send(handle->fd, buf, size, 0);
1347 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
1355 * Get the statistics for the given packet capture handle.
1358 pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats)
1360 struct pcap_linux *handlep = handle->priv;
1388 if (handle->opt.promisc)
1399 * One reason might be to handle the count wrapping
1406 * on 32-bit platforms, we can handle the real count.
1426 if (getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS,
1469 * getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS, ....
1478 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, errno,
1816 pcap_setdirection_linux(pcap_t *handle, pcap_direction_t d)
1822 handle->direction = d;
1855 * constant, as arguments, and sets "handle->linktype" to the
1856 * appropriate DLT_XXX constant and sets "handle->offset" to
1857 * the appropriate value (to make "handle->offset" plus link-layer
1871 static int map_arphrd_to_dlt(pcap_t *handle, int arptype,
1892 handle->linktype = DLT_RAW;
1921 ret = iface_dsa_get_proto_info(device, handle);
1932 handle->offset = 2;
1939 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
1940 if (handle->dlt_list == NULL) {
1941 pcapint_fmt_errmsg_for_errno(handle->errbuf,
1945 handle->dlt_list[0] = DLT_EN10MB;
1946 handle->dlt_list[1] = DLT_DOCSIS;
1947 handle->dlt_count = 2;
1953 handle->linktype = DLT_EN10MB;
1954 handle->offset = 2;
1958 handle->linktype = DLT_EN3MB;
1962 handle->linktype = DLT_AX25_KISS;
1966 handle->linktype = DLT_PRONET;
1970 handle->linktype = DLT_CHAOS;
1976 handle->linktype = DLT_CAN_SOCKETCAN;
1984 handle->linktype = DLT_IEEE802;
1985 handle->offset = 2;
1989 handle->linktype = DLT_ARCNET_LINUX;
1996 handle->linktype = DLT_FDDI;
1997 handle->offset = 3;
2041 handle->linktype = DLT_LINUX_SLL;
2043 handle->linktype = -1;
2050 handle->linktype = DLT_IEEE802_11;
2057 handle->linktype = DLT_PRISM_HEADER;
2064 handle->linktype = DLT_IEEE802_11_RADIO;
2088 handle->linktype = DLT_LINUX_SLL;
2091 * XXX - handle ISDN types here? We can't fall
2106 handle->linktype = DLT_RAW;
2114 handle->linktype = DLT_C_HDLC;
2141 handle->linktype = DLT_RAW;
2148 handle->linktype = DLT_FRELAY;
2152 handle->linktype = DLT_LTALK;
2171 handle->linktype = DLT_IP_OVER_FC;
2236 handle->linktype = DLT_FC_2;
2237 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 3);
2238 if (handle->dlt_list == NULL) {
2239 pcapint_fmt_errmsg_for_errno(handle->errbuf,
2243 handle->dlt_list[0] = DLT_FC_2;
2244 handle->dlt_list[1] = DLT_FC_2_WITH_FRAME_DELIMS;
2245 handle->dlt_list[2] = DLT_IP_OVER_FC;
2246 handle->dlt_count = 3;
2254 handle->linktype = DLT_LINUX_IRDA;
2269 handle->linktype = DLT_LINUX_LAPD;
2280 handle->linktype = DLT_RAW;
2287 handle->linktype = DLT_IEEE802_15_4_NOFCS;
2294 handle->linktype = DLT_NETLINK;
2309 handle->linktype = DLT_VSOCK;
2313 handle->linktype = -1;
2325 setup_socket(pcap_t *handle, int is_any_device)
2327 struct pcap_linux *handlep = handle->priv;
2328 const char *device = handle->opt.device;
2360 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2370 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2378 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2394 handlep->lo_ifindex = iface_get_id(sock_fd, "lo", handle->errbuf);
2400 handle->offset = 0;
2411 if (handle->opt.rfmon) {
2418 err = enter_rfmon_mode(handle, sock_fd, device);
2443 arptype = iface_get_arptype(sock_fd, device, handle->errbuf);
2448 status = map_arphrd_to_dlt(handle, arptype, device, 1);
2453 if (handle->linktype == -1 ||
2454 handle->linktype == DLT_LINUX_SLL ||
2455 handle->linktype == DLT_LINUX_IRDA ||
2456 handle->linktype == DLT_LINUX_LAPD ||
2457 handle->linktype == DLT_NETLINK ||
2458 (handle->linktype == DLT_EN10MB &&
2475 pcapint_fmt_errmsg_for_errno(handle->errbuf,
2489 pcapint_fmt_errmsg_for_errno(handle->errbuf,
2500 if (handle->dlt_list != NULL) {
2501 free(handle->dlt_list);
2502 handle->dlt_list = NULL;
2503 handle->dlt_count = 0;
2506 if (handle->linktype == -1) {
2511 * to handle the new type.
2513 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2527 if (handle->linktype != DLT_LINUX_IRDA &&
2528 handle->linktype != DLT_LINUX_LAPD &&
2529 handle->linktype != DLT_NETLINK)
2530 handle->linktype = DLT_LINUX_SLL;
2534 handle->errbuf);
2541 handle->errbuf, 0)) != 0) {
2549 if (handle->opt.rfmon) {
2562 handle->linktype = DLT_LINUX_SLL;
2563 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
2564 if (handle->dlt_list == NULL) {
2565 pcapint_fmt_errmsg_for_errno(handle->errbuf,
2569 handle->dlt_list[0] = DLT_LINUX_SLL;
2570 handle->dlt_list[1] = DLT_LINUX_SLL2;
2571 handle->dlt_count = 2;
2605 if (!is_any_device && handle->opt.promisc) {
2611 pcapint_fmt_errmsg_for_errno(handle->errbuf,
2630 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2635 handle->offset += VLAN_TAG_LEN;
2648 if (handle->snapshot < SLL2_HDR_LEN + 1)
2649 handle->snapshot = SLL2_HDR_LEN + 1;
2651 handle->bufsize = handle->snapshot;
2656 set_vlan_offset(handle);
2658 if (handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) {
2662 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "setsockopt: unable to set SO_TIMESTAMPNS");
2671 handle->fd = sock_fd;
2685 handle->bpf_codegen_flags |= BPF_SPECIAL_VLAN_HANDLING;
2700 * sets handle->errbuf to the appropriate message.
2703 setup_mmapped(pcap_t *handle)
2705 struct pcap_linux *handlep = handle->priv;
2712 handlep->oneshot_buffer = malloc(handle->snapshot);
2714 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2719 if (handle->opt.buffer_size == 0) {
2721 handle->opt.buffer_size = 2*1024*1024;
2723 status = prepare_tpacket_socket(handle);
2729 status = create_ring(handle);
2744 * handle->offset is used to get the current position into the rx ring.
2745 * handle->cc is used to store the ring size.
2761 * supported; return -1 on any other error, and set handle->errbuf.
2764 init_tpacket(pcap_t *handle, int version, const char *version_str)
2766 struct pcap_linux *handlep = handle->priv;
2777 if (getsockopt(handle->fd, SOL_PACKET, PACKET_HDRLEN, &val, &len) < 0) {
2798 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2804 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2813 if (setsockopt(handle->fd, SOL_PACKET, PACKET_VERSION, &val,
2815 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
2829 * Return 0 if we succeed and -1 on any other error, and set handle->errbuf.
2832 prepare_tpacket_socket(pcap_t *handle)
2848 if (!handle->opt.immediate) {
2849 ret = init_tpacket(handle, TPACKET_V3, "TPACKET_V3");
2874 ret = init_tpacket(handle, TPACKET_V2, "TPACKET_V2");
2887 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2906 * sets handle->errbuf to the appropriate message.
2909 create_ring(pcap_t *handle)
2911 struct pcap_linux *handlep = handle->priv;
2961 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE,
2963 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3003 frame_size = handle->snapshot;
3004 if (handle->linktype == DLT_EN10MB) {
3009 mtu = iface_get_mtu(handle->fd, handle->opt.device,
3010 handle->errbuf);
3013 offload = iface_get_offload(handle);
3030 if (getsockopt(handle->fd, SOL_SOCKET, SO_TYPE, &sk_type,
3032 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3073 req.tp_frame_nr = (handle->opt.buffer_size + req.tp_frame_size - 1)/req.tp_frame_size;
3092 req.tp_frame_nr = (handle->opt.buffer_size + req.tp_frame_size - 1)/req.tp_frame_size;
3096 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3102 /* compute the minimum block size that will handle this frame.
3133 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER ||
3134 handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER_UNSYNCED) {
3148 pcapint_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
3154 if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) {
3165 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3189 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3200 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER) {
3214 if (setsockopt(handle->fd, SOL_PACKET, PACKET_TIMESTAMP,
3216 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3260 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
3278 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3286 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
3288 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3292 destroy_ring(handle);
3297 handle->cc = req.tp_frame_nr;
3298 handle->buffer = malloc(handle->cc * sizeof(union thdr *));
3299 if (!handle->buffer) {
3300 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
3303 destroy_ring(handle);
3308 handle->offset = 0;
3311 for (j=0; j<frames_per_block; ++j, ++handle->offset) {
3312 RING_GET_CURRENT_FRAME(handle) = base;
3317 handle->bufsize = req.tp_frame_size;
3318 handle->offset = 0;
3324 destroy_ring(pcap_t *handle)
3326 struct pcap_linux *handlep = handle->priv;
3336 (void)setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
3369 pcap_t *handle = sp->pd;
3370 struct pcap_linux *handlep = handle->priv;
3378 pcap_getnonblock_linux(pcap_t *handle)
3380 struct pcap_linux *handlep = handle->priv;
3387 pcap_setnonblock_linux(pcap_t *handle, int nonblock)
3389 struct pcap_linux *handlep = handle->priv;
3395 if (pcapint_setnonblock_fd(handle, nonblock) == -1)
3425 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3444 pcap_get_ring_frame_status(pcap_t *handle, int offset)
3446 struct pcap_linux *handlep = handle->priv;
3449 h.raw = RING_GET_FRAME_AT(handle, offset);
3467 static int pcap_wait_for_frames_mmap(pcap_t *handle)
3469 struct pcap_linux *handlep = handle->priv;
3475 pollinfo[0].fd = handle->fd;
3562 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3572 if (handle->break_loop) {
3573 handle->break_loop = 0;
3598 snprintf(handle->errbuf,
3604 snprintf(handle->errbuf,
3617 if (getsockopt(handle->fd, SOL_SOCKET,
3652 handle->required_select_timeout = &netdown_timeout;
3659 snprintf(handle->errbuf,
3664 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3686 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3711 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3722 if (handle->break_loop) {
3723 handle->break_loop = 0;
3753 if (!device_still_exists(handle)) {
3764 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3775 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
3782 snprintf(handle->errbuf,
3787 pcapint_fmt_errmsg_for_errno(handle->errbuf,
3804 handle->required_select_timeout = NULL;
3819 /* handle a single memory mapped packet */
3821 pcap_t *handle,
3834 struct pcap_linux *handlep = handle->priv;
3842 if (tp_mac + tp_snaplen > handle->bufsize) {
3847 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3851 tp_mac, tp_snaplen, handle->bufsize,
3855 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3858 tp_mac, tp_snaplen, handle->bufsize);
3877 if (handle->linktype == DLT_LINUX_SLL2) {
3899 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3939 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4137 if (handlep->filter_in_userland && handle->fcode.bf_insns) {
4143 if (pcapint_filter_with_aux_data(handle->fcode.bf_insns,
4151 if (!linux_check_direction(handle, sll))
4163 if (handle->linktype == DLT_LINUX_SLL2) {
4216 if (pcaphdr.caplen > (bpf_u_int32)handle->snapshot)
4217 pcaphdr.caplen = handle->snapshot;
4226 pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback,
4229 struct pcap_linux *handlep = handle->priv;
4235 h.raw = RING_GET_CURRENT_FRAME(handle);
4241 ret = pcap_wait_for_frames_mmap(handle);
4267 h.raw = RING_GET_CURRENT_FRAME(handle);
4272 handle,
4280 handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? h.h2->tp_nsec : h.h2->tp_nsec / 1000,
4309 if (++handle->offset >= handle->cc)
4310 handle->offset = 0;
4313 if (handle->break_loop) {
4314 handle->break_loop = 0;
4323 pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback,
4326 struct pcap_linux *handlep = handle->priv;
4334 h.raw = RING_GET_CURRENT_FRAME(handle);
4340 ret = pcap_wait_for_frames_mmap(handle);
4346 h.raw = RING_GET_CURRENT_FRAME(handle);
4374 h.raw = RING_GET_CURRENT_FRAME(handle);
4394 while (packets_to_read-- && !handle->break_loop) {
4397 handle,
4405 handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? tp3_hdr->tp_nsec : tp3_hdr->tp_nsec / 1000,
4440 if (++handle->offset >= handle->cc)
4441 handle->offset = 0;
4447 if (handle->break_loop) {
4448 handle->break_loop = 0;
4464 pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
4472 if (!handle)
4475 pcapint_strlcpy(handle->errbuf, "setfilter: No filter specified",
4480 handlep = handle->priv;
4484 if (pcapint_install_bpf_program(handle, filter) < 0)
4497 if (handle->fcode.bf_len > USHRT_MAX) {
4525 switch (fix_program(handle, &fcode)) {
4578 if ((err = set_kernel_filter(handle, &fcode)) == 0)
4621 if (reset_kernel_filter(handle) == -1) {
4622 pcapint_fmt_errmsg_for_errno(handle->errbuf,
4655 offset = handle->offset;
4657 offset = handle->cc - 1;
4658 for (n=0; n < handle->cc; ++n) {
4660 offset = handle->cc - 1;
4661 if (pcap_get_ring_frame_status(handle, offset) != TP_STATUS_KERNEL)
4689 * value > handle->cc, and if it were equal to
4690 * handle->cc, it wouldn't be zero, and thus would
4691 * be decremented to handle->cc - 1.)
4693 handlep->blocks_to_filter_in_userland = handle->cc - n;
4795 enter_rfmon_mode(pcap_t *handle, int sock_fd, const char *device)
4797 struct pcap_linux *handlep = handle->priv;
4807 ret = get_mac80211_phydev(handle, device, phydev_path, PATH_MAX);
4822 ret = nl80211_init(handle, &nlstate, device);
4832 ret = add_mon_if(handle, sock_fd, &nlstate, device, mondevice);
4842 * Hard failure. Just return ret; handle->errbuf
4850 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4870 if (!pcapint_do_addexit(handle)) {
4875 del_mon_if(handle, sock_fd, &nlstate, device,
4887 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4890 del_mon_if(handle, sock_fd, &nlstate, device,
4897 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
4900 del_mon_if(handle, sock_fd, &nlstate, device,
4913 * the handle.
4920 pcapint_add_to_pcaps_to_close(handle);
4926 enter_rfmon_mode(pcap_t *handle _U_, int sock_fd _U_, const char *device _U_)
4953 iface_set_all_ts_types(pcap_t *handle, char *ebuf)
4957 handle->tstamp_type_list = malloc(NUM_SOF_TIMESTAMPING_TYPES * sizeof(u_int));
4958 if (handle->tstamp_type_list == NULL) {
4964 handle->tstamp_type_list[i] = sof_ts_type_map[i].pcap_tstamp_val;
4965 handle->tstamp_type_count = NUM_SOF_TIMESTAMPING_TYPES;
4974 iface_get_ts_types(const char *device, pcap_t *handle, char *ebuf)
4990 handle->tstamp_type_list = NULL;
5022 if (iface_set_all_ts_types(handle, ebuf) == -1)
5033 handle->tstamp_type_list = NULL;
5064 handle->tstamp_type_list = NULL;
5074 handle->tstamp_type_list = malloc(num_ts_types * sizeof(u_int));
5075 if (handle->tstamp_type_list == NULL) {
5082 handle->tstamp_type_list[j] = sof_ts_type_map[i].pcap_tstamp_val;
5086 handle->tstamp_type_count = num_ts_types;
5088 handle->tstamp_type_list = NULL;
5094 iface_get_ts_types(const char *device, pcap_t *handle, char *ebuf)
5104 handle->tstamp_type_list = NULL;
5112 if (iface_set_all_ts_types(handle, ebuf) == -1)
5150 iface_ethtool_flag_ioctl(pcap_t *handle, int cmd, const char *cmdname,
5157 pcapint_strlcpy(ifr.ifr_name, handle->opt.device, sizeof(ifr.ifr_name));
5161 if (ioctl(handle->fd, SIOCETHTOOL, &ifr) == -1) {
5172 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
5174 handle->opt.device, cmdname);
5196 iface_get_offload(pcap_t *handle)
5201 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GTSO, "ETHTOOL_GTSO", 0);
5214 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGSO, "ETHTOOL_GGSO", 0);
5222 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS", 0);
5235 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GGRO, "ETHTOOL_GGRO", 0);
5249 ret = iface_ethtool_flag_ioctl(handle, ETHTOOL_GUFO, "ETHTOOL_GUFO", 1);
5260 iface_get_offload(pcap_t *handle _U_)
5287 iface_dsa_get_proto_info(const char *device, pcap_t *handle)
5304 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
5319 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
5336 handle->linktype = dsa_protos[i].linktype;
5346 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5409 fix_program(pcap_t *handle, struct sock_fprog *fcode)
5411 struct pcap_linux *handlep = handle->priv;
5422 prog_size = sizeof(*handle->fcode.bf_insns) * handle->fcode.bf_len;
5423 len = handle->fcode.bf_len;
5426 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
5430 memcpy(f, handle->fcode.bf_insns, prog_size);
5460 if (fix_offset(handle, p) < 0) {
5478 fix_offset(pcap_t *handle, struct bpf_insn *p)
5488 if (handle->linktype == DLT_LINUX_SLL2) {
5563 set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode)
5601 if (setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
5616 save_mode = fcntl(handle->fd, F_GETFL, 0);
5618 pcapint_fmt_errmsg_for_errno(handle->errbuf,
5623 if (fcntl(handle->fd, F_SETFL, save_mode | O_NONBLOCK) < 0) {
5624 pcapint_fmt_errmsg_for_errno(handle->errbuf,
5629 while (recv(handle->fd, &drain, sizeof drain, MSG_TRUNC) >= 0)
5639 (void)fcntl(handle->fd, F_SETFL, save_mode);
5640 (void)reset_kernel_filter(handle);
5641 pcapint_fmt_errmsg_for_errno(handle->errbuf,
5646 if (fcntl(handle->fd, F_SETFL, save_mode) == -1) {
5647 pcapint_fmt_errmsg_for_errno(handle->errbuf,
5657 ret = setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
5677 if (reset_kernel_filter(handle) == -1) {
5678 pcapint_fmt_errmsg_for_errno(handle->errbuf,
5690 reset_kernel_filter(pcap_t *handle)
5701 ret = setsockopt(handle->fd, SOL_SOCKET, SO_DETACH_FILTER,