diff options
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r-- | pcap-bt-linux.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/pcap-bt-linux.c b/pcap-bt-linux.c index 0c6c08d1..50871011 100644 --- a/pcap-bt-linux.c +++ b/pcap-bt-linux.c @@ -71,7 +71,7 @@ static int bt_setdirection_linux(pcap_t *, pcap_direction_t); static int bt_stats_linux(pcap_t *, struct pcap_stat *); int -bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str) +bt_findalldevs(pcap_if_t **alldevsp, char *err_str) { pcap_if_t *found_dev = *alldevsp; struct hci_dev_list_req *dev_list; @@ -135,10 +135,39 @@ done: } pcap_t * -bt_create(const char *device, char *ebuf) +bt_create(const char *device, char *ebuf, int *is_ours) { + char *cp, *cpend; + long devnum; pcap_t *p; + /* Does this look like a Bluetooth device? */ + cp = strrchr(device, '/'); + if (cp == NULL) + cp = device; + /* Does it begin with BT_IFACE? */ + if (strncmp(cp, BT_IFACE, sizeof BT_IFACE - 1) != 0) { + /* Nope, doesn't begin with BT_IFACE */ + *is_ours = 0; + return NULL; + } + /* Yes - is BT_IFACE followed by a number? */ + cp += sizeof BT_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); |