]> The Tcpdump Group git mirrors - libpcap/commitdiff
Work around Linuxes with net/bpf.h differently.
authorGuy Harris <[email protected]>
Fri, 20 Oct 2017 21:59:44 +0000 (14:59 -0700)
committerGuy Harris <[email protected]>
Fri, 20 Oct 2017 21:59:44 +0000 (14:59 -0700)
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.

CMakeLists.txt
configure
configure.ac

index 86d331d95bc38862963c9dab1516695d30e3db08..3e378a398755ffd7fbb5c33f6773a08ad5ce6460 100644 (file)
@@ -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
index 017958810afd23b66a1d2a8df91dd8a5bd7a5623..a6f242463b1ae1a286a82e0e6e6561eff6fe7f7a 100755 (executable)
--- 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 <sys/ioctl.h>
+#ifdef HAVE_SYS_IOCCOM_H
+#include <sys/ioccom.h>
+#endif
+#include <net/bpf.h>
+#include <net/if.h>
+
+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
index 4856e8ef8135eb6d0bcc31cb9697f1b9949bd3e4..a8f3f37bef16c88f12d7cb69fedb7b3ef1cfa1a1 100644 (file)
@@ -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 <sys/ioctl.h>
+#ifdef HAVE_SYS_IOCCOM_H
+#include <sys/ioccom.h>
+#endif
+#include <net/bpf.h>
+#include <net/if.h>
+],
+                       [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