summaryrefslogtreecommitdiff
path: root/pcap-bt-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-11 13:22:34 -0700
committerGuy Harris <guy@alum.mit.edu>2012-06-11 13:22:34 -0700
commit2426611584e9099af5f98d18ef37337df9bef025 (patch)
tree4a79e50330d0f179362445bab756177565991310 /pcap-bt-linux.c
parent4e14566d51233686b7f4563f0a48a11a3f9eb808 (diff)
downloadlibpcap-2426611584e9099af5f98d18ef37337df9bef025.tar.gz
Have non-interface modules take responsibility for identifying their devices.
Have a table of routines to do pcap_create() for devices that aren't regular network interfaces. Try each of those in succession until one says "it's mine" (whether it succeeds or fails); if none do, do a pcap_create() for a regular interface. Have those routines do more stringent tests of the name - don't just accept any name that has a particular substring anywhere in it. That reduces the likelihood of a false match (as happened with the CANbus module when somebody renamed their Ethernet interface "canopy"). Have the table also include routines for pcap_findalldevs().
Diffstat (limited to 'pcap-bt-linux.c')
-rw-r--r--pcap-bt-linux.c33
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);