Lines Matching refs:handle

356 static void destroy_ring(pcap_t *handle);
357 static int create_ring(pcap_t *handle, int *status);
358 static int prepare_tpacket_socket(pcap_t *handle);
387 static int enter_rfmon_mode(pcap_t *handle, int sock_fd,
390 static int iface_get_offload(pcap_t *handle);
394 static int fix_program(pcap_t *handle, struct sock_fprog *fcode,
397 static int set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode);
398 static int reset_kernel_filter(pcap_t *handle);
409 pcap_t *handle;
411 handle = pcap_create_common(device, ebuf, sizeof (struct pcap_linux));
412 if (handle == NULL)
415 handle->activate_op = pcap_activate_linux;
416 handle->can_set_rfmon_op = pcap_can_set_rfmon_linux;
428 handle->tstamp_type_count = 3;
429 handle->tstamp_type_list = malloc(3 * sizeof(u_int));
430 if (handle->tstamp_type_list == NULL) {
431 free(handle);
434 handle->tstamp_type_list[0] = PCAP_TSTAMP_HOST;
435 handle->tstamp_type_list[1] = PCAP_TSTAMP_ADAPTER;
436 handle->tstamp_type_list[2] = PCAP_TSTAMP_ADAPTER_UNSYNCED;
448 handle->tstamp_precision_count = 2;
449 handle->tstamp_precision_list = malloc(2 * sizeof(u_int));
450 if (handle->tstamp_precision_list == NULL) {
451 if (handle->tstamp_type_list != NULL)
452 free(handle->tstamp_type_list);
453 free(handle);
456 handle->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
457 handle->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
460 return handle;
509 * return 1; if not, return 0. On an error, fill in handle->errbuf and
513 get_mac80211_phydev(pcap_t *handle, const char *device, char *phydev_path,
523 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
538 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
589 nl80211_init(pcap_t *handle, struct nl80211_state *state, const char *device)
595 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
596 "%s: failed to allocate netlink handle", device);
601 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
608 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
616 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
639 add_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
646 ifindex = iface_get_id(sock_fd, device, handle->errbuf);
652 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
684 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
712 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
727 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
735 del_mon_if(pcap_t *handle, int sock_fd, struct nl80211_state *state,
742 ifindex = iface_get_id(sock_fd, mondevice, handle->errbuf);
748 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
759 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
767 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
781 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
789 enter_rfmon_mode_mac80211(pcap_t *handle, int sock_fd, const char *device)
791 struct pcap_linux *handlep = handle->priv;
801 ret = get_mac80211_phydev(handle, device, phydev_path, PATH_MAX);
817 ret = nl80211_init(handle, &nlstate, device);
827 ret = add_mon_if(handle, sock_fd, &nlstate, device, mondevice);
834 * Hard failure. Just return ret; handle->errbuf
842 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
862 if (!pcap_do_addexit(handle)) {
876 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
879 del_mon_if(handle, sock_fd, &nlstate, device,
886 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
889 del_mon_if(handle, sock_fd, &nlstate, device,
902 * the handle.
909 pcap_add_to_pcaps_to_close(handle);
916 pcap_can_set_rfmon_linux(pcap_t *handle)
927 if (strcmp(handle->opt.source, "any") == 0) {
947 ret = get_mac80211_phydev(handle, handle->opt.source, phydev_path,
968 (void)snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
976 strncpy(ireq.ifr_ifrn.ifrn_name, handle->opt.source,
988 (void)snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1071 static void pcap_cleanup_linux( pcap_t *handle )
1073 struct pcap_linux *handlep = handle->priv;
1102 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
1115 if (ioctl(handle->fd, SIOCSIFFLAGS,
1130 ret = nl80211_init(handle, &nlstate, handlep->device);
1132 ret = del_mon_if(handle, handle->fd, &nlstate,
1140 handlep->mondevice, handle->errbuf);
1166 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) != -1) {
1170 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1)
1183 if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) {
1199 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1) {
1213 pcap_remove_from_pcaps_to_close(handle);
1224 pcap_cleanup_live_common(handle);
1228 * Get a handle for a live capture from the given device. You can
1236 pcap_activate_linux(pcap_t *handle)
1238 struct pcap_linux *handlep = handle->priv;
1242 device = handle->opt.source;
1244 handle->inject_op = pcap_inject_linux;
1245 handle->setfilter_op = pcap_setfilter_linux;
1246 handle->setdirection_op = pcap_setdirection_linux;
1247 handle->set_datalink_op = pcap_set_datalink_linux;
1248 handle->getnonblock_op = pcap_getnonblock_fd;
1249 handle->setnonblock_op = pcap_setnonblock_fd;
1250 handle->cleanup_op = pcap_cleanup_linux;
1251 handle->read_op = pcap_read_linux;
1252 handle->stats_op = pcap_stats_linux;
1260 if (handle->opt.promisc) {
1261 handle->opt.promisc = 0;
1263 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1271 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "strdup: %s",
1277 handlep->timeout = handle->opt.timeout;
1284 if (handle->opt.promisc)
1296 status = activate_new(handle);
1301 * handle->errbuf has been set appropriately.
1310 switch (activate_mmap(handle, &status)) {
1333 * return and, if it's PCAP_ERROR, handle->errbuf
1341 if ((status = activate_old(handle)) != 1) {
1344 * Tidy up and report our failure (handle->errbuf
1355 if (handle->opt.buffer_size != 0) {
1359 if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
1360 &handle->opt.buffer_size,
1361 sizeof(handle->opt.buffer_size)) == -1) {
1362 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1371 handle->buffer = malloc(handle->bufsize + handle->offset);
1372 if (!handle->buffer) {
1373 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1380 * "handle->fd" is a socket, so "select()" and "poll()"
1383 handle->selectable_fd = handle->fd;
1388 pcap_cleanup_linux(handle);
1398 pcap_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
1404 return pcap_read_packet(handle, callback, user);
1408 pcap_set_datalink_linux(pcap_t *handle, int dlt)
1410 handle->linktype = dlt;
1420 linux_check_direction(const pcap_t *handle, const struct sockaddr_ll *sll)
1422 struct pcap_linux *handlep = handle->priv;
1437 if (handle->direction == PCAP_D_IN)
1444 if (handle->direction == PCAP_D_OUT)
1456 pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
1458 struct pcap_linux *handlep = handle->priv;
1503 * to set handle->break_loop (we ignore it on other
1513 bp = handle->buffer + handle->offset;
1524 iov.iov_len = handle->bufsize - offset;
1532 if (handle->break_loop) {
1538 handle->break_loop = 0;
1543 packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC);
1547 handle->fd, bp + offset,
1548 handle->bufsize - offset, MSG_TRUNC,
1569 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1574 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1590 * that won't handle packet sockets without socket
1604 if (!linux_check_direction(handle, &from))
1695 * We currently handle this by making a copy of the filter
1703 if (caplen > handle->snapshot)
1704 caplen = handle->snapshot;
1707 if (handlep->filter_in_userland && handle->fcode.bf_insns) {
1708 if (bpf_filter(handle->fcode.bf_insns, bp,
1720 if (handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) {
1721 if (ioctl(handle->fd, SIOCGSTAMPNS, &pcap_header.ts) == -1) {
1722 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1729 if (ioctl(handle->fd, SIOCGSTAMP, &pcap_header.ts) == -1) {
1730 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
1792 pcap_inject_linux(pcap_t *handle, const void *buf, size_t size)
1794 struct pcap_linux *handlep = handle->priv;
1804 strlcpy(handle->errbuf,
1818 strlcpy(handle->errbuf,
1826 ret = send(handle->fd, buf, size, 0);
1828 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
1836 * Get the statistics for the given packet capture handle.
1844 pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats)
1846 struct pcap_linux *handlep = handle->priv;
1875 if (handle->opt.promisc)
1886 if (getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS,
1932 * getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS, ....
1950 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2361 pcap_setfilter_linux_common(pcap_t *handle, struct bpf_program *filter,
2371 if (!handle)
2374 strncpy(handle->errbuf, "setfilter: No filter specified",
2379 handlep = handle->priv;
2383 if (install_bpf_program(handle, filter) < 0)
2397 if (handle->fcode.bf_len > USHRT_MAX) {
2424 switch (fix_program(handle, &fcode, is_mmapped)) {
2477 if ((err = set_kernel_filter(handle, &fcode)) == 0)
2509 reset_kernel_filter(handle);
2526 pcap_setfilter_linux(pcap_t *handle, struct bpf_program *filter)
2528 return pcap_setfilter_linux_common(handle, filter, 0);
2537 pcap_setdirection_linux(pcap_t *handle, pcap_direction_t d)
2540 struct pcap_linux *handlep = handle->priv;
2543 handle->direction = d;
2551 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
2563 * able to handle DLT_LINUX_SLL captures.
2595 * constant, as arguments, and sets "handle->linktype" to the
2596 * appropriate DLT_XXX constant and sets "handle->offset" to
2597 * the appropriate value (to make "handle->offset" plus link-layer
2609 static void map_arphrd_to_dlt(pcap_t *handle, int arptype, int cooked_ok)
2631 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
2635 if (handle->dlt_list != NULL) {
2636 handle->dlt_list[0] = DLT_EN10MB;
2637 handle->dlt_list[1] = DLT_DOCSIS;
2638 handle->dlt_count = 2;
2644 handle->linktype = DLT_EN10MB;
2645 handle->offset = 2;
2649 handle->linktype = DLT_EN3MB;
2653 handle->linktype = DLT_AX25_KISS;
2657 handle->linktype = DLT_PRONET;
2661 handle->linktype = DLT_CHAOS;
2667 handle->linktype = DLT_CAN_SOCKETCAN;
2675 handle->linktype = DLT_IEEE802;
2676 handle->offset = 2;
2680 handle->linktype = DLT_ARCNET_LINUX;
2687 handle->linktype = DLT_FDDI;
2688 handle->offset = 3;
2732 handle->linktype = DLT_LINUX_SLL;
2734 handle->linktype = -1;
2741 handle->linktype = DLT_IEEE802_11;
2748 handle->linktype = DLT_PRISM_HEADER;
2755 handle->linktype = DLT_IEEE802_11_RADIO;
2779 handle->linktype = DLT_LINUX_SLL;
2782 * XXX - handle ISDN types here? We can't fall
2797 handle->linktype = DLT_RAW;
2805 handle->linktype = DLT_C_HDLC;
2832 handle->linktype = DLT_RAW;
2839 handle->linktype = DLT_FRELAY;
2843 handle->linktype = DLT_LTALK;
2862 handle->linktype = DLT_IP_OVER_FC;
2927 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
2931 if (handle->dlt_list != NULL) {
2932 handle->dlt_list[0] = DLT_FC_2;
2933 handle->dlt_list[1] = DLT_FC_2_WITH_FRAME_DELIMS;
2934 handle->dlt_list[2] = DLT_IP_OVER_FC;
2935 handle->dlt_count = 3;
2937 handle->linktype = DLT_FC_2;
2945 handle->linktype = DLT_LINUX_IRDA;
2958 handle->linktype = DLT_LINUX_LAPD;
2969 handle->linktype = DLT_RAW;
2976 handle->linktype = DLT_IEEE802_15_4_NOFCS;
2980 handle->linktype = -1;
2995 activate_new(pcap_t *handle)
2998 struct pcap_linux *handlep = handle->priv;
2999 const char *device = handle->opt.source;
3027 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
3057 handlep->lo_ifindex = iface_get_id(sock_fd, "lo", handle->errbuf);
3063 handle->offset = 0;
3074 if (handle->opt.rfmon) {
3081 err = enter_rfmon_mode(handle, sock_fd, device);
3105 arptype = iface_get_arptype(sock_fd, device, handle->errbuf);
3110 map_arphrd_to_dlt(handle, arptype, 1);
3111 if (handle->linktype == -1 ||
3112 handle->linktype == DLT_LINUX_SLL ||
3113 handle->linktype == DLT_LINUX_IRDA ||
3114 handle->linktype == DLT_LINUX_LAPD ||
3115 (handle->linktype == DLT_EN10MB &&
3128 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3135 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3157 if (handle->dlt_list != NULL) {
3158 free(handle->dlt_list);
3159 handle->dlt_list = NULL;
3160 handle->dlt_count = 0;
3163 if (handle->linktype == -1) {
3168 * to handle the new type.
3170 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3183 if (handle->linktype != DLT_LINUX_IRDA &&
3184 handle->linktype != DLT_LINUX_LAPD)
3185 handle->linktype = DLT_LINUX_SLL;
3189 handle->errbuf);
3196 handle->errbuf)) != 1) {
3207 if (handle->opt.rfmon) {
3218 handle->linktype = DLT_LINUX_SLL;
3252 if (!is_any_device && handle->opt.promisc) {
3258 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3271 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3276 handle->offset += VLAN_TAG_LEN;
3294 if (handle->snapshot < SLL_HDR_LEN + 1)
3295 handle->snapshot = SLL_HDR_LEN + 1;
3297 handle->bufsize = handle->snapshot;
3302 switch (handle->linktype) {
3318 handle->fd = sock_fd;
3321 if (handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) {
3324 if (setsockopt(handle->fd, SOL_SOCKET, SO_TIMESTAMPNS, &nsec_tstamps, sizeof(nsec_tstamps)) < 0) {
3325 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "setsockopt: unable to set SO_TIMESTAMPNS");
3351 * if that is PCAP_ERROR, sets handle->errbuf to the appropriate message.
3354 activate_mmap(pcap_t *handle, int *status)
3356 struct pcap_linux *handlep = handle->priv;
3363 handlep->oneshot_buffer = malloc(handle->snapshot);
3365 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3372 if (handle->opt.buffer_size == 0) {
3374 handle->opt.buffer_size = 2*1024*1024;
3376 ret = prepare_tpacket_socket(handle);
3382 ret = create_ring(handle, status);
3406 * handle->offset is used to get the current position into the rx ring.
3407 * handle->cc is used to store the ring size.
3412 handle->read_op = pcap_read_linux_mmap_v1;
3416 handle->read_op = pcap_read_linux_mmap_v2;
3421 handle->read_op = pcap_read_linux_mmap_v3;
3425 handle->cleanup_op = pcap_cleanup_linux_mmap;
3426 handle->setfilter_op = pcap_setfilter_linux_mmap;
3427 handle->setnonblock_op = pcap_setnonblock_mmap;
3428 handle->getnonblock_op = pcap_getnonblock_mmap;
3429 handle->oneshot_callback = pcap_oneshot_mmap;
3430 handle->selectable_fd = handle->fd;
3435 activate_mmap(pcap_t *handle _U_, int *status _U_)
3449 * supported; return -1 on any other error, and set handle->errbuf.
3452 init_tpacket(pcap_t *handle, int version, const char *version_str)
3454 struct pcap_linux *handlep = handle->priv;
3459 if (getsockopt(handle->fd, SOL_PACKET, PACKET_HDRLEN, &val, &len) < 0) {
3464 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3473 if (setsockopt(handle->fd, SOL_PACKET, PACKET_VERSION, &val,
3475 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3485 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE, &val,
3487 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3504 * supported; return -1 on any other error, and set handle->errbuf.
3507 prepare_tpacket_socket(pcap_t *handle)
3509 struct pcap_linux *handlep = handle->priv;
3527 if (handle->opt.immediate)
3530 ret = init_tpacket(handle, TPACKET_V3, "TPACKET_V3");
3539 ret = init_tpacket(handle, TPACKET_V2, "TPACKET_V2");
3563 * if that is PCAP_ERROR, sets handle->errbuf to the appropriate message.
3566 create_ring(pcap_t *handle, int *status)
3568 struct pcap_linux *handlep = handle->priv;
3625 frame_size = handle->snapshot;
3626 if (handle->linktype == DLT_EN10MB) {
3630 offload = iface_get_offload(handle);
3636 mtu = iface_get_mtu(handle->fd, handle->opt.source,
3637 handle->errbuf);
3651 if (getsockopt(handle->fd, SOL_SOCKET, SO_TYPE, &sk_type,
3653 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3660 if (getsockopt(handle->fd, SOL_PACKET, PACKET_RESERVE,
3668 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3708 req.tp_frame_nr = handle->opt.buffer_size/req.tp_frame_size;
3720 req.tp_frame_nr = handle->opt.buffer_size/req.tp_frame_size;
3725 /* compute the minumum block size that will handle this frame.
3756 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER ||
3757 handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER_UNSYNCED) {
3771 strcpy(ifr.ifr_name, handle->opt.source);
3774 if (ioctl(handle->fd, SIOCSHWTSTAMP, &ifr) < 0) {
3800 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3812 if (handle->opt.tstamp_type == PCAP_TSTAMP_ADAPTER) {
3826 if (setsockopt(handle->fd, SOL_PACKET, PACKET_TIMESTAMP,
3828 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3854 if (setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
3878 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3888 PROT_READ|PROT_WRITE, MAP_SHARED, handle->fd, 0);
3890 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3894 destroy_ring(handle);
3900 handle->cc = req.tp_frame_nr;
3901 handle->buffer = malloc(handle->cc * sizeof(union thdr *));
3902 if (!handle->buffer) {
3903 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
3907 destroy_ring(handle);
3913 handle->offset = 0;
3916 for (j=0; j<frames_per_block; ++j, ++handle->offset) {
3917 RING_GET_FRAME(handle) = base;
3922 handle->bufsize = req.tp_frame_size;
3923 handle->offset = 0;
3929 destroy_ring(pcap_t *handle)
3931 struct pcap_linux *handlep = handle->priv;
3936 setsockopt(handle->fd, SOL_PACKET, PACKET_RX_RING,
3969 pcap_t *handle = sp->pd;
3970 struct pcap_linux *handlep = handle->priv;
3978 pcap_cleanup_linux_mmap( pcap_t *handle )
3980 struct pcap_linux *handlep = handle->priv;
3982 destroy_ring(handle);
3987 pcap_cleanup_linux(handle);
4026 pcap_get_ring_frame(pcap_t *handle, int status)
4028 struct pcap_linux *handlep = handle->priv;
4031 h.raw = RING_GET_FRAME(handle);
4061 static int pcap_wait_for_frames_mmap(pcap_t *handle)
4063 if (!pcap_get_ring_frame(handle, TP_STATUS_USER)) {
4064 struct pcap_linux *handlep = handle->priv;
4070 pollinfo.fd = handle->fd;
4104 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4116 snprintf(handle->errbuf,
4128 if (recv(handle->fd, &c, sizeof c,
4142 snprintf(handle->errbuf,
4146 snprintf(handle->errbuf,
4154 snprintf(handle->errbuf,
4161 if (handle->break_loop) {
4162 handle->break_loop = 0;
4170 /* handle a single memory mapped packet */
4172 pcap_t *handle,
4184 struct pcap_linux *handlep = handle->priv;
4190 if (tp_mac + tp_snaplen > handle->bufsize) {
4191 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4194 tp_mac, tp_snaplen, handle->bufsize);
4208 if (handlep->filter_in_userland && handle->fcode.bf_insns &&
4209 (bpf_filter(handle->fcode.bf_insns, bp,
4214 if (!linux_check_direction(handle, sll))
4246 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4295 if (pcaphdr.caplen > handle->snapshot)
4296 pcaphdr.caplen = handle->snapshot;
4305 pcap_read_linux_mmap_v1(pcap_t *handle, int max_packets, pcap_handler callback,
4308 struct pcap_linux *handlep = handle->priv;
4313 ret = pcap_wait_for_frames_mmap(handle);
4323 h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER);
4328 handle,
4365 if (++handle->offset >= handle->cc)
4366 handle->offset = 0;
4369 if (handle->break_loop) {
4370 handle->break_loop = 0;
4379 pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback,
4382 struct pcap_linux *handlep = handle->priv;
4387 ret = pcap_wait_for_frames_mmap(handle);
4397 h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER);
4402 handle,
4410 handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? h.h2->tp_nsec : h.h2->tp_nsec / 1000,
4443 if (++handle->offset >= handle->cc)
4444 handle->offset = 0;
4447 if (handle->break_loop) {
4448 handle->break_loop = 0;
4458 pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback,
4461 struct pcap_linux *handlep = handle->priv;
4468 ret = pcap_wait_for_frames_mmap(handle);
4473 h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER);
4481 h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER);
4497 handle,
4505 handle->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO ? tp3_hdr->tp_nsec : tp3_hdr->tp_nsec / 1000,
4544 if (++handle->offset >= handle->cc)
4545 handle->offset = 0;
4551 if (handle->break_loop) {
4552 handle->break_loop = 0;
4561 pcap_setfilter_linux_mmap(pcap_t *handle, struct bpf_program *filter)
4563 struct pcap_linux *handlep = handle->priv;
4573 ret = pcap_setfilter_linux_common(handle, filter, 1);
4593 offset = handle->offset;
4594 if (--handle->offset < 0)
4595 handle->offset = handle->cc - 1;
4596 for (n=0; n < handle->cc; ++n) {
4597 if (--handle->offset < 0)
4598 handle->offset = handle->cc - 1;
4599 if (!pcap_get_ring_frame(handle, TP_STATUS_KERNEL))
4621 handle->offset = offset;
4630 * value > handle->cc, and if it were equal to
4631 * handle->cc, it wouldn't be zero, and thus would
4632 * be decremented to handle->cc - 1.)
4634 handlep->blocks_to_filter_in_userland = handle->cc - n;
4777 enter_rfmon_mode_wext(pcap_t *handle, int sock_fd, const char *device)
4837 struct pcap_linux *handlep = handle->priv;
4852 err = has_wext(sock_fd, device, handle->errbuf);
4880 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4893 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4904 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
4910 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5107 if (!pcap_do_addexit(handle)) {
5151 pcap_add_to_pcaps_to_close(handle);
5168 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5177 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5197 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5286 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5368 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5375 if (ioctl(handle->fd, SIOCSIWMODE, &ireq) == -1) {
5397 pcap_add_to_pcaps_to_close(handle);
5407 enter_rfmon_mode(pcap_t *handle, int sock_fd, const char *device)
5414 ret = enter_rfmon_mode_mac80211(handle, sock_fd, device);
5422 ret = enter_rfmon_mode_wext(handle, sock_fd, device);
5447 iface_ethtool_ioctl(pcap_t *handle, int cmd, const char *cmdname)
5453 strncpy(ifr.ifr_name, handle->opt.source, sizeof(ifr.ifr_name));
5457 if (ioctl(handle->fd, SIOCETHTOOL, &ifr) == -1) {
5467 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5468 "%s: SIOETHTOOL(%s) ioctl failed: %s", handle->opt.source,
5476 iface_get_offload(pcap_t *handle)
5481 ret = iface_ethtool_ioctl(handle, ETHTOOL_GTSO, "ETHTOOL_GTSO");
5489 ret = iface_ethtool_ioctl(handle, ETHTOOL_GUFO, "ETHTOOL_GUFO");
5502 ret = iface_ethtool_ioctl(handle, ETHTOOL_GGSO, "ETHTOOL_GGSO");
5510 ret = iface_ethtool_ioctl(handle, ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
5523 ret = iface_ethtool_ioctl(handle, ETHTOOL_GGRO, "ETHTOOL_GGRO");
5534 iface_get_offload(pcap_t *handle _U_)
5553 activate_old(pcap_t *handle)
5555 struct pcap_linux *handlep = handle->priv;
5558 const char *device = handle->opt.source;
5564 handle->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
5565 if (handle->fd == -1) {
5566 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5591 strncpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems",
5595 if (iface_bind_old(handle->fd, device, handle->errbuf) == -1)
5601 arptype = iface_get_arptype(handle->fd, device, handle->errbuf);
5609 map_arphrd_to_dlt(handle, arptype, 0);
5610 if (handle->linktype == -1) {
5611 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5618 if (handle->opt.promisc) {
5621 if (ioctl(handle->fd, SIOCGIFFLAGS, &ifr) == -1) {
5622 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5639 if (!pcap_do_addexit(handle)) {
5649 if (ioctl(handle->fd, SIOCSIFFLAGS, &ifr) == -1) {
5650 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5661 pcap_add_to_pcaps_to_close(handle);
5715 mtu = iface_get_mtu(handle->fd, device, handle->errbuf);
5718 handle->bufsize = MAX_LINKHEADER_SIZE + mtu;
5719 if (handle->bufsize < handle->snapshot)
5720 handle->bufsize = handle->snapshot;
5728 handle->bufsize = handle->snapshot;
5735 handle->offset = 0;
5836 fix_program(pcap_t *handle, struct sock_fprog *fcode, int is_mmapped)
5838 struct pcap_linux *handlep = handle->priv;
5849 prog_size = sizeof(*handle->fcode.bf_insns) * handle->fcode.bf_len;
5850 len = handle->fcode.bf_len;
5853 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
5857 memcpy(f, handle->fcode.bf_insns, prog_size);
5974 set_kernel_filter(pcap_t *handle, struct sock_fprog *fcode)
6012 if (setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
6027 save_mode = fcntl(handle->fd, F_GETFL, 0);
6029 fcntl(handle->fd, F_SETFL, save_mode | O_NONBLOCK) >= 0) {
6030 while (recv(handle->fd, &drain, sizeof drain,
6034 fcntl(handle->fd, F_SETFL, save_mode);
6037 reset_kernel_filter(handle);
6038 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
6048 ret = setsockopt(handle->fd, SOL_SOCKET, SO_ATTACH_FILTER,
6068 reset_kernel_filter(handle);
6076 reset_kernel_filter(pcap_t *handle)
6086 return setsockopt(handle->fd, SOL_SOCKET, SO_DETACH_FILTER,