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