Skip to content

Commit

Permalink
Display interface name and index on DLT_LINUX_SLL2
Browse files Browse the repository at this point in the history
When in reading mode display warning about possible wrong interfaces.
(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 <pvorel@suse.cz>
Suggested-by: Guy Harris <guy@alum.mit.edu>
  • Loading branch information
pevik committed Jul 18, 2018
1 parent eb962af commit 13c3538
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmakeconfig.h.in
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -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>])
Expand Down
14 changes: 14 additions & 0 deletions print-sll.c
Expand Up @@ -25,6 +25,10 @@
#include <config.h>
#endif

#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif

#include "netdissect-stdinc.h"

#include "netdissect.h"
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tcpdump.c
Expand Up @@ -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.
Expand Down

0 comments on commit 13c3538

Please sign in to comment.