Skip to content

Commit 0e04b9d

Browse files
committed
SLL2: Translate interface indices to names on Linux only.
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>.
1 parent b779eda commit 0e04b9d

File tree

6 files changed

+6
-9
lines changed

6 files changed

+6
-9
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
2626
advance the packet data pointer
2727
OSPF: Print more truncation indications
2828
OSPF: Add more length checks
29+
SLL2: Translate interface indices to names on Linux only.
2930
TCP: Add support for the AE (AccECN) flag.
3031
User interface:
3132
Add optional unit suffix on -C file size.

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ cmake_pop_check_state()
344344
# Header files.
345345
#
346346
check_include_file(rpc/rpc.h HAVE_RPC_RPC_H)
347-
check_include_file(net/if.h HAVE_NET_IF_H)
348347
if(HAVE_RPC_RPC_H)
349348
check_include_files("rpc/rpc.h;rpc/rpcent.h" HAVE_RPC_RPCENT_H)
350349
endif(HAVE_RPC_RPC_H)

cmakeconfig.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
/* Define to 1 if you have the `rpc' library (-lrpc). */
6161
#cmakedefine HAVE_LIBRPC 1
6262

63-
/* Define to 1 if you have the <net/if.h> header file. */
64-
#cmakedefine HAVE_NET_IF_H 1
65-
6663
/* Define to 1 if you have the `openat' function. */
6764
#cmakedefine HAVE_OPENAT 1
6865

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if test "$ac_cv_prog_cc_c99" = "no"; then
3030
fi
3131
AC_LBL_C_INIT(V_CCOPT, V_INCLS)
3232

33-
AC_CHECK_HEADERS(rpc/rpc.h rpc/rpcent.h net/if.h)
33+
AC_CHECK_HEADERS(rpc/rpc.h rpc/rpcent.h)
3434
#
3535
# Get the size of a void *, to know whether this is a 32-bit or 64-bit build.
3636
#

print-sll.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <config.h>
2525

26-
#ifdef HAVE_NET_IF_H
26+
#ifdef __linux__
2727
#include <net/if.h>
2828
#endif
2929

@@ -403,7 +403,7 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
403403
u_short ether_type;
404404
int llc_hdrlen;
405405
u_int hdrlen;
406-
#ifdef HAVE_NET_IF_H
406+
#ifdef __linux__
407407
uint32_t if_index;
408408
char ifname[IF_NAMESIZE];
409409
#endif
@@ -412,7 +412,7 @@ sll2_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char
412412
ND_TCHECK_LEN(p, SLL2_HDR_LEN);
413413

414414
sllp = (const struct sll2_header *)p;
415-
#ifdef HAVE_NET_IF_H
415+
#ifdef __linux__
416416
if_index = GET_BE_U_4(sllp->sll2_if_index);
417417
if (!if_indextoname(if_index, ifname))
418418
strncpy(ifname, "?", 2);

tcpdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ main(int argc, char **argv)
21662166
pcap_datalink_val_to_description(dlt));
21672167
}
21682168
fprintf(stderr, ", snapshot length %d\n", pcap_snapshot(pd));
2169-
#ifdef DLT_LINUX_SLL2
2169+
#if defined(DLT_LINUX_SLL2) && defined(__linux__)
21702170
if (dlt == DLT_LINUX_SLL2)
21712171
fprintf(stderr, "Warning: interface names might be incorrect\n");
21722172
#endif

0 commit comments

Comments
 (0)