diff options
Diffstat (limited to 'pcap-usb-linux.c')
-rw-r--r-- | pcap-usb-linux.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c index f1b430c7bda93..26f6189706041 100644 --- a/pcap-usb-linux.c +++ b/pcap-usb-linux.c @@ -148,7 +148,7 @@ usb_dev_add(pcap_if_t** alldevsp, int n, char *err_str) } int -usb_platform_finddevs(pcap_if_t **alldevsp, char *err_str) +usb_findalldevs(pcap_if_t **alldevsp, char *err_str) { struct dirent* data; int ret = 0; @@ -284,10 +284,40 @@ probe_devices(int bus) } pcap_t * -usb_create(const char *device, char *ebuf) +usb_create(const char *device, char *ebuf, int *is_ours) { + const char *cp; + char *cpend; + long devnum; pcap_t *p; + /* Does this look like a USB monitoring device? */ + cp = strrchr(device, '/'); + if (cp == NULL) + cp = device; + /* Does it begin with USB_IFACE? */ + if (strncmp(cp, USB_IFACE, sizeof USB_IFACE - 1) != 0) { + /* Nope, doesn't begin with USB_IFACE */ + *is_ours = 0; + return NULL; + } + /* Yes - is USB_IFACE followed by a number? */ + cp += sizeof USB_IFACE - 1; + devnum = strtol(cp, &cpend, 10); + if (cpend == cp || *cpend != '\0') { + /* Not followed by a number. */ + *is_ours = 0; + return NULL; + } + if (devnum < 0) { + /* Followed by a non-valid number. */ + *is_ours = 0; + return NULL; + } + + /* OK, it's probably ours. */ + *is_ours = 1; + p = pcap_create_common(device, ebuf); if (p == NULL) return (NULL); |