* Returns -1 on error, 0 otherwise.
* The list, as returned through "alldevsp", may be null if no interfaces
* were up and could be opened.
- *
- * This is the implementation used on platforms that have "getifaddrs()".
*/
int
-pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
pcap_if_t *devlist = NULL;
struct ifaddrs *ifap, *ifa;
freeifaddrs(ifap);
- if (ret != -1) {
- /*
- * We haven't had any errors yet; do any platform-specific
- * operations to add devices.
- */
- if (pcap_platform_finddevs(&devlist, errbuf) < 0)
- ret = -1;
- }
-
if (ret == -1) {
/*
* We had an error; free the list we've been constructing.
*
* XXX - or platforms that have other, better mechanisms but for which
* we don't yet have code to use that mechanism; I think there's a better
- * way on Linux, for example.
+ * way on Linux, for example, but if that better way is "getifaddrs()",
+ * we already have that.
*/
int
-pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
pcap_if_t *devlist = NULL;
register int fd;
free(buf);
(void)close(fd);
- if (ret != -1) {
- /*
- * We haven't had any errors yet; do any platform-specific
- * operations to add devices.
- */
- if (pcap_platform_finddevs(&devlist, errbuf) < 0)
- ret = -1;
- }
-
if (ret == -1) {
/*
* We had an error; free the list we've been constructing.
* SIOCGLIFCONF rather than SIOCGIFCONF in order to get IPv6 addresses.)
*/
int
-pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
pcap_if_t *devlist = NULL;
register int fd4, fd6, fd;
(void)close(fd6);
(void)close(fd4);
- if (ret != -1) {
- /*
- * We haven't had any errors yet; do any platform-specific
- * operations to add devices.
- */
- if (pcap_platform_finddevs(&devlist, errbuf) < 0)
- ret = -1;
- }
-
if (ret == -1) {
/*
* We had an error; free the list we've been constructing.
extern pcap_if_t *acn_if_list; /* pcap's list of available interfaces */
-int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) {
+int pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf) {
//printf("pcap_findalldevs()\n"); // fulko
#include "pcap-int.h"
-#ifdef HAVE_DAG_API
-#include "pcap-dag.h"
-#endif /* HAVE_DAG_API */
-
-#ifdef HAVE_SNF_API
-#include "pcap-snf.h"
-#endif /* HAVE_SNF_API */
-
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#endif /* HAVE_ZEROCOPY_BPF */
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
-#ifdef HAVE_DAG_API
- if (strstr(device, "dag"))
- return (dag_create(device, ebuf));
-#endif /* HAVE_DAG_API */
-#ifdef HAVE_SNF_API
- if (strstr(device, "snf"))
- return (snf_create(device, ebuf));
-#endif /* HAVE_SNF_API */
-
p = pcap_create_common(device, ebuf);
if (p == NULL)
return (NULL);
int
pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf)
{
-#ifdef HAVE_DAG_API
- if (dag_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif /* HAVE_DAG_API */
-#ifdef HAVE_SNF_API
- if (snf_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif /* HAVE_SNF_API */
-
return (0);
}
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;
}
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);
/*
* Prototypes for Bluetooth-related functions
*/
-int bt_platform_finddevs(pcap_if_t **alldevsp, char *err_str);
-pcap_t *bt_create(const char *device, char *ebuf);
+int bt_findalldevs(pcap_if_t **alldevsp, char *err_str);
+pcap_t *bt_create(const char *device, char *ebuf, int *is_ours);
static int can_setdirection_linux(pcap_t *, pcap_direction_t);
static int can_stats_linux(pcap_t *, struct pcap_stat *);
+int
+can_findalldevs(pcap_if_t **devlistp, char *errbuf)
+{
+ /*
+ * There are no platform-specific devices since each device
+ * exists as a regular network interface.
+ *
+ * XXX - true?
+ */
+ return 0;
+}
+
pcap_t *
-can_create(const char *device, char *ebuf)
+can_create(const char *device, char *ebuf, int *is_ours)
{
+ char *cp, *cpend;
+ long devnum;
pcap_t* p;
+ /* Does this look like a CANbus device? */
+ cp = strrchr(device, '/');
+ if (cp == NULL)
+ cp = device;
+ /* Does it begin with "can" or "vcan"? */
+ if (strncmp(cp, "can", 3) == 0) {
+ /* Begins with "can" */
+ cp += 3; /* skip past "can" */
+ } else if (strncmp(cp, "vcan", 4) == 0) {
+ /* Begins with "vcan" */
+ cp += 4;
+ } else {
+ /* Nope, doesn't begin with "can" or "vcan" */
+ *is_ours = 0;
+ return NULL;
+ }
+ /* Yes - is "can" or "vcan" followed by a number from 0? */
+ 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);
/*
* Prototypes for SocketCAN related functions
*/
-pcap_t* can_create(const char *device, char *ebuf);
+pcap_t* can_create(const char *device, char *ebuf, int *is_ours);
+int can_findalldevs(pcap_if_t **devlistp, char *errbuf);
struct canusb_t
{
- libusb_context *ctx;
- libusb_device_handle *dev;
- char* src;
- pthread_t worker;
- int rdpipe, wrpipe;
- volatile int* loop;
+ libusb_context *ctx;
+ libusb_device_handle *dev;
+ pthread_t worker;
+ int rdpipe, wrpipe;
+ volatile int* loop;
};
static struct canusb_t canusb;
static volatile int loop;
-
-
-int canusb_platform_finddevs(pcap_if_t **alldevsp, char *err_str)
+int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
libusb_context *fdctx;
libusb_device** devs;
libusb_get_device_descriptor(devs[i],&desc);
if ((desc.idVendor != CANUSB_VID) || (desc.idProduct != CANUSB_PID))
- continue; //It is not, check next device
+ continue; //It is not, check next device
//It is!
libusb_device_handle *dh = NULL;
if (ret = libusb_open(devs[i],&dh) == 0)
{
- char dev_name[30];
- char dev_descr[50];
+ char dev_name[30];
+ char dev_descr[50];
int n = libusb_get_string_descriptor_ascii(dh,desc.iSerialNumber,sernum,64);
sernum[n] = 0;
- snprintf(dev_name, 30, CANUSB_IFACE"%s", sernum);
- snprintf(dev_descr, 50, "CanUSB [%s]", sernum);
+ snprintf(dev_name, 30, CANUSB_IFACE"%s", sernum);
+ snprintf(dev_descr, 50, "CanUSB [%s]", sernum);
libusb_close(dh);
if (pcap_add_if(alldevsp, dev_name, 0, dev_descr, err_str) < 0)
{
- libusb_free_device_list(devs,1);
- return -1;
+ libusb_free_device_list(devs,1);
+ return -1;
}
}
}
pcap_t *
-canusb_create(const char *device, char *ebuf)
+canusb_create(const char *device, char *ebuf, int *is_ours)
{
- pcap_t* p;
+ char *cp, *cpend;
+ long devnum;
+ pcap_t* p;
- libusb_init(&canusb.ctx);
-
- p = pcap_create_common(device, ebuf);
- if (p == NULL)
- return (NULL);
-
- memset(&canusb, 0x00, sizeof(canusb));
+ libusb_init(&canusb.ctx);
+
+ /* Does this look like a DAG device? */
+ cp = strrchr(device, '/');
+ if (cp == NULL)
+ cp = device;
+ /* Does it begin with "canusb"? */
+ if (strncmp(cp, "canusb", 6) != 0) {
+ /* Nope, doesn't begin with "canusb" */
+ *is_ours = 0;
+ return NULL;
+ }
+ /* Yes - is "canusb" followed by a number? */
+ cp += 6;
+ 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);
+
+ memset(&canusb, 0x00, sizeof(canusb));
+ p->activate_op = canusb_activate;
- p->activate_op = canusb_activate;
-
- canusb.src = strdup(p->opt.source);
- return (p);
+ return (p);
}
/*
* Prototypes for SocketCAN related functions
*/
-pcap_t* canusb_create(const char *device, char *ebuf);
-int canusb_listdevices(pcap_if_t **pdevlist, char* errbuf);
+pcap_t* canusb_create(const char *device, char *ebuf, int *is_ours);
+int canusb_findalldevspcap_if_t **pdevlist, char* errbuf);
#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
#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];
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;
* 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;
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))
{
* @(#) $Header: /tcpdump/master/libpcap/pcap-dag.h,v 1.7 2008-04-04 19:37:45 guy Exp $ (LBL)
*/
-pcap_t *dag_create(const char *, char *);
-int dag_platform_finddevs(pcap_if_t **devlistp, char *errbuf);
+pcap_t *dag_create(const char *, char *, int *);
+int dag_findalldevs(pcap_if_t **devlistp, char *errbuf);
#ifndef TYPE_AAL5
#define TYPE_AAL5 4
#endif
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
int pcap_setnonblock_fd(pcap_t *p, int, char *);
#endif
+/*
+ * Internal interfaces for "pcap_create()".
+ *
+ * "pcap_create_interface()" is the routine to do a pcap_create on
+ * a regular network interface. There are multiple implementations
+ * of this, one for each platform type (Linux, BPF, DLPI, etc.),
+ * with the one used chosen by the configure script.
+ *
+ * "pcap_create_common()" allocates and fills in a pcap_t, for use
+ * by pcap_create routines.
+ */
+pcap_t *pcap_create_interface(const char *, char *);
pcap_t *pcap_create_common(const char *, char *);
int pcap_do_addexit(pcap_t *);
void pcap_add_to_pcaps_to_close(pcap_t *);
/*
* Internal interfaces for "pcap_findalldevs()".
*
+ * "pcap_findalldevs_interfaces()" finds interfaces using the
+ * "standard" mechanisms (SIOCGIFCONF, "getifaddrs()", etc.).
+ *
* "pcap_platform_finddevs()" is a platform-dependent routine to
- * add devices not found by the "standard" mechanisms (SIOCGIFCONF,
- * "getifaddrs()", etc..
+ * add devices not found by the "standard" mechanisms.
*
- * "pcap_add_if()" adds an interface to the list of interfaces.
+ * "pcap_add_if()" adds an interface to the list of interfaces, for
+ * use by various "find interfaces" routines.
*/
+int pcap_findalldevs_interfaces(pcap_if_t **, char *);
int pcap_platform_finddevs(pcap_if_t **, char *);
int add_addr_to_iflist(pcap_if_t **, const char *, u_int, struct sockaddr *,
size_t, struct sockaddr *, size_t, struct sockaddr *, size_t,
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
#include "pcap/sll.h"
#include "pcap/vlan.h"
-#ifdef HAVE_DAG_API
-#include "pcap-dag.h"
-#endif /* HAVE_DAG_API */
-
-#ifdef HAVE_SEPTEL_API
-#include "pcap-septel.h"
-#endif /* HAVE_SEPTEL_API */
-
-#ifdef HAVE_SNF_API
-#include "pcap-snf.h"
-#endif /* HAVE_SNF_API */
-
-#ifdef PCAP_SUPPORT_USB
-#include "pcap-usb-linux.h"
-#endif
-
-#ifdef PCAP_SUPPORT_BT
-#include "pcap-bt-linux.h"
-#endif
-
-#ifdef PCAP_SUPPORT_CAN
-#include "pcap-can-linux.h"
-#endif
-
-#if PCAP_SUPPORT_CANUSB
-#include "pcap-canusb-linux.h"
-#endif
-
-#ifdef PCAP_SUPPORT_NETFILTER
-#include "pcap-netfilter-linux.h"
-#endif
-
/*
* If PF_PACKET is defined, we can use {SOCK_RAW,SOCK_DGRAM}/PF_PACKET
* sockets rather than SOCK_PACKET sockets.
#endif /* SO_ATTACH_FILTER */
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *handle;
- /*
- * A null device name is equivalent to the "any" device.
- */
- if (device == NULL)
- device = "any";
-
-#ifdef HAVE_DAG_API
- if (strstr(device, "dag")) {
- return dag_create(device, ebuf);
- }
-#endif /* HAVE_DAG_API */
-
-#ifdef HAVE_SEPTEL_API
- if (strstr(device, "septel")) {
- return septel_create(device, ebuf);
- }
-#endif /* HAVE_SEPTEL_API */
-
-#ifdef HAVE_SNF_API
- handle = snf_create(device, ebuf);
- if (strstr(device, "snf") || handle != NULL)
- return handle;
-
-#endif /* HAVE_SNF_API */
-
-#ifdef PCAP_SUPPORT_BT
- if (strstr(device, "bluetooth")) {
- return bt_create(device, ebuf);
- }
-#endif
-
-#if PCAP_SUPPORT_CANUSB
- if (strstr(device, "canusb")) {
- return canusb_create(device, ebuf);
- }
-#endif
-
-#ifdef PCAP_SUPPORT_CAN
- if ((strncmp(device, "can", 3) == 0 && isdigit(device[3])) ||
- (strncmp(device, "vcan", 4) == 0 && isdigit(device[4]))) {
- return can_create(device, ebuf);
- }
-#endif
-
-#ifdef PCAP_SUPPORT_USB
- if (strstr(device, "usbmon")) {
- return usb_create(device, ebuf);
- }
-#endif
-
-#ifdef PCAP_SUPPORT_NETFILTER
- if (strncmp(device, "nflog", strlen("nflog")) == 0) {
- return nflog_create(device, ebuf);
- }
-#endif
-
handle = pcap_create_common(device, ebuf);
if (handle == NULL)
return NULL;
if (pcap_add_if(alldevsp, "any", 0, any_descr, errbuf) < 0)
return (-1);
-#ifdef HAVE_DAG_API
- /*
- * Add DAG devices.
- */
- if (dag_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif /* HAVE_DAG_API */
-
-#ifdef HAVE_SEPTEL_API
- /*
- * Add Septel devices.
- */
- if (septel_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif /* HAVE_SEPTEL_API */
-
-#ifdef HAVE_SNF_API
- if (snf_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif /* HAVE_SNF_API */
-
-#ifdef PCAP_SUPPORT_BT
- /*
- * Add Bluetooth devices.
- */
- if (bt_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif
-
-#ifdef PCAP_SUPPORT_USB
- /*
- * Add USB devices.
- */
- if (usb_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif
-
-#ifdef PCAP_SUPPORT_NETFILTER
- /*
- * Add netfilter devices.
- */
- if (netfilter_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif
-
-#if PCAP_SUPPORT_CANUSB
- if (canusb_platform_finddevs(alldevsp, errbuf) < 0)
- return (-1);
-#endif
-
return (0);
}
pcap_t *
nflog_create(const char *device, char *ebuf)
{
+ char *cp;
pcap_t *p;
+ /* Does this look like an nflog device? */
+ cp = strrchr(device, '/');
+ if (cp == NULL)
+ cp = device;
+ /* Does it begin with NFLOG_IFACE? */
+ if (strncmp(cp, NFLOG_IFACE, sizeof NFLOG_IFACE - 1) != 0) {
+ /* Nope, doesn't begin with NFLOG_IFACE */
+ *is_ours = 0;
+ return NULL;
+ }
+ /*
+ * Yes - is that either the end of the name, or is it followed
+ * by a colon?
+ */
+ cp += sizeof NFLOG_IFACE - 1;
+ if (*cp != ':' && *cp != '\0') {
+ /* Nope */
+ *is_ours = 0;
+ return NULL;
+ }
+
+ /* OK, it's probably ours. */
+ *is_ours = 1;
+
p = pcap_create_common(device, ebuf);
if (p == NULL)
return (NULL);
}
int
-netfilter_platform_finddevs(pcap_if_t **alldevsp, char *err_str)
+nflog_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
pcap_if_t *found_dev = *alldevsp;
int sock;
return -1;
return 0;
}
-
/*
* Prototypes for netlink-related functions
*/
-int netfilter_platform_finddevs(pcap_if_t **alldevsp, char *err_str);
-pcap_t *nflog_create(const char *device, char *ebuf);
+int nflog_findalldevs(pcap_if_t **alldevsp, char *err_str);
+pcap_t *nflog_create(const char *device, char *ebuf, int *is_ours);
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
static char nosup[] = "live packet capture not supported on this system";
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
(void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
return (NULL);
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
#include <sys/types.h>
#include <unistd.h>
-#ifdef HAVE_SEPTEL_API
#include <msg.h>
#include <ss7_inc.h>
#include <sysgct.h>
#include <pack.h>
#include <system.h>
-#endif /* HAVE_SEPTEL_API */
-#ifdef SEPTEL_ONLY
-/* This code is required when compiling for a Septel device only. */
#include "pcap-septel.h"
-/* Replace septel function names with pcap equivalent. */
-#define septel_create pcap_create
-#define septel_platform_finddevs pcap_platform_finddevs
-#endif /* SEPTEL_ONLY */
-
static int septel_setfilter(pcap_t *p, struct bpf_program *fp);
static int septel_stats(pcap_t *p, struct pcap_stat *ps);
static int septel_setnonblock(pcap_t *p, int nonblock, char *errbuf);
return 0;
}
-pcap_t *septel_create(const char *device, char *ebuf) {
+pcap_t *septel_create(const char *device, char *ebuf, int *is_ours) {
+ char *cp;
pcap_t *p;
+ /* Does this look like the Septel device? */
+ cp = strrchr(device, '/');
+ if (cp == NULL)
+ cp = device;
+ if (strcmp(cp, "septel") != 0) {
+ /* Nope, it's not "septel" */
+ *is_ours = 0;
+ return NULL;
+ }
+
+ /* OK, it's probably ours. */
+ *is_ours = 1;
+
p = pcap_create_common(device, ebuf);
if (p == NULL)
return NULL;
int
-septel_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
+septel_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
unsigned char *p;
const char description[512]= "Intel/Septel device";
* @(#) $Header: /tcpdump/master/libpcap/pcap-septel.h,v 1.2 2008-04-04 19:37:45 guy Exp $
*/
-pcap_t *septel_create(const char *device, char *ebuf);
-
+pcap_t *septel_create(const char *device, char *ebuf, int *is_ours);
+int septel_findalldevs(pcap_if_t **devlistp, char *errbuf);
iface_t *p;
pcap_if_t *alldevsp;
- pcap_findalldevs(&alldevsp, errbuf);
+ pcap_findalldevs_interfaces(&alldevsp, errbuf);
for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { /* scan the table... */
for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
u = &units[chassis][geoslot];
return 0;
}
-pcap_t *pcap_create(const char *device, char *ebuf) {
+pcap_t *pcap_create_interface(const char *device, char *ebuf) {
pcap_t *p;
p = pcap_create_common(device, ebuf);
#include "snf.h"
#include "pcap-int.h"
-#ifdef SNF_ONLY
-#define snf_create pcap_create
-#define snf_platform_finddevs pcap_platform_finddevs
-#endif
-
static int
snf_set_datalink(pcap_t *p, int dlt)
{
}
int
-snf_platform_finddevs(pcap_if_t **devlistp, char *errbuf)
+snf_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
/*
* There are no platform-specific devices since each device
}
pcap_t *
-snf_create(const char *device, char *ebuf)
+snf_create(const char *device, char *ebuf, int *is_ours)
{
pcap_t *p;
int boardnum = -1;
struct snf_ifaddrs *ifaddrs, *ifa;
size_t devlen;
- if (snf_init(SNF_VERSION_API))
+ if (snf_init(SNF_VERSION_API)) {
+ /* Can't initialize the API, so no SNF devices */
+ *is_ours = 0;
return NULL;
+ }
/*
* Match a given interface name to our list of interface names, from
* which we can obtain the intended board number
*/
- if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL)
+ if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL) {
+ /* Can't get SNF addresses */
+ *is_ours = 0;
return NULL;
+ }
devlen = strlen(device) + 1;
ifa = ifaddrs;
while (ifa) {
* and "snf10gX" where X is the board number.
*/
if (sscanf(device, "snf10g%d", &boardnum) != 1 &&
- sscanf(device, "snf%d", &boardnum) != 1)
+ sscanf(device, "snf%d", &boardnum) != 1) {
+ /* Nope, not a supported name */
+ *is_ours = 0;
return NULL;
+ }
}
+ /* OK, it's probably ours. */
+ *is_ours = 1;
+
p = pcap_create_common(device, ebuf);
if (p == NULL)
return NULL;
-pcap_t *snf_create(const char *, char *);
-int snf_platform_finddevs(pcap_if_t **devlistp, char *errbuf);
+pcap_t *snf_create(const char *, char *, int *);
+int snf_findalldevs(pcap_if_t **devlistp, char *errbuf);
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
}
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;
}
pcap_t *
-usb_create(const char *device, char *ebuf)
+usb_create(const char *device, char *ebuf, int *is_ours)
{
+ char *cp, *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);
/*
* Prototypes for USB-related functions
*/
-int usb_platform_finddevs(pcap_if_t **alldevsp, char *err_str);
-pcap_t *usb_create(const char *device, char *ebuf);
+int usb_findalldevs(pcap_if_t **alldevsp, char *err_str);
+pcap_t *usb_create(const char *device, char *ebuf, int *is_ours);
}
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
#include "pcap-int.h"
#ifdef HAVE_DAG_API
-#include <dagnew.h>
-#include <dagapi.h>
+#include "pcap-dag.h"
+#endif /* HAVE_DAG_API */
+
+#ifdef HAVE_SEPTEL_API
+#include "pcap-septel.h"
+#endif /* HAVE_SEPTEL_API */
+
+#ifdef HAVE_SNF_API
+#include "pcap-snf.h"
+#endif /* HAVE_SNF_API */
+
+#ifdef PCAP_SUPPORT_USB
+#include "pcap-usb-linux.h"
+#endif
+
+#ifdef PCAP_SUPPORT_BT
+#include "pcap-bt-linux.h"
+#endif
+
+#ifdef PCAP_SUPPORT_CAN
+#include "pcap-can-linux.h"
+#endif
+
+#ifdef PCAP_SUPPORT_CANUSB
+#include "pcap-canusb-linux.h"
+#endif
+
+#ifdef PCAP_SUPPORT_NETFILTER
+#include "pcap-netfilter-linux.h"
#endif
int
return (p->read_op(p, 1, p->oneshot_callback, (u_char *)&s));
}
+#if defined(DAG_ONLY)
+int
+pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+{
+ return (dag_findalldevs(alldevsp, errbuf));
+}
+
+pcap_t *
+pcap_create(const char *source, char *errbuf)
+{
+ return (dag_create(source, errbuf));
+}
+#elif defined(SEPTEL_ONLY)
+int
+pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+{
+ return (septel_findalldevs(alldevsp, errbuf));
+}
+
+pcap_t *
+pcap_create(const char *source, char *errbuf)
+{
+ return (septel_create(source, errbuf));
+}
+#elif defined(SNF_ONLY)
+int
+pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+{
+ return (snf_findalldevs(alldevsp, errbuf));
+}
+
+pcap_t *
+pcap_create(const char *source, char *errbuf)
+{
+ return (snf_create(source, errbuf));
+}
+#else /* regular pcap */
+struct capture_source_type {
+ int (*findalldevs_op)(pcap_if_t **, char *);
+ pcap_t *(*create_op)(const char *, char *, int *);
+} capture_source_types[] = {
+#ifdef HAVE_DAG_API
+ { dag_findalldevs, dag_create },
+#endif
+#ifdef HAVE_SEPTEL_API
+ { septel_findalldevs, septel_create },
+#endif
+#ifdef HAVE_SNF_API
+ { snf_findalldevs, snf_create },
+#endif
+#ifdef PCAP_SUPPORT_BT
+ { bt_findalldevs, bt_create },
+#endif
+#if PCAP_SUPPORT_CANUSB
+ { canusb_findalldevs, canusb_create },
+#endif
+#ifdef PCAP_SUPPORT_CAN
+ { can_findalldevs, can_create },
+#endif
+#ifdef PCAP_SUPPORT_USB
+ { usb_findalldevs, usb_create },
+#endif
+#ifdef PCAP_SUPPORT_NETFILTER
+ { nflog_findalldevs, nflog_create },
+#endif
+};
+
+#define N_CAPTURE_SOURCE_TYPES (sizeof capture_source_types / sizeof capture_source_types[0])
+
+/*
+ * Get a list of all capture sources that are up and that we can open.
+ * Returns -1 on error, 0 otherwise.
+ * The list, as returned through "alldevsp", may be null if no interfaces
+ * were up and could be opened.
+ */
+int
+pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
+{
+ size_t i;
+
+ /*
+ * Get the list of regular interfaces first.
+ */
+ if (pcap_findalldevs_interfaces(alldevsp, errbuf) == -1)
+ return (-1); /* failure */
+
+ /*
+ * Add any interfaces that need a platform-specific mechanism
+ * to find.
+ */
+ if (pcap_platform_finddevs(alldevsp, errbuf) == -1) {
+ /*
+ * We had an error; free the list we've been
+ * constructing.
+ */
+ if (*alldevsp != NULL) {
+ pcap_freealldevs(*alldevsp);
+ *alldevsp = NULL;
+ }
+ return (-1);
+ }
+
+ /*
+ * Ask each of the non-local-network-interface capture
+ * source types what interfaces they have.
+ */
+ for (i = 0; i < N_CAPTURE_SOURCE_TYPES; i++) {
+ if (capture_source_types[i].findalldevs_op(alldevsp, errbuf) == -1) {
+ /*
+ * We had an error; free the list we've been
+ * constructing.
+ */
+ if (*alldevsp != NULL) {
+ pcap_freealldevs(*alldevsp);
+ *alldevsp = NULL;
+ }
+ return (-1);
+ }
+ }
+ return (0);
+}
+
+pcap_t *
+pcap_create(const char *source, char *errbuf)
+{
+ size_t i;
+ int is_theirs;
+ pcap_t *p;
+
+ /*
+ * A null source name is equivalent to the "any" device -
+ * which might not be supported on this platform, but
+ * this means that you'll get a "not supported" error
+ * rather than, say, a crash when we try to dereference
+ * the null pointer.
+ */
+ if (source == NULL)
+ source = "any";
+
+ /*
+ * Try each of the non-local-network-interface capture
+ * source types until we find one that works for this
+ * device or run out of types.
+ */
+ for (i = 0; i < N_CAPTURE_SOURCE_TYPES; i++) {
+ is_theirs = 0;
+ p = capture_source_types[i].create_op(source, errbuf, &is_theirs);
+ if (is_theirs) {
+ /*
+ * The device name refers to a device of the
+ * type in question; either it succeeded,
+ * in which case p refers to a pcap_t to
+ * later activate for the device, or it
+ * failed, in which case p is null and we
+ * should return that to report the failure
+ * to create.
+ */
+ return (p);
+ }
+ }
+
+ /*
+ * OK, try it as a regular network interface.
+ */
+ return (pcap_create_interface(source, errbuf));
+}
+#endif
+
static void
initialize_ops(pcap_t *p)
{