diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-06-11 13:22:34 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-06-11 13:22:34 -0700 |
commit | 2426611584e9099af5f98d18ef37337df9bef025 (patch) | |
tree | 4a79e50330d0f179362445bab756177565991310 /pcap-dag.c | |
parent | 4e14566d51233686b7f4563f0a48a11a3f9eb808 (diff) | |
download | libpcap-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-dag.c')
-rw-r--r-- | pcap-dag.c | 52 |
1 files changed, 39 insertions, 13 deletions
@@ -48,6 +48,12 @@ struct rtentry; /* declarations in <net/if.h> */ #include "pcap-dag.h" +/* + * DAG devices have names beginning with "dag", followed by a number + * from 0 to MAXDAG. + */ +#define MAXDAG 31 + #define ATM_CELL_SIZE 52 #define ATM_HDR_SIZE 4 @@ -82,15 +88,6 @@ static const unsigned short endian_test_word = 0x0100; #define IS_BIGENDIAN() (*((unsigned char *)&endian_test_word)) - -#ifdef DAG_ONLY -/* This code is required when compiling for a DAG device only. */ - -/* Replace dag function names with pcap equivalent. */ -#define dag_create pcap_create -#define dag_platform_finddevs pcap_platform_finddevs -#endif /* DAG_ONLY */ - #define MAX_DAG_PACKET 65536 static unsigned char TempPkt[MAX_DAG_PACKET]; @@ -835,10 +832,39 @@ fail: return PCAP_ERROR; } -pcap_t *dag_create(const char *device, char *ebuf) +pcap_t *dag_create(const char *device, char *ebuf, int *is_ours) { + char *cp, *cpend; + long devnum; pcap_t *p; + /* Does this look like a DAG device? */ + cp = strrchr(device, '/'); + if (cp == NULL) + cp = device; + /* Does it begin with "dag"? */ + if (strncmp(cp, "dag", 3) != 0) { + /* Nope, doesn't begin with "dag" */ + *is_ours = 0; + return NULL; + } + /* Yes - is "dag" followed by a number from 0 to MAXDAG? */ + cp += 3; + devnum = strtol(cp, &cpend, 10); + if (cpend == cp || *cpend != '\0') { + /* Not followed by a number. */ + *is_ours = 0; + return NULL; + } + if (devnum < 0 || devnum > MAXDAG) { + /* 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; @@ -870,7 +896,7 @@ dag_stats(pcap_t *p, struct pcap_stat *ps) { * open attempts will still be much less than the naive approach. */ int -dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf) +dag_findalldevs(pcap_if_t **devlistp, char *errbuf) { char name[12]; /* XXX - pick a size */ int ret = 0; @@ -879,8 +905,8 @@ dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf) int dagstream; int dagfd; - /* Try all the DAGs 0-31 */ - for (c = 0; c < 32; c++) { + /* Try all the DAGs 0-MAXDAG */ + for (c = 0; c <= MAXDAG; c++) { snprintf(name, 12, "dag%d", c); if (-1 == dag_parse_name(name, dagname, DAGNAME_BUFSIZE, &dagstream)) { |