The directory to scan is just /dev, which is wired into the udev source,
at least in the systemd source tree. Just scan that directory, rather
than using using udevinfo to find out the directory. (If there is ever
a reason to look anywhere there than /dev for the usbmon devices - and,
if so, there had better be a good reason, as stuffing special files
anywhere other than /dev on any UN*X, including Linux, will break
programs that use /dev/null or /dev/tty, among other well-known devices
- then provide a mechanism that works at *run time*, so that it works
even for cross-builds libpcap, and that works regardless of whether the
machine on which the built version of libpcap has udev and whether it
has udevinfo or udevadm or whatever.)
(cherry picked from commit
52d9062fcd8d3ae8cef695f7a1c630f3dde5b968)
if(NOT DISABLE_LINUX_USBMON)
set(PCAP_SUPPORT_LINUX_USBMON TRUE)
set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
- set(LINUX_USB_MON_DEV /dev/usbmon)
#
# Do we have a version of <linux/compiler.h> available?
# If so, we might need it for <linux/usbdevice_fs.h>.
/* IPv6 */
#cmakedefine INET6 1
-/* path for device for USB sniffing */
-#cmakedefine LINUX_USB_MON_DEV "@LINUX_USB_MON_DEV@"
-
/* Define to 1 if netinet/ether.h declares `ether_hostton' */
#cmakedefine NETINET_ETHER_H_DECLARES_ETHER_HOSTTON 1
/* IPv6 */
#undef INET6
-/* path for device for USB sniffing */
-#undef LINUX_USB_MON_DEV
-
/* Define to 1 if netinet/ether.h declares `ether_hostton' */
#undef NETINET_ETHER_H_DECLARES_ETHER_HOSTTON
MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
- if test $? -ne 0 ; then
- ac_usb_dev_name="usbmon"
- fi
-
-cat >>confdefs.h <<_ACEOF
-#define LINUX_USB_MON_DEV "/dev/$ac_usb_dev_name"
-_ACEOF
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: Device for USB sniffing is /dev/$ac_usb_dev_name" >&5
-$as_echo "$as_me: Device for USB sniffing is /dev/$ac_usb_dev_name" >&6;}
+ #
+ # Note: if the directory for special files is *EVER* somewhere
+ # other than the UN*X standard of /dev (which will break any
+ # software that looks for /dev/null or /dev/tty, for example,
+ # so doing that is *REALLY* not a good idea), please provide
+ # some mechanism to determine that directory at *run time*,
+ # rather than *configure time*, so that it works when doinga
+ # a cross-build, and that works with *multiple* distributions,
+ # with our without udev, and with multiple versions of udev,
+ # with udevinfo or udevadm or any other mechanism to get the
+ # special files directory.
#
# Do we have a version of <linux/compiler.h> available?
# If so, we might need it for <linux/usbdevice_fs.h>.
AC_DEFINE(PCAP_SUPPORT_LINUX_USBMON, 1, [target host supports Linux usbmon for USB sniffing])
MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
AC_MSG_RESULT(yes)
- ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
- if test $? -ne 0 ; then
- ac_usb_dev_name="usbmon"
- fi
- AC_DEFINE_UNQUOTED(LINUX_USB_MON_DEV, "/dev/$ac_usb_dev_name", [path for device for USB sniffing])
- AC_MSG_NOTICE(Device for USB sniffing is /dev/$ac_usb_dev_name)
+ #
+ # Note: if the directory for special files is *EVER* somewhere
+ # other than the UN*X standard of /dev (which will break any
+ # software that looks for /dev/null or /dev/tty, for example,
+ # so doing that is *REALLY* not a good idea), please provide
+ # some mechanism to determine that directory at *run time*,
+ # rather than *configure time*, so that it works when doinga
+ # a cross-build, and that works with *multiple* distributions,
+ # with our without udev, and with multiple versions of udev,
+ # with udevinfo or udevadm or any other mechanism to get the
+ # special files directory.
#
# Do we have a version of <linux/compiler.h> available?
# If so, we might need it for <linux/usbdevice_fs.h>.
#include "diag-control.h"
#define USB_IFACE "usbmon"
+
+#define USBMON_DEV_PREFIX "usbmon"
+#define USBMON_DEV_PREFIX_LEN (sizeof USBMON_DEV_PREFIX - 1)
#define USB_LINE_LEN 4096
#if __BYTE_ORDER == __LITTLE_ENDIAN
int
usb_findalldevs(pcap_if_list_t *devlistp, char *err_str)
{
- char usb_mon_dir[PATH_MAX];
- char *usb_mon_prefix;
- size_t usb_mon_prefix_len;
struct dirent* data;
int ret = 0;
DIR* dir;
/*
* We require 2.6.27 or later kernels, so we have binary-mode support.
- * What do the device names look like?
- * Split LINUX_USB_MON_DEV into a directory that we'll
- * scan and a file name prefix that we'll check for.
- */
- pcap_strlcpy(usb_mon_dir, LINUX_USB_MON_DEV, sizeof usb_mon_dir);
- usb_mon_prefix = strrchr(usb_mon_dir, '/');
- if (usb_mon_prefix == NULL) {
- /*
- * This "shouldn't happen". Just give up if it
- * does.
- */
- return 0;
- }
- *usb_mon_prefix++ = '\0';
- usb_mon_prefix_len = strlen(usb_mon_prefix);
-
- /*
- * Open the directory and scan it.
+ * The devices are of the form /dev/usbmon{N}.
+ * Open /dev and scan it.
*/
- dir = opendir(usb_mon_dir);
+ dir = opendir("/dev");
if (dir != NULL) {
while ((ret == 0) && ((data = readdir(dir)) != 0)) {
name = data->d_name;
/*
* Is this a usbmon device?
*/
- if (strncmp(name, usb_mon_prefix, usb_mon_prefix_len) != 0)
+ if (strncmp(name, USBMON_DEV_PREFIX,
+ USBMON_DEV_PREFIX_LEN) != 0)
continue; /* no */
/*
* What's the device number?
*/
- if (sscanf(&name[usb_mon_prefix_len], "%d", &n) == 0)
+ if (sscanf(&name[USBMON_DEV_PREFIX_LEN], "%d", &n) == 0)
continue; /* failed */
ret = usb_dev_add(devlistp, n, err_str);
* We require 2.6.27 or later kernels, so we have binary-mode support.
* Try to open the binary interface.
*/
- snprintf(full_path, USB_LINE_LEN, LINUX_USB_MON_DEV"%d", handlep->bus_index);
+ snprintf(full_path, USB_LINE_LEN, "/dev/"USBMON_DEV_PREFIX"%d",
+ handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
if (handle->fd < 0)
{