2 * Copyright (c) 2006 Paolo Abeni (Italy)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * USB sniffing API implementation for Linux platform
31 * By Paolo Abeni <paolo.abeni@email.it>
32 * Modifications: Kris Katterjohn <katterjohn@gmail.com>
36 static const char rcsid
[] _U_
=
37 "@(#) $Header: /tcpdump/master/libpcap/pcap-usb-linux.c,v 1.33 2008-12-23 21:38:50 guy Exp $ (LBL)";
45 #include "pcap-usb-linux.h"
48 #ifdef NEED_STRERROR_H
60 #include <netinet/in.h>
61 #include <sys/ioctl.h>
63 #ifdef HAVE_LINUX_USBDEVICE_FS_H
64 #include <linux/usbdevice_fs.h>
67 #define USB_IFACE "usbmon"
68 #define USB_TEXT_DIR "/sys/kernel/debug/usbmon"
69 #define SYS_USB_BUS_DIR "/sys/bus/usb/devices"
70 #define PROC_USB_BUS_DIR "/proc/bus/usb"
71 #define USB_LINE_LEN 4096
73 #if __BYTE_ORDER == __LITTLE_ENDIAN
78 #define htols(s) bswap_16(s)
79 #define htoll(l) bswap_32(l)
80 #define htol64(ll) bswap_64(ll)
83 struct mon_bin_stats
{
91 size_t data_len
; /* Length of data (can be zero) */
94 struct mon_bin_mfetch
{
95 int32_t *offvec
; /* Vector of events fetched */
96 int32_t nfetch
; /* Number of events to fetch (out: fetched) */
97 int32_t nflush
; /* Number of events to flush */
100 #define MON_IOC_MAGIC 0x92
102 #define MON_IOCQ_URB_LEN _IO(MON_IOC_MAGIC, 1)
103 #define MON_IOCX_URB _IOWR(MON_IOC_MAGIC, 2, struct mon_bin_hdr)
104 #define MON_IOCG_STATS _IOR(MON_IOC_MAGIC, 3, struct mon_bin_stats)
105 #define MON_IOCT_RING_SIZE _IO(MON_IOC_MAGIC, 4)
106 #define MON_IOCQ_RING_SIZE _IO(MON_IOC_MAGIC, 5)
107 #define MON_IOCX_GET _IOW(MON_IOC_MAGIC, 6, struct mon_bin_get)
108 #define MON_IOCX_MFETCH _IOWR(MON_IOC_MAGIC, 7, struct mon_bin_mfetch)
109 #define MON_IOCH_MFLUSH _IO(MON_IOC_MAGIC, 8)
111 #define MON_BIN_SETUP 0x1 /* setup hdr is present*/
112 #define MON_BIN_SETUP_ZERO 0x2 /* setup buffer is not available */
113 #define MON_BIN_DATA_ZERO 0x4 /* data buffer is not available */
114 #define MON_BIN_ERROR 0x8
116 /* forward declaration */
117 static int usb_activate(pcap_t
*);
118 static int usb_stats_linux(pcap_t
*, struct pcap_stat
*);
119 static int usb_stats_linux_bin(pcap_t
*, struct pcap_stat
*);
120 static int usb_read_linux(pcap_t
*, int , pcap_handler
, u_char
*);
121 static int usb_read_linux_bin(pcap_t
*, int , pcap_handler
, u_char
*);
122 static int usb_read_linux_mmap(pcap_t
*, int , pcap_handler
, u_char
*);
123 static int usb_inject_linux(pcap_t
*, const void *, size_t);
124 static int usb_setfilter_linux(pcap_t
*, struct bpf_program
*);
125 static int usb_setdirection_linux(pcap_t
*, pcap_direction_t
);
126 static void usb_cleanup_linux_mmap(pcap_t
*);
128 /* facility to add an USB device to the device list*/
130 usb_dev_add(pcap_if_t
** alldevsp
, int n
, char *err_str
)
134 snprintf(dev_name
, 10, USB_IFACE
"%d", n
);
135 snprintf(dev_descr
, 30, "USB bus number %d", n
);
137 if (pcap_add_if(alldevsp
, dev_name
, 0,
138 dev_descr
, err_str
) < 0)
144 usb_platform_finddevs(pcap_if_t
**alldevsp
, char *err_str
)
153 /* try scanning sysfs usb bus directory */
154 dir
= opendir(SYS_USB_BUS_DIR
);
156 while ((ret
== 0) && ((data
= readdir(dir
)) != 0)) {
159 if (strncmp(name
, "usb", 3) != 0)
162 if (sscanf(&name
[3], "%d", &n
) == 0)
165 ret
= usb_dev_add(alldevsp
, n
, err_str
);
172 /* that didn't work; try scanning procfs usb bus directory */
173 dir
= opendir(PROC_USB_BUS_DIR
);
175 while ((ret
== 0) && ((data
= readdir(dir
)) != 0)) {
179 /* if this file name does not end with a number it's not of our interest */
180 if ((len
< 1) || !isdigit(name
[--len
]))
182 while (isdigit(name
[--len
]));
183 if (sscanf(&name
[len
+1], "%d", &n
) != 1)
186 ret
= usb_dev_add(alldevsp
, n
, err_str
);
193 /* neither of them worked */
198 int usb_mmap(pcap_t
* handle
)
200 int len
= ioctl(handle
->fd
, MON_IOCQ_RING_SIZE
);
204 handle
->buffer
= mmap(0, len
, PROT_READ
, MAP_SHARED
, handle
->fd
, 0);
205 return handle
->buffer
!= MAP_FAILED
;
208 #define CTRL_TIMEOUT (5*1000) /* milliseconds */
210 #define USB_DIR_IN 0x80
211 #define USB_TYPE_STANDARD 0x00
212 #define USB_RECIP_DEVICE 0x00
214 #define USB_REQ_GET_DESCRIPTOR 6
216 #define USB_DT_DEVICE 1
218 /* probe the descriptors of the devices attached to the bus */
219 /* the descriptors will end up in the captured packet stream */
220 /* and be decoded by external apps like wireshark */
221 /* without these identifying probes packet data can't be fully decoded */
223 probe_devices(int bus
)
225 struct usbdevfs_ctrltransfer ctrl
;
231 /* scan usb bus directories for device nodes */
232 snprintf(buf
, sizeof(buf
), "/dev/bus/usb/%03d", bus
);
237 while ((ret
>= 0) && ((data
= readdir(dir
)) != 0)) {
239 char* name
= data
->d_name
;
244 snprintf(buf
, sizeof(buf
), "/dev/bus/usb/%03d/%s", bus
, data
->d_name
);
246 fd
= open(buf
, O_RDWR
);
250 ctrl
.bRequestType
= USB_DIR_IN
| USB_TYPE_STANDARD
| USB_RECIP_DEVICE
;
251 ctrl
.bRequest
= USB_REQ_GET_DESCRIPTOR
;
252 ctrl
.wValue
= USB_DT_DEVICE
<< 8;
254 ctrl
.wLength
= sizeof(buf
);
256 ctrl
.timeout
= CTRL_TIMEOUT
;
258 ret
= ioctl(fd
, USBDEVFS_CONTROL
, &ctrl
);
266 usb_create(const char *device
, char *ebuf
)
270 p
= pcap_create_common(device
, ebuf
);
274 p
->activate_op
= usb_activate
;
279 usb_activate(pcap_t
* handle
)
281 char full_path
[USB_LINE_LEN
];
283 /* Initialize some components of the pcap structure. */
284 handle
->bufsize
= handle
->snapshot
;
286 handle
->linktype
= DLT_USB_LINUX
;
288 handle
->inject_op
= usb_inject_linux
;
289 handle
->setfilter_op
= usb_setfilter_linux
;
290 handle
->setdirection_op
= usb_setdirection_linux
;
291 handle
->set_datalink_op
= NULL
; /* can't change data link type */
292 handle
->getnonblock_op
= pcap_getnonblock_fd
;
293 handle
->setnonblock_op
= pcap_setnonblock_fd
;
295 /*get usb bus index from device name */
296 if (sscanf(handle
->opt
.source
, USB_IFACE
"%d", &handle
->md
.ifindex
) != 1)
298 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
299 "Can't get USB bus index from %s", handle
->opt
.source
);
303 /*now select the read method: try to open binary interface */
304 snprintf(full_path
, USB_LINE_LEN
, LINUX_USB_MON_DEV
"%d", handle
->md
.ifindex
);
305 handle
->fd
= open(full_path
, O_RDONLY
, 0);
308 if (handle
->opt
.rfmon
) {
310 * Monitor mode doesn't apply to USB devices.
313 return PCAP_ERROR_RFMON_NOTSUP
;
316 /* binary api is available, try to use fast mmap access */
317 if (usb_mmap(handle
)) {
318 handle
->linktype
= DLT_USB_LINUX_MMAPPED
;
319 handle
->stats_op
= usb_stats_linux_bin
;
320 handle
->read_op
= usb_read_linux_mmap
;
321 handle
->cleanup_op
= usb_cleanup_linux_mmap
;
322 probe_devices(handle
->md
.ifindex
);
325 * "handle->fd" is a real file, so "select()" and
326 * "poll()" work on it.
328 handle
->selectable_fd
= handle
->fd
;
332 /* can't mmap, use plain binary interface access */
333 handle
->stats_op
= usb_stats_linux_bin
;
334 handle
->read_op
= usb_read_linux_bin
;
335 probe_devices(handle
->md
.ifindex
);
338 /*Binary interface not available, try open text interface */
339 snprintf(full_path
, USB_LINE_LEN
, USB_TEXT_DIR
"/%dt", handle
->md
.ifindex
);
340 handle
->fd
= open(full_path
, O_RDONLY
, 0);
343 /* no more fallback, give it up*/
344 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
345 "Can't open USB bus file %s: %s", full_path
, strerror(errno
));
349 if (handle
->opt
.rfmon
) {
351 * Monitor mode doesn't apply to USB devices.
354 return PCAP_ERROR_RFMON_NOTSUP
;
357 handle
->stats_op
= usb_stats_linux
;
358 handle
->read_op
= usb_read_linux
;
362 * "handle->fd" is a real file, so "select()" and "poll()"
365 handle
->selectable_fd
= handle
->fd
;
367 /* for plain binary access and text access we need to allocate the read
369 handle
->buffer
= malloc(handle
->bufsize
);
370 if (!handle
->buffer
) {
371 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
372 "malloc: %s", pcap_strerror(errno
));
381 return c
< 'A' ? c
- '0': ((c
<'a') ? c
- 'A' + 10: c
-'a'+10);
385 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and
386 * <linux-kernel-source>/drivers/usb/mon/mon_text.c for urb string
390 usb_read_linux(pcap_t
*handle
, int max_packets
, pcap_handler callback
, u_char
*user
)
393 * /usr/src/linux/Documentation/usb/usbmon.txt
397 int tag
, cnt
, ep_num
, dev_addr
, dummy
, ret
, urb_len
, data_len
;
398 char etype
, pipeid1
, pipeid2
, status
[16], urb_tag
, line
[USB_LINE_LEN
];
400 u_char
* rawdata
= handle
->buffer
;
401 struct pcap_pkthdr pkth
;
402 pcap_usb_header
* uhdr
= (pcap_usb_header
*)handle
->buffer
;
403 u_char urb_transfer
=0;
406 /* ignore interrupt system call errors */
408 ret
= read(handle
->fd
, line
, USB_LINE_LEN
- 1);
409 if (handle
->break_loop
)
411 handle
->break_loop
= 0;
414 } while ((ret
== -1) && (errno
== EINTR
));
418 return 0; /* no data there */
420 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
421 "Can't read from fd %d: %s", handle
->fd
, strerror(errno
));
425 /* read urb header; %n argument may increment return value, but it's
426 * not mandatory, so does not count on it*/
428 ret
= sscanf(string
, "%x %d %c %c%c:%d:%d %s%n", &tag
, ×tamp
, &etype
,
429 &pipeid1
, &pipeid2
, &dev_addr
, &ep_num
, status
,
433 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
434 "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
439 uhdr
->device_address
= dev_addr
;
440 uhdr
->bus_id
= handle
->md
.ifindex
;
444 /* don't use usbmon provided timestamp, since it have low precision*/
445 if (gettimeofday(&pkth
.ts
, NULL
) < 0)
447 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
448 "Can't get timestamp for message '%s' %d:%s",
449 string
, errno
, strerror(errno
));
452 uhdr
->ts_sec
= pkth
.ts
.tv_sec
;
453 uhdr
->ts_usec
= pkth
.ts
.tv_usec
;
455 /* parse endpoint information */
457 urb_transfer
= URB_CONTROL
;
458 else if (pipeid1
== 'Z')
459 urb_transfer
= URB_ISOCHRONOUS
;
460 else if (pipeid1
== 'I')
461 urb_transfer
= URB_INTERRUPT
;
462 else if (pipeid1
== 'B')
463 urb_transfer
= URB_BULK
;
464 if (pipeid2
== 'i') {
465 ep_num
|= URB_TRANSFER_IN
;
469 incoming
= !incoming
;
474 if (handle
->direction
== PCAP_D_OUT
)
478 if (handle
->direction
== PCAP_D_IN
)
480 uhdr
->event_type
= etype
;
481 uhdr
->transfer_type
= urb_transfer
;
482 uhdr
->endpoint_number
= ep_num
;
483 pkth
.caplen
= sizeof(pcap_usb_header
);
484 rawdata
+= sizeof(pcap_usb_header
);
486 /* check if this is a setup packet */
487 ret
= sscanf(status
, "%d", &dummy
);
490 /* this a setup packet, setup data can be filled with underscore if
491 * usbmon has not been able to read them, so we must parse this fields as
493 pcap_usb_setup
* shdr
;
494 char str1
[3], str2
[3], str3
[5], str4
[5], str5
[5];
495 ret
= sscanf(string
, "%s %s %s %s %s%n", str1
, str2
, str3
, str4
,
499 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
500 "Can't parse USB bus message '%s', too few tokens (expected 5 got %d)",
506 /* try to convert to corresponding integer */
508 shdr
->bmRequestType
= strtoul(str1
, 0, 16);
509 shdr
->bRequest
= strtoul(str2
, 0, 16);
510 shdr
->wValue
= htols(strtoul(str3
, 0, 16));
511 shdr
->wIndex
= htols(strtoul(str4
, 0, 16));
512 shdr
->wLength
= htols(strtoul(str5
, 0, 16));
514 uhdr
->setup_flag
= 0;
517 uhdr
->setup_flag
= 1;
520 ret
= sscanf(string
, " %d%n", &urb_len
, &cnt
);
523 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
524 "Can't parse urb length from '%s'", string
);
529 /* urb tag is not present if urb length is 0, so we can stop here
531 pkth
.len
= urb_len
+pkth
.caplen
;
532 uhdr
->urb_len
= urb_len
;
535 if (uhdr
->urb_len
== 0)
538 /* check for data presence; data is present if and only if urb tag is '=' */
539 if (sscanf(string
, " %c", &urb_tag
) != 1)
541 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
542 "Can't parse urb tag from '%s'", string
);
549 /* skip urb tag and following space */
552 /* if we reach this point we got some urb data*/
555 /* read all urb data; if urb length is greater then the usbmon internal
556 * buffer length used by the kernel to spool the URB, we get only
557 * a partial information.
558 * At least until linux 2.6.17 there is no way to set usbmon intenal buffer
559 * length and default value is 130. */
560 while ((string
[0] != 0) && (string
[1] != 0) && (pkth
.caplen
< handle
->snapshot
))
562 rawdata
[0] = ascii_to_int(string
[0]) * 16 + ascii_to_int(string
[1]);
565 if (string
[0] == ' ')
572 uhdr
->data_len
= data_len
;
573 handle
->md
.packets_read
++;
574 if (pkth
.caplen
> handle
->snapshot
)
575 pkth
.caplen
= handle
->snapshot
;
577 callback(user
, &pkth
, handle
->buffer
);
582 usb_inject_linux(pcap_t
*handle
, const void *buf
, size_t size
)
584 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
, "inject not supported on "
590 usb_stats_linux(pcap_t
*handle
, struct pcap_stat
*stats
)
592 int dummy
, ret
, consumed
, cnt
;
593 char string
[USB_LINE_LEN
];
594 char token
[USB_LINE_LEN
];
596 snprintf(string
, USB_LINE_LEN
, USB_TEXT_DIR
"/%ds", handle
->md
.ifindex
);
598 int fd
= open(string
, O_RDONLY
, 0);
601 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
602 "Can't open USB stats file %s: %s",
603 string
, strerror(errno
));
607 /* read stats line */
609 ret
= read(fd
, string
, USB_LINE_LEN
-1);
610 } while ((ret
== -1) && (errno
== EINTR
));
615 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
616 "Can't read stats from fd %d ", fd
);
621 /* extract info on dropped urbs */
622 for (consumed
=0; consumed
< ret
; ) {
623 /* from the sscanf man page:
624 * The C standard says: "Execution of a %n directive does
625 * not increment the assignment count returned at the completion
626 * of execution" but the Corrigendum seems to contradict this.
627 * Do not make any assumptions on the effect of %n conversions
628 * on the return value and explicitly check for cnt assignmet*/
630 int ntok
= sscanf(ptr
, "%s%n", token
, &cnt
);
631 if ((ntok
< 1) || (cnt
< 0))
635 if (strcmp(token
, "nreaders") == 0)
636 ret
= sscanf(ptr
, "%d", &stats
->ps_drop
);
638 ret
= sscanf(ptr
, "%d", &dummy
);
645 stats
->ps_recv
= handle
->md
.packets_read
;
646 stats
->ps_ifdrop
= 0;
651 usb_setfilter_linux(pcap_t
*p
, struct bpf_program
*fp
)
657 usb_setdirection_linux(pcap_t
*p
, pcap_direction_t d
)
665 usb_stats_linux_bin(pcap_t
*handle
, struct pcap_stat
*stats
)
668 struct mon_bin_stats st
;
669 ret
= ioctl(handle
->fd
, MON_IOCG_STATS
, &st
);
672 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
673 "Can't read stats from fd %d:%s ", handle
->fd
, strerror(errno
));
677 stats
->ps_recv
= handle
->md
.packets_read
+ st
.queued
;
678 stats
->ps_ifdrop
= 0;
679 stats
->ps_drop
= st
.dropped
;
684 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and
685 * <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
688 usb_read_linux_bin(pcap_t
*handle
, int max_packets
, pcap_handler callback
, u_char
*user
)
690 struct mon_bin_get info
;
692 struct pcap_pkthdr pkth
;
693 int clen
= handle
->snapshot
- sizeof(pcap_usb_header
);
695 /* the usb header is going to be part of 'packet' data*/
696 info
.hdr
= (pcap_usb_header
*) handle
->buffer
;
697 info
.data
= handle
->buffer
+ sizeof(pcap_usb_header
);
698 info
.data_len
= clen
;
700 /* ignore interrupt system call errors */
702 ret
= ioctl(handle
->fd
, MON_IOCX_GET
, &info
);
703 if (handle
->break_loop
)
705 handle
->break_loop
= 0;
708 } while ((ret
== -1) && (errno
== EINTR
));
712 return 0; /* no data there */
714 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
715 "Can't read from fd %d: %s", handle
->fd
, strerror(errno
));
719 /* we can get less that than really captured from kernel, depending on
720 * snaplen, so adjust header accordingly */
721 if (info
.hdr
->data_len
< clen
)
722 clen
= info
.hdr
->data_len
;
723 info
.hdr
->data_len
= clen
;
724 pkth
.caplen
= clen
+ sizeof(pcap_usb_header
);
725 pkth
.len
= info
.hdr
->data_len
+ sizeof(pcap_usb_header
);
726 pkth
.ts
.tv_sec
= info
.hdr
->ts_sec
;
727 pkth
.ts
.tv_usec
= info
.hdr
->ts_usec
;
729 handle
->md
.packets_read
++;
730 callback(user
, &pkth
, handle
->buffer
);
735 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and
736 * <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
740 usb_read_linux_mmap(pcap_t
*handle
, int max_packets
, pcap_handler callback
, u_char
*user
)
742 struct mon_bin_mfetch fetch
;
743 int32_t vec
[VEC_SIZE
];
744 struct pcap_pkthdr pkth
;
745 pcap_usb_header
* hdr
;
750 max_clen
= handle
->snapshot
- sizeof(pcap_usb_header
);
754 int limit
= max_packets
- packets
;
757 if (limit
> VEC_SIZE
)
760 /* try to fetch as many events as possible*/
762 fetch
.nfetch
= limit
;
763 fetch
.nflush
= nflush
;
764 /* ignore interrupt system call errors */
766 ret
= ioctl(handle
->fd
, MON_IOCX_MFETCH
, &fetch
);
767 if (handle
->break_loop
)
769 handle
->break_loop
= 0;
772 } while ((ret
== -1) && (errno
== EINTR
));
776 return 0; /* no data there */
778 snprintf(handle
->errbuf
, PCAP_ERRBUF_SIZE
,
779 "Can't mfetch fd %d: %s", handle
->fd
, strerror(errno
));
783 /* keep track of processed events, we will flush them later */
784 nflush
= fetch
.nfetch
;
785 for (i
=0; i
<fetch
.nfetch
; ++i
) {
787 hdr
= (pcap_usb_header
*) &handle
->buffer
[vec
[i
]];
788 if (hdr
->event_type
== '@')
791 /* we can get less that than really captured from kernel, depending on
792 * snaplen, so adjust header accordingly */
794 if (hdr
->data_len
< clen
)
795 clen
= hdr
->data_len
;
797 /* get packet info from header*/
798 pkth
.caplen
= clen
+ sizeof(pcap_usb_header_mmapped
);
799 pkth
.len
= hdr
->data_len
+ sizeof(pcap_usb_header_mmapped
);
800 pkth
.ts
.tv_sec
= hdr
->ts_sec
;
801 pkth
.ts
.tv_usec
= hdr
->ts_usec
;
803 handle
->md
.packets_read
++;
804 callback(user
, &pkth
, (u_char
*) hdr
);
808 /* with max_packets <= 0 we stop afer the first chunk*/
809 if ((max_packets
<= 0) || (packets
== max_packets
))
813 /* flush pending events*/
814 ioctl(handle
->fd
, MON_IOCH_MFLUSH
, nflush
);
819 usb_cleanup_linux_mmap(pcap_t
* handle
)
821 /* buffer must not be freed because it's memory mapped */
822 /* XXX - does it need to be unmapped? */
823 handle
->buffer
= NULL
;
824 pcap_cleanup_live_common(handle
);