From: Guy Harris Date: Fri, 20 Oct 2017 21:59:44 +0000 (-0700) Subject: Work around Linuxes with net/bpf.h differently. X-Git-Tag: libpcap-1.9-bp~470 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/6e284bd2bc5690f48bee83435f75200ef1e71a6f Work around Linuxes with net/bpf.h differently. Make sure net/bpf.h not only exists but defines BIOCSETIF. This way, if some system has Linux packet sockets *and* BPF, we still choose BPF. Some systems might offer Linux packet sockets for compatibility. This also handles non-Linux systems that have net/bpf.h but don't have BPF as a capture mechanism. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 86d331d9..3e378a39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -623,6 +623,18 @@ else() # Check for a bunch of headers for various packet capture mechanisms. # check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H) + if(HAVE_NET_BPF_H) + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + check_symbol_exists(BIOCSETIF net/bpf.h BPF_H_DEFINES_BIOCSETIF) + endif(HAVE_NET_BPF_H) check_include_file(net/pfilt.h HAVE_NET_PFILT_H) check_include_file(net/enet.h HAVE_NET_ENET_H) check_include_file(net/nit.h HAVE_NET_NIT_H) @@ -631,20 +643,18 @@ else() check_include_file(net/raw.h HAVE_NET_RAW_H) check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H) - if(HAVE_LINUX_SOCKET_H) - # - # No prizes for guessing this one. - # Check this before BPF, because it appears that - # at least one Arch Linux system might have a net/bpf.h. - # - set(PCAP_TYPE linux) - elseif(HAVE_NET_BPF_H) + if(BPF_H_DEFINES_BIOCSETIF) # # BPF. # Check this before DLPI, so that we pick BPF on # Solaris 11 and later. # set(PCAP_TYPE bpf) + elseif(HAVE_LINUX_SOCKET_H) + # + # No prizes for guessing this one. + # + set(PCAP_TYPE linux) elseif(HAVE_NET_PFILT_H) # # DEC OSF/1, Digital UNIX, Tru64 UNIX diff --git a/configure b/configure index 01795881..a6f24246 100755 --- a/configure +++ b/configure @@ -5358,7 +5358,63 @@ else # Check for a bunch of headers for various packet # capture mechanisms. # - for ac_header in net/bpf.h net/pfilt.h net/enet.h + for ac_header in net/bpf.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "net/bpf.h" "ac_cv_header_net_bpf_h" "$ac_includes_default" +if test "x$ac_cv_header_net_bpf_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_NET_BPF_H 1 +_ACEOF + +fi + +done + + if test "$ac_cv_header_net_bpf_h" = yes; then + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if net/bpf.h defines BIOCSETIF" >&5 +$as_echo_n "checking if net/bpf.h defines BIOCSETIF... " >&6; } + if ${ac_cv_lbl_bpf_h_defines_biocsetif+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#ifdef HAVE_SYS_IOCCOM_H +#include +#endif +#include +#include + +int +main () +{ +u_int i = BIOCSETIF; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_lbl_bpf_h_defines_biocsetif=yes +else + ac_cv_lbl_bpf_h_defines_biocsetif=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lbl_bpf_h_defines_biocsetif" >&5 +$as_echo "$ac_cv_lbl_bpf_h_defines_biocsetif" >&6; } + fi + for ac_header in net/pfilt.h net/enet.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" @@ -5398,20 +5454,7 @@ fi done - if test "$ac_cv_header_linux_socket_h" = yes; then - # - # No prizes for guessing this one. - # Check this before BPF, because it appears that - # at least one Arch Linux system might have a net/bpf.h. - # - V_PCAP=linux - - # - # XXX - this won't work with older kernels that have - # SOCK_PACKET sockets but not PF_PACKET sockets. - # - VALGRINDTEST=valgrindtest - elif test "$ac_cv_header_net_bpf_h" = yes; then + if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then # # BPF. # Check this before DLPI, so that we pick BPF on @@ -5430,6 +5473,17 @@ done VALGRINDTEST=valgrindtest ;; esac + elif test "$ac_cv_header_linux_socket_h" = yes; then + # + # No prizes for guessing this one. + # + V_PCAP=linux + + # + # XXX - this won't work with older kernels that have + # SOCK_PACKET sockets but not PF_PACKET sockets. + # + VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_pfilt_h" = yes; then # # DEC OSF/1, Digital UNIX, Tru64 UNIX diff --git a/configure.ac b/configure.ac index 4856e8ef..a8f3f37b 100644 --- a/configure.ac +++ b/configure.ac @@ -333,24 +333,38 @@ else # Check for a bunch of headers for various packet # capture mechanisms. # - AC_CHECK_HEADERS(net/bpf.h net/pfilt.h net/enet.h) + AC_CHECK_HEADERS(net/bpf.h) + if test "$ac_cv_header_net_bpf_h" = yes; then + # + # Does it define BIOCSETIF? + # I.e., is it a header for an LBL/BSD-style capture + # mechanism, or is it just a header for a BPF filter + # engine? Some versions of Arch Linux, for example, + # have a net/bpf.h that doesn't define BIOCSETIF; + # as it's a Linux, it should use packet sockets, + # instead. + # + AC_MSG_CHECKING(if net/bpf.h defines BIOCSETIF) + AC_CACHE_VAL(ac_cv_lbl_bpf_h_defines_biocsetif, + AC_TRY_COMPILE( +[ +#include +#ifdef HAVE_SYS_IOCCOM_H +#include +#endif +#include +#include +], + [u_int i = BIOCSETIF;], + ac_cv_lbl_bpf_h_defines_biocsetif=yes, + ac_cv_lbl_bpf_h_defines_biocsetif=no)) + AC_MSG_RESULT($ac_cv_lbl_bpf_h_defines_biocsetif) + fi + AC_CHECK_HEADERS(net/pfilt.h net/enet.h) AC_CHECK_HEADERS(net/nit.h sys/net/nit.h) AC_CHECK_HEADERS(linux/socket.h net/raw.h sys/dlpi.h) - if test "$ac_cv_header_linux_socket_h" = yes; then - # - # No prizes for guessing this one. - # Check this before BPF, because it appears that - # at least one Arch Linux system might have a net/bpf.h. - # - V_PCAP=linux - - # - # XXX - this won't work with older kernels that have - # SOCK_PACKET sockets but not PF_PACKET sockets. - # - VALGRINDTEST=valgrindtest - elif test "$ac_cv_header_net_bpf_h" = yes; then + if test "$ac_cv_lbl_bpf_h_defines_biocsetif" = yes; then # # BPF. # Check this before DLPI, so that we pick BPF on @@ -369,6 +383,17 @@ else VALGRINDTEST=valgrindtest ;; esac + elif test "$ac_cv_header_linux_socket_h" = yes; then + # + # No prizes for guessing this one. + # + V_PCAP=linux + + # + # XXX - this won't work with older kernels that have + # SOCK_PACKET sockets but not PF_PACKET sockets. + # + VALGRINDTEST=valgrindtest elif test "$ac_cv_header_net_pfilt_h" = yes; then # # DEC OSF/1, Digital UNIX, Tru64 UNIX