]> The Tcpdump Group git mirrors - libpcap/commitdiff
Fix "tcpdump -i <n>" for something-only libpcap builds.
authorDenis Ovsienko <[email protected]>
Thu, 14 Nov 2024 08:15:02 +0000 (08:15 +0000)
committerDenis Ovsienko <[email protected]>
Thu, 14 Nov 2024 08:24:27 +0000 (08:24 +0000)
pcap_create() returns NULL for all errors, so tcpdump tries to find
evidence of ENODEV in the error buffer in order to retry using a
different device name.  That does not work when the error string is
"This version of libpcap only supports...", so use a format string that
works and place it in pcap-int.h.

# tcpdump --version
tcpdump version 5.0.0-PRE-GIT
libpcap version 1.11.0-PRE-GIT (DAG-only)

# tcpdump -D
1.dag0 (alias for dag0:0) [none]
2.dag0:0 (Rx stream 0, 64 MiB, DAG 7.5G2 rev A at 0000:01:00.0) [none]
3.dag1 (alias for dag1:0) [none]
4.dag1:0 (Rx stream 0, 64 MiB, DAG 9.2X2 rev D at 0000:02:00.0) [none]
5.dag16 (alias for dag16:0) [none]
6.dag16:0 (Rx stream 0, 64 MiB, vDAG) [none]

Before:

# tcpdump -ni 1
tcpdump: This version of libpcap only supports DAG cards

After:

# tcpdump -ni abcde
tcpdump: No such device (this build of libpcap supports DAG devices only).

# tcpdump -ni 1
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on dag0, link-type EN10MB (Ethernet), snapshot length 262144 bytes

CHANGES
pcap-dag.c
pcap-dpdk.c
pcap-int.h
pcap-septel.c
pcap-snf.c

diff --git a/CHANGES b/CHANGES
index 4e4e86a85055cda4deea02ec939e9f0bf1cab0e7..7ecc8452f620195b46af6434fa270270322c4265 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
       Merge four header files into gencode.c.
       Remove DAG card support on Windows as Linux is the only
         platform currently supported.
+      Fix "tcpdump -i <n>" for something-only libpcap builds.
     Link-layer types:
       Add LINKTYPE_ETW/DLT_ETW.
       Add LINKTYPE_NETANALYZER_NG/DLT_NETANALYZER_NG (pull request
index 13f5f35e7bcd8a91a98a409b6ff1762993588c1e..e11ebb29719546f7f4d475db4ac34874e9f9d4ba 100644 (file)
@@ -1449,8 +1449,7 @@ pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf _U_)
 pcap_t *
 pcapint_create_interface(const char *device _U_, char *errbuf)
 {
-       snprintf(errbuf, PCAP_ERRBUF_SIZE,
-           "This version of libpcap only supports DAG cards");
+       snprintf(errbuf, PCAP_ERRBUF_SIZE, PCAP_ENODEV_MESSAGE, "DAG");
        return NULL;
 }
 
index 794fae3932120047b4c36b8d4d09e77561cc9199..76de9b769084c2aef5728db3eb0b01ee433fe374 100644 (file)
@@ -1068,8 +1068,7 @@ pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
 pcap_t *
 pcapint_create_interface(const char *device, char *errbuf)
 {
-       snprintf(errbuf, PCAP_ERRBUF_SIZE,
-           "This version of libpcap only supports DPDK");
+       snprintf(errbuf, PCAP_ERRBUF_SIZE, PCAP_ENODEV_MESSAGE, "DPDK");
        return NULL;
 }
 
index 3b85492915cae7a7d304c8b9082d3e3f17642fcc..9fd41a946b687704a9ece4d30dd9604a386b5cbe 100644 (file)
@@ -413,6 +413,14 @@ int        pcapint_setnonblock_fd(pcap_t *p, int);
  * by pcap_create routines.
  */
 pcap_t *pcapint_create_interface(const char *, char *);
+/*
+ * A format string for something-only libpcap builds, which use a stub
+ * implementation of pcapint_create_interface().  It contains the substring
+ * "No such device" (one of the standard descriptions of ENODEV) -- this way
+ * tcpdump can detect a particular error condition even though pcap_create()
+ * returns NULL for all errors.
+ */
+#define PCAP_ENODEV_MESSAGE "No such device (this build of libpcap supports %s devices only)."
 
 /*
  * This wrapper takes an error buffer pointer and a type to use for the
index 4546e44aed35cd0a1c94d5f39d8b29a77e6228e1..033a181e4f2cf065c1ab01829d1ecfaa1a44cdc9 100644 (file)
@@ -308,8 +308,7 @@ pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
 pcap_t *
 pcapint_create_interface(const char *device, char *errbuf)
 {
-  snprintf(errbuf, PCAP_ERRBUF_SIZE,
-                "This version of libpcap only supports Septel cards");
+       snprintf(errbuf, PCAP_ERRBUF_SIZE, PCAP_ENODEV_MESSAGE, "Septel");
   return (NULL);
 }
 
index 959cf20f7a49401826a297af66bd6932b8ce54ba..6dcc6ca21c567ca0e61da83ea943cbabde6cf86b 100644 (file)
@@ -608,8 +608,7 @@ pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf _U_)
 pcap_t *
 pcapint_create_interface(const char *device _U_, char *errbuf)
 {
-       snprintf(errbuf, PCAP_ERRBUF_SIZE,
-           "This version of libpcap only supports SNF cards");
+       snprintf(errbuf, PCAP_ERRBUF_SIZE, PCAP_ENODEV_MESSAGE, "SNF");
        return NULL;
 }