]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Display interface and index and name on DLT_LINUX_SLL2
authorPetr Vorel <[email protected]>
Thu, 12 Jul 2018 20:01:43 +0000 (22:01 +0200)
committerDenis Ovsienko <[email protected]>
Thu, 19 Jul 2018 06:15:11 +0000 (07:15 +0100)
Index is displayed always, name only if available.

Warn about possible wrong interfaces when in reading mode
(pcap file can be displayed on a different host then where
was captured) [1].

See: GH the-tcpdump-group/libpcap#127

[1] https://lists.sandelman.ca/pipermail/tcpdump-workers/2018-July/001019.html

Signed-off-by: Petr Vorel <[email protected]>
Suggested-by: Guy Harris <[email protected]>
Reviewed-by: Denis Ovsienko <[email protected]>
Reviewed-by: Guy Harris <[email protected]>
CMakeLists.txt
cmakeconfig.h.in
config.h.in
configure
configure.ac
print-sll.c
tcpdump.c

index ff02c8bb4578d0cc145bca212403f816ccded3d7..ab5f8355893de9aa867574453b030ea2e0eb844f 100644 (file)
@@ -191,6 +191,7 @@ include(CheckTypeSize)
 #
 check_include_file(fcntl.h HAVE_FCNTL_H)
 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 a29fc638261d6605e757f803fbb1cf47c27bf11e..9e2c0268dc0a3e34a3e671b8b6ce9cc076639a8c 100644 (file)
@@ -78,6 +78,9 @@
 /* Define to 1 if you have the <netdnet/dn.h> header file. */
 #cmakedefine HAVE_NETDNET_DN_H 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 <net/if_pflog.h> header file. */
 #cmakedefine HAVE_NET_IF_PFLOG_H 1
 
index 4fcbba77efe1ada2b6250dc76f8304b3bb63e348..8ae16730ffb65716c0b0ae4caa128f66d08d06bd 100644 (file)
@@ -78,6 +78,9 @@
 /* Define to 1 if you have the <netdnet/dn.h> header file. */
 #undef HAVE_NETDNET_DN_H
 
+/* Define to 1 if you have the <net/if.h> header file. */
+#undef HAVE_NET_IF_H
+
 /* Define to 1 if you have the <net/if_pflog.h> header file. */
 #undef HAVE_NET_IF_PFLOG_H
 
index eb33db18e17d37c5c6d3c2a49a201c34cd7f3354..f64c4eea51abd54f83fce537315c33e37dbb64a7 100755 (executable)
--- a/configure
+++ b/configure
@@ -4037,7 +4037,7 @@ fi
 done
 
 
-for ac_header in fcntl.h rpc/rpc.h rpc/rpcent.h
+for ac_header in fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
index 32f48b606b3e7cc4cfec1e42077102ff233c7893..46f841c0349e9d0d2d5b71e6c1f70fc83593ccb0 100644 (file)
@@ -24,7 +24,7 @@ AC_PROG_CC_C99
 AC_LBL_C_INIT(V_CCOPT, V_INCLS)
 AC_LBL_C_INLINE
 
-AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h)
+AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
 AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
 #include <sys/socket.h>
 #include <net/if.h>])
index 960314427de9b43bb52c0132888a2e17cfdeeb78..e6c7bd4a7e9e89671cb80a282b72e5f605d434d5 100644 (file)
 #include <config.h>
 #endif
 
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+
 #include "netdissect-stdinc.h"
 
 #include "netdissect.h"
@@ -395,6 +399,9 @@ 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
+       char ifname[IF_NAMESIZE];
+#endif
 
        ndo->ndo_protocol = "sll2_if";
        if (caplen < SLL2_HDR_LEN) {
@@ -408,6 +415,13 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
        }
 
        sllp = (const struct sll2_header *)p;
+#ifdef HAVE_NET_IF_H
+       uint32_t index = EXTRACT_BE_U_4(sllp->sll2_if_index);
+       if (if_indextoname(index, ifname))
+               ND_PRINT("ifindex %u (%s) ", index, ifname);
+       else
+               ND_PRINT("ifindex %u ", index);
+#endif
 
        if (ndo->ndo_eflag)
                sll2_print(ndo, sllp, length);
index 2bef72c8e5fc911e4b500353fd2041adc7829127..0ef211171a9d14d8658e2c341e4c4ae1e63d887f 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1978,6 +1978,10 @@ main(int argc, char **argv)
                            RFileName, dlt_name,
                            pcap_datalink_val_to_description(dlt));
                }
+#ifdef DLT_LINUX_SLL2
+               if (dlt == DLT_LINUX_SLL2)
+                       fprintf(stderr, "Warning: interface names might be incorrect\n");
+#endif
        } else {
                /*
                 * We're doing a live capture.