diff with -u attached
-- Jon Smirl [EMAIL PROTECTED]
? libpcap.diff ? libpcap.patch ? lpcap.diff Index: pcap-usb-linux.c =================================================================== RCS file: /tcpdump/master/libpcap/pcap-usb-linux.c,v retrieving revision 1.14 diff -u -r1.14 pcap-usb-linux.c --- pcap-usb-linux.c 1 Feb 2007 03:17:20 -0000 1.14 +++ pcap-usb-linux.c 3 Apr 2007 14:41:22 -0000 @@ -57,10 +57,11 @@ #include <netinet/in.h> #include <sys/ioctl.h> #include <sys/mman.h> +#include <usb.h> #define USB_IFACE "usb" #define USB_TEXT_DIR "/sys/kernel/debug/usbmon" -#define USB_BUS_DIR "/proc/bus/usb" +#define USB_BUS_DIR "/sys/bus/usb/devices" #define USB_LINE_LEN 4096 @@ -153,13 +154,11 @@ while ((ret == 0) && ((data = readdir(dir)) != 0)) { int n; char* name = data->d_name; - int len = strlen(name); - /* if this file name does not end with a number it's not of our interest */ - if ((len < 1) || !isdigit(name[--len])) + if (strncmp(name, "usb", 3) != 0) continue; - while (isdigit(name[--len])); - if (sscanf(&name[len+1], "%d", &n) != 1) + + if (sscanf(&name[3], "%d", &n) == 0) continue; ret = usb_dev_add(alldevsp, n, err_str); @@ -180,6 +179,66 @@ return handle->buffer != MAP_FAILED; } +#define CTRL_TIMEOUT (5*1000) /* milliseconds */ + +struct usb_ctrltransfer { + /* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */ + u_int8_t bRequestType; + u_int8_t bRequest; + u_int16_t wValue; + u_int16_t wIndex; + u_int16_t wLength; + + u_int32_t timeout; /* in milliseconds */ + + /* pointer to data */ + void *data; +}; +#define IOCTL_USB_CONTROL _IOWR('U', 0, struct usb_ctrltransfer) + +static int +probe_devices(int bus) +{ + struct usb_ctrltransfer ctrl; + struct dirent* data; + int ret = 0; + char buf[40]; + DIR* dir; + + /* scan profs usb bus directorys */ + snprintf(buf, sizeof buf, "/dev/bus/usb/%03d", bus); + dir = opendir(buf); + if (!dir) return 0; + while ((ret >= 0) && ((data = readdir(dir)) != 0)) { + int n, len, fd; + char* name = data->d_name; + + if (name[0] == '.') + continue; + + snprintf(buf, sizeof buf, "/dev/bus/usb/%03d/%s", bus, data->d_name); + + fd = open(buf, O_RDWR); + if (fd == -1) + continue; + + ctrl.bRequestType = USB_ENDPOINT_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE; + ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; + ctrl.wValue = USB_DT_DEVICE << 8; + ctrl.wIndex = 0; + ctrl.wLength = sizeof buf; + + ctrl.data = buf; + ctrl.timeout = CTRL_TIMEOUT; + + ret = ioctl(fd, IOCTL_USB_CONTROL, &ctrl); + + close(fd); + } + closedir(dir); + return ret; +} + pcap_t* usb_open_live(const char* bus, int snaplen, int promisc , int to_ms, char* errmsg) { @@ -237,12 +296,14 @@ handle->stats_op = usb_stats_linux_bin; handle->read_op = usb_read_linux_mmap; handle->close_op = usb_close_linux_mmap; + probe_devices(handle->md.ifindex); return handle; } /* can't mmap, use plain binary interface access */ handle->stats_op = usb_stats_linux_bin; handle->read_op = usb_read_linux_bin; + probe_devices(handle->md.ifindex); } else { /*Binary interface not available, try open text interface */ @@ -575,6 +636,7 @@ stats->ps_recv = handle->md.packets_read + st.queued; stats->ps_ifdrop = st.dropped; + stats->ps_drop = st.dropped; return 0; } @@ -619,7 +681,7 @@ clen = info.hdr->data_len; info.hdr->data_len = clen; pkth.caplen = clen + sizeof(pcap_usb_header); - pkth.len = info.hdr->urb_len + sizeof(pcap_usb_header); + pkth.len = info.hdr->data_len + sizeof(pcap_usb_header); pkth.ts.tv_sec = info.hdr->ts_sec; pkth.ts.tv_usec = info.hdr->ts_usec;
- This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.