From: Petr Vorel Date: Thu, 12 Jul 2018 20:01:43 +0000 (+0200) Subject: Display interface and index and name on DLT_LINUX_SLL2 X-Git-Tag: tcpdump-4.99-bp~1094 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/152acc2ece46a796779503d103ff6a0deb90cbc1 Display interface and index and name on DLT_LINUX_SLL2 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 Suggested-by: Guy Harris Reviewed-by: Denis Ovsienko Reviewed-by: Guy Harris --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ff02c8bb..ab5f8355 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index a29fc638..9e2c0268 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -78,6 +78,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_NETDNET_DN_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NET_IF_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_NET_IF_PFLOG_H 1 diff --git a/config.h.in b/config.h.in index 4fcbba77..8ae16730 100644 --- a/config.h.in +++ b/config.h.in @@ -78,6 +78,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETDNET_DN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NET_IF_H + /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_PFLOG_H diff --git a/configure b/configure index eb33db18..f64c4eea 100755 --- 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" diff --git a/configure.ac b/configure.ac index 32f48b60..46f841c0 100644 --- a/configure.ac +++ b/configure.ac @@ -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 #include #include ]) diff --git a/print-sll.c b/print-sll.c index 96031442..e6c7bd4a 100644 --- a/print-sll.c +++ b/print-sll.c @@ -25,6 +25,10 @@ #include #endif +#ifdef HAVE_NET_IF_H +#include +#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); diff --git a/tcpdump.c b/tcpdump.c index 2bef72c8..0ef21117 100644 --- 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.