]> The Tcpdump Group git mirrors - tcpdump/commitdiff
SLL2: Translate interface indices to names on Linux only. 1163/head
authorDenis Ovsienko <[email protected]>
Mon, 1 Apr 2024 12:26:28 +0000 (13:26 +0100)
committerDenis Ovsienko <[email protected]>
Tue, 2 Apr 2024 10:36:13 +0000 (11:36 +0100)
print-sll.c uses HAVE_NET_IF_H, which does not always work right: the
header is in POSIX.1-2001, but the result of if_indextoname() is
irrelevant if the current OS is not Linux, in which case the packet was
captured on a different host because libpcap produces DLT_LINUX_SLL2 on
Linux only.  The result can be irrelevant on Linux too, but this does
not have an easy solution.

To reduce the problem space, switch print-sll.c to check for __linux__
instead.  In tcpdump.c print the warning about interface names only if
sll2_if_print() would print interface names.  Since HAVE_NET_IF_H has no
purpose now, remove the checks for <net/if.h>.

CHANGES
CMakeLists.txt
cmakeconfig.h.in
configure.ac
print-sll.c
tcpdump.c

diff --git a/CHANGES b/CHANGES
index 44e0eb2380de175086e3c801549b3ea3d7ff1f64..7aa9021dc2a68eb9956e9d377dbb8e7bbaa98058 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
         advance the packet data pointer
       OSPF: Print more truncation indications
       OSPF: Add more length checks
+      SLL2: Translate interface indices to names on Linux only.
       TCP: Add support for the AE (AccECN) flag.
     User interface:
       Add optional unit suffix on -C file size.
index b120511d9cf78a33b32fc0894555ec98239da13a..ad511ca67e520c206025fe6e654e6ed50a99640b 100644 (file)
@@ -344,7 +344,6 @@ cmake_pop_check_state()
 # Header files.
 #
 check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
-check_include_file(net/if.h HAVE_NET_IF_H)
 if(HAVE_RPC_RPC_H)
     check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
 endif(HAVE_RPC_RPC_H)
index 37f398c422c56570e6c5ad3ca0f6332990cbcef6..95e7adb48d4275a88da3978f396c9ce2aaffc2e1 100644 (file)
@@ -60,9 +60,6 @@
 /* Define to 1 if you have the `rpc' library (-lrpc). */
 #cmakedefine HAVE_LIBRPC 1
 
-/* Define to 1 if you have the <net/if.h> header file. */
-#cmakedefine HAVE_NET_IF_H 1
-
 /* Define to 1 if you have the `openat' function. */
 #cmakedefine HAVE_OPENAT 1
 
index 1ec630461e88a1555cdaf8179f235cfb61eb8964..a35a8806638cd4d00cc22324e3d65c99db592f0f 100644 (file)
@@ -30,7 +30,7 @@ if test "$ac_cv_prog_cc_c99" = "no"; then
 fi
 AC_LBL_C_INIT(V_CCOPT, V_INCLS)
 
-AC_CHECK_HEADERS(rpc/rpc.h rpc/rpcent.h net/if.h)
+AC_CHECK_HEADERS(rpc/rpc.h rpc/rpcent.h)
 #
 # Get the size of a void *, to know whether this is a 32-bit or 64-bit build.
 #
index 3a760aef0a02d5c4d7911390ecd5258cbdcc458f..a86bacef6cd21a776f7283c7820192b15293c761 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <config.h>
 
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
 #include <net/if.h>
 #endif
 
@@ -403,7 +403,7 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        u_short ether_type;
        int llc_hdrlen;
        u_int hdrlen;
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
        uint32_t if_index;
        char ifname[IF_NAMESIZE];
 #endif
@@ -412,7 +412,7 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        ND_TCHECK_LEN(p, SLL2_HDR_LEN);
 
        sllp = (const struct sll2_header *)p;
-#ifdef HAVE_NET_IF_H
+#ifdef __linux__
        if_index = GET_BE_U_4(sllp->sll2_if_index);
        if (!if_indextoname(if_index, ifname))
                strncpy(ifname, "?", 2);
index e4c52c5e4f301890bf14a367a3aab81db7118879..51480dce4f5e6eb374a89dedfb2a83ece42de56c 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -2166,7 +2166,7 @@ main(int argc, char **argv)
                                pcap_datalink_val_to_description(dlt));
                }
                fprintf(stderr, ", snapshot length %d\n", pcap_snapshot(pd));
-#ifdef DLT_LINUX_SLL2
+#if defined(DLT_LINUX_SLL2) && defined(__linux__)
                if (dlt == DLT_LINUX_SLL2)
                        fprintf(stderr, "Warning: interface names might be incorrect\n");
 #endif