]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add more configure-script tests to CMakeLists.txt.
authorGuy Harris <[email protected]>
Fri, 8 Sep 2017 10:52:00 +0000 (03:52 -0700)
committerGuy Harris <[email protected]>
Fri, 8 Sep 2017 10:52:00 +0000 (03:52 -0700)
While we're at it, remove some no-longer-necessary header file tests
from the configure script, and move the test for zero-copy BPF from the
configure script to pcap-bpf.c, so we don't have to do it in either the
configure scripr or in CMakeLists.txt.

CMakeLists.txt
cmakeconfig.h.in
config.h.in
configure
configure.ac
pcap-bpf.c

index e887c9eb6a770918c3a540be9296a45179a4f334..c5e6d5fb35426e9469c13638dd7d3a395bb33fc7 100644 (file)
@@ -42,6 +42,10 @@ else()
     option (HAVE_REMOTE "Enable remote capture" OFF)
 endif( WIN32 )
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    option(BUILD_WITH_LIBNL "Build with libnl" ON)
+endif()
+
 ######################################
 # Project settings
 ######################################
@@ -136,14 +140,38 @@ include(CheckTypeSize)
 #
 # Header files.
 #
-check_include_file( inttypes.h HAVE_INTTYPES_H )
-check_include_file( stdint.h HAVE_STDINT_H )
-check_include_file( unistd.h HAVE_UNISTD_H )
-if( NOT HAVE_UNISTD_H )
-    add_definitions( -DYY_NO_UNISTD_H )
-endif( NOT HAVE_UNISTD_H )
-check_include_file( bitypes.h HAVE_SYS_BITYPES_H )
-check_include_file( limits.h HAVE_LIMITS_H )
+check_include_file(inttypes.h HAVE_INTTYPES_H)
+check_include_file(stdint.h HAVE_STDINT_H)
+check_include_file(unistd.h HAVE_UNISTD_H)
+if(NOT HAVE_UNISTD_H)
+    add_definitions(-DYY_NO_UNISTD_H)
+endif(NOT HAVE_UNISTD_H)
+check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
+check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
+check_include_file(sys/select.h HAVE_SYS_SELECT_H)
+check_include_file(limits.h HAVE_LIMITS_H)
+check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
+check_include_file(net/pfvar.h HAVE_NET_PFVAR_H)
+if(HAVE_NET_PFVAR_H)
+    check_c_source_compiles(
+"#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/pfvar.h>
+
+int
+main(void)
+{
+       return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
+}
+"
+        HAVE_PF_NAT_THROUGH_PF_NORDR)
+endif()
+check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
+    check_include_file(linux/if_bonding.h HAVE_LINUX_IF_BONDING_H)
+endif()
 
 #
 # Functions.
@@ -235,11 +263,9 @@ if( WIN32 )
     if (HAVE_PACKET32)
        #
        # We have packet.dll.
-       # Set the capture type to NPF, and link with packet.dll before
-       # WinSock2.
+       # Set the capture type to NPF.
        #
        set( PCAP_TYPE npf )
-       set(PCAP_LINK_LIBRARIES packet ${PCAP_LINK_LIBRARIES})
     else()
        #
        # We don't have any capture type we know about, so just use
@@ -281,15 +307,6 @@ else()
         set( PCAP_TYPE nit )
     elseif( EXISTS /usr/include/linux/socket.h )
         set( PCAP_TYPE linux )
-
-       #
-       # Do we have the wireless extensions?
-       #
-        check_include_file( linux/wireless.h HAVE_LINUX_WIRELESS_H )
-
-        #
-        # XXX - many more Linux checks.
-       #
     elseif( EXISTS /usr/include/net/raw.h )
         set( PCAP_TYPE snoop )
     elseif( EXISTS /usr/include/odmi.h )
@@ -301,10 +318,6 @@ else()
         set( PCAP_TYPE bpf )
     elseif( /usr/include/sys/dlpi.h )
         set( PCAP_TYPE dlpi )
-
-        #
-        # XXX - many more DLPI checks.
-        #
     else()
        set( PCAP_TYPE null )
     endif()
@@ -312,6 +325,154 @@ endif( WIN32 )
 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
 
+
+#
+# Do capture-mechanism-dependent tests.
+#
+if(PCAP_TYPE STREQUAL "npf")
+    #
+    # Link with packet.dll before WinSock2.
+    #
+    set(PCAP_LINK_LIBRARIES packet ${PCAP_LINK_LIBRARIES})
+elseif(PCAP_TYPE STREQUAL "dlpi")
+    #
+    # Needed for common functions used by pcap-[dlpi,libdlpi].c
+    #
+    set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
+
+    #
+    # Checks for some header files.
+    #
+    check_include_files(sys/bufmod.h HAVE_SYS_BUFMOD_H)
+    check_include_files(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
+
+    #
+    # Checks to see if Solaris has the public libdlpi(3LIB) library.
+    # Note: The existence of /usr/include/libdlpi.h does not mean it is the
+    # public libdlpi(3LIB) version. Before libdlpi was made public, a
+    # private version also existed, which did not have the same APIs.
+    # Due to a gcc bug, the default search path for 32-bit libraries does
+    # not include /lib, we add it explicitly here.
+    # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
+    # Also, due to the bug above applications that link to libpcap with
+    # libdlpi will have to add "-L/lib" option to "configure".
+    #
+    set(CMAKE_REQUIRED_FLAGS "-L/lib")
+    set(CMAKE_REQUIRED_LIBRARIES dlpi)
+    check_function_exists(dlpi_walk HAVE_LIBDLPI)
+    set(CMAKE_REQUIRED_FLAGS "")
+    set(CMAKE_REQUIRED_LIBRARIES "")
+    if(HAVE_LIBDLPI)
+       #
+       # XXX - add -L/lib
+       #
+       set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
+       set(PCAP_TYPE libdlpi)
+    endif()
+
+    #
+    # Check whether we have a /dev/dlpi device or have multiple devices.
+    #
+    if(EXISTS /dev/dlpi)
+       set(HAVE_DEV_DLPI TRUE)
+    else()
+       if(IS_DIRECTORY /dev/dlpi)
+           set(PCAP_DEV_PREFIX, "/dev/dlpi")
+       endif()
+    endif()
+
+    #
+    # This check is for Solaris with DLPI support for passive modes.
+    # See dlpi(7P) for more details.
+    #
+    # XXX - there's no check_struct() macro that's like
+    # check_struct_has_member() except that it only checks for the
+    # existence of the structure type, so we use
+    # check_struct_has_member() and look for dl_primitive.
+    #
+    check_struct_has_member("dl_passive_req_t" dl_primitive sys/types.h sys/dlpi.h HAVE_DLPI_PASSIVE)
+elseif(PCAP_TYPE STREQUAL "linux")
+    #
+    # Do we have the wireless extensions?
+    #
+    check_include_file( linux/wireless.h HAVE_LINUX_WIRELESS_H )
+
+    #
+    # Do we have libnl?
+    #
+    if(BUILD_WITH_LIBNL)
+       #
+       # Try libnl 3.x first.
+       #
+       set(CMAKE_REQUIRED_LIBRARIES nl-3)
+       check_function_exists(nl_socket_alloc HAVE_LIBNL)
+       set(CMAKE_REQUIRED_FLAGS "")
+       if(HAVE_LIBNL)
+           #
+           # Yes, we have libnl 3.x.
+           #
+           set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
+           set(HAVE_LIBNL_3_x ON)
+           set(HAVE_LIBNL_NLE ON)
+           set(HAVE_LIBNL_SOCKETS ON)
+           include_directories("/usr/include/libnl3")
+       else()
+           #
+           # Try libnl 2.x.
+           #
+           set(CMAKE_REQUIRED_LIBRARIES nl)
+           check_function_exists(nl_socket_alloc HAVE_LIBNL)
+           set(CMAKE_REQUIRED_FLAGS "")
+           if(HAVE_LIBNL)
+               #
+               # Yes, we have libnl 2.x.
+               #
+               set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
+               set(HAVE_LIBNL_2_x ON)
+               set(HAVE_LIBNL_NLE ON)
+               set(HAVE_LIBNL_SOCKETS ON)
+           else()
+               #
+               # No, we don't; do we have libnl 1.x?
+               #
+               set(CMAKE_REQUIRED_LIBRARIES nl)
+               check_function_exists(nl_handle_alloc HAVE_LIBNL)
+               set(CMAKE_REQUIRED_FLAGS "")
+               if(HAVE_LIBNL)
+                   set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
+               endif()
+           endif()
+       endif()
+    endif()
+
+    check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
+
+    #
+    # Checks to see if tpacket_stats is defined in linux/if_packet.h
+    # If so then pcap-linux.c can use this to report proper statistics.
+    #
+    check_struct_has_member("struct tpacket_stats" tp_packets linux/if_packet.h HAVE_TPACKET_STATS)
+
+    check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
+    if(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI)
+        set(HAVE_LINUX_TPACKET_AUXDATA tp_vlan_tci)
+    endif()
+elseif(PCAP_TYPE STREQUAL "bpf")
+    #
+    # Check whether we have the *BSD-style ioctls.
+    #
+    check_include_file(net/if_media.h HAVE_NET_IF_MEDIA_H)
+
+    #
+    # Check whether we have struct BPF_TIMEVAL.
+    #
+    if(HAVE_SYS_IOCCOM_H)
+        check_struct_has_member("struct BPF_TIMEVAL" tv_sec sys/types.h sys/ioccom.h net/bpf.h HAVE_STRUCT_BPF_TIMEVAL)
+    else()
+        check_struct_has_member("struct BPF_TIMEVAL" tv_sec sys/types.h net/bpf.h HAVE_STRUCT_BPF_TIMEVAL)
+    endif()
+endif()
+
 #
 # Now figure out how we get a list of interfaces and addresses,
 # if we support capturing.  Don't bother if we don't support
@@ -322,7 +483,7 @@ if( NOT WIN32 )
     # UN*X - figure out what type of interface list mechanism we
     # have.
     #
-    if( ${PCAP_TYPE} STREQUAL "null" )
+    if(PCAP_TYPE STREQUAL "null")
         #
         # We can't capture, so we can't open any capture
         # devices, so we won't return any interfaces.
@@ -330,13 +491,13 @@ if( NOT WIN32 )
         set( FINDALLDEVS_TYPE null )
     else()
         check_function_exists( getifaddrs HAVE_GETIFADDRS )
-        if( ${HAVE_GETIFADDRS} )
+        if(HAVE_GETIFADDRS)
             #
             # We have "getifaddrs()"; make sure we have <ifaddrs.h>
             # as well, just in case some platform is really weird.
             #
             check_include_file( ifaddrs.h HAVE_IFADDRS_H )
-            if( ${HAVE_IFADDRS_H} )
+            if(HAVE_IFADDRS_H)
                 #
                 # We have the header, so we use "getifaddrs()" to
                 # get the list of interfaces.
@@ -362,7 +523,7 @@ if( NOT WIN32 )
             # The first thing we use is the type of capture mechanism,
             # which is somewhat of a proxy for the OS we're using.
             #
-            if( ${PCAP_TYPE} STREQUAL "dlpi" OR ${PCAP_TYPE} STREQUAL "libdlpi" )
+            if(PCAP_TYPE STREQUAL "dlpi" OR PCAP_TYPE STREQUAL "libdlpi")
                 #
                 # This might be Solaris 8 or later, with
                 # SIOCGLIFCONF, or it might be some other OS
@@ -414,7 +575,7 @@ endif( WIN32 )
 # Try to find Flex, a Windows version of Flex, or Lex.
 #
 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
-if( ${LEX_EXECUTABLE} STREQUAL "LEX_EXECUTABLE-NOTFOUND" )
+if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND" )
     message(FATAL_ERROR "Neither flex nor win_flex nor lex was found." )
 endif()
 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
@@ -446,7 +607,7 @@ set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
 # Try to find YACC or Bison.
 #
 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
-if( ${YACC_EXECUTABLE} STREQUAL "YACC_EXECUTABLE-NOTFOUND" )
+if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND" )
     message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found." )
 endif()
 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
index 699d6bf6b12ac673348b6a83bfed47010175d986..c3e472175dbdf54a6def889e5a39843565c9ae05 100644 (file)
 /* Define to 1 if you have the `PacketIsLoopbackAdapter' function. */
 #cmakedefine HAVE_PACKET_IS_LOOPBACK_ADAPTER 1
 
-/* define if the system supports zerocopy BPF */
-#cmakedefine HAVE_ZEROCOPY_BPF 1
-
 /* define if your compiler has __attribute__ */
 #cmakedefine HAVE___ATTRIBUTE__ 1
 
 #cmakedefine PACKAGE_VERSION 1
 
 /* /dev/dlpi directory */
-#cmakedefine PCAP_DEV_PREFIX 1
+#cmakedefine PCAP_DEV_PREFIX ""
 
 /* target host supports Bluetooth sniffing */
 #cmakedefine PCAP_SUPPORT_BT 1
index 208dff2b66e421e18c73e52c8c6a562a9b767351..0c16e572d9d015c145a71b9cdadb79a6b17a6e5b 100644 (file)
@@ -79,9 +79,6 @@
 /* Define to 1 if you have the <linux/if_bonding.h> header file. */
 #undef HAVE_LINUX_IF_BONDING_H
 
-/* Define to 1 if you have the <linux/if_packet.h> header file. */
-#undef HAVE_LINUX_IF_PACKET_H
-
 /* Define to 1 if you have the <linux/net_tstamp.h> header file. */
 #undef HAVE_LINUX_NET_TSTAMP_H
 
@@ -91,9 +88,6 @@
 /* if tp_vlan_tci exists */
 #undef HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI
 
-/* Define to 1 if you have the <linux/types.h> header file. */
-#undef HAVE_LINUX_TYPES_H
-
 /* Define to 1 if you have the <linux/usbdevice_fs.h> header file. */
 #undef HAVE_LINUX_USBDEVICE_FS_H
 
 /* Define to 1 if you have the <netinet/if_ether.h> header file. */
 #undef HAVE_NETINET_IF_ETHER_H
 
-/* Define to 1 if you have the <netpacket/if_packet.h> header file. */
-#undef HAVE_NETPACKET_IF_PACKET_H
-
 /* Define to 1 if you have the <netpacket/packet.h> header file. */
 #undef HAVE_NETPACKET_PACKET_H
 
 /* Define to 1 if you have the <sys/ioccom.h> header file. */
 #undef HAVE_SYS_IOCCOM_H
 
-/* Define to 1 if you have the <sys/select.h> header file. */
-#undef HAVE_SYS_SELECT_H
-
 /* Define to 1 if you have the <sys/sockio.h> header file. */
 #undef HAVE_SYS_SOCKIO_H
 
 /* Define to 1 if you have the `vsnprintf' function. */
 #undef HAVE_VSNPRINTF
 
-/* define if the system supports zerocopy BPF */
-#undef HAVE_ZEROCOPY_BPF
-
 /* define if your compiler has __attribute__ */
 #undef HAVE___ATTRIBUTE__
 
index e7e21b367d0166423c3d692efb5b2e8ce7e91830..c573076983cda763a727a09e0f9f9fbbc9d5c029 100755 (executable)
--- a/configure
+++ b/configure
@@ -4705,7 +4705,7 @@ $as_echo "#define HAVE_FSEEKO 1" >>confdefs.h
 fi
 
 
-for ac_header in sys/ioccom.h sys/select.h sys/sockio.h limits.h
+for ac_header in sys/ioccom.h sys/sockio.h limits.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"
@@ -4718,25 +4718,12 @@ fi
 
 done
 
-for ac_header in linux/types.h
+for ac_header in netpacket/packet.h
 do :
-  ac_fn_c_check_header_mongrel "$LINENO" "linux/types.h" "ac_cv_header_linux_types_h" "$ac_includes_default"
-if test "x$ac_cv_header_linux_types_h" = xyes; then :
+  ac_fn_c_check_header_mongrel "$LINENO" "netpacket/packet.h" "ac_cv_header_netpacket_packet_h" "$ac_includes_default"
+if test "x$ac_cv_header_netpacket_packet_h" = xyes; then :
   cat >>confdefs.h <<_ACEOF
-#define HAVE_LINUX_TYPES_H 1
-_ACEOF
-
-fi
-
-done
-
-for ac_header in linux/if_packet.h netpacket/packet.h netpacket/if_packet.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"
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
-  cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+#define HAVE_NETPACKET_PACKET_H 1
 _ACEOF
 
 fi
@@ -6019,36 +6006,6 @@ fi
 done
 
 
-       { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the system supports zerocopy BPF" >&5
-$as_echo_n "checking whether the system supports zerocopy BPF... " >&6; }
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/socket.h>
-           #include <sys/ioctl.h>
-           #include <net/if.h>
-           #include <net/bpf.h>
-int
-main ()
-{
-return (BIOCROTZBUF + BPF_BUFMODE_ZBUF);
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-               { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-$as_echo "#define HAVE_ZEROCOPY_BPF 1" >>confdefs.h
-
-
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
            #
            # Check whether we have struct BPF_TIMEVAL.
            #
index 8abad84ddebfa58073d3d68a999bb2d2e56b0175..f67852bcbb4c5c8b784445ade9c96b146ee0c746 100644 (file)
@@ -103,9 +103,8 @@ dnl in "aclocal.m4" uses it, so we would still have to test for it
 dnl and set "HAVE_SYS_IOCCOM_H" if we have it, otherwise
 dnl "AC_LBL_FIXINCLUDES" wouldn't work on some platforms such as Solaris.
 dnl
-AC_CHECK_HEADERS(sys/ioccom.h sys/select.h sys/sockio.h limits.h)
-AC_CHECK_HEADERS(linux/types.h)
-AC_CHECK_HEADERS(linux/if_packet.h netpacket/packet.h netpacket/if_packet.h)
+AC_CHECK_HEADERS(sys/ioccom.h sys/sockio.h limits.h)
+AC_CHECK_HEADERS(netpacket/packet.h)
 AC_CHECK_HEADERS(net/pfvar.h, , , [#include <sys/types.h>
 #include <sys/socket.h>
 #include <net/if.h>])
@@ -572,20 +571,6 @@ bpf)
        #
        AC_CHECK_HEADERS(net/if_media.h)
 
-       AC_MSG_CHECKING(whether the system supports zerocopy BPF)
-       AC_TRY_COMPILE(
-           [#include <sys/socket.h>
-           #include <sys/ioctl.h>
-           #include <net/if.h>
-           #include <net/bpf.h>],
-           [return (BIOCROTZBUF + BPF_BUFMODE_ZBUF);],
-           [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_ZEROCOPY_BPF, 1,
-               [define if the system supports zerocopy BPF])
-           ],
-           AC_MSG_RESULT(no))
-
            #
            # Check whether we have struct BPF_TIMEVAL.
            #
index cd93b55334c4acb3b0a23c7a2796c06fe224f6f1..a6403780a81817b837e38b96b907f88a4cd22117 100644 (file)
@@ -24,9 +24,6 @@
 #endif
 
 #include <sys/param.h>                 /* optionally get BSD define */
-#ifdef HAVE_ZEROCOPY_BPF
-#include <sys/mman.h>
-#endif
 #include <sys/socket.h>
 #include <time.h>
 /*
@@ -57,10 +54,6 @@ static const char usbus_prefix[] = "usbus";
 #include <dirent.h>
 #endif
 
-#ifdef HAVE_ZEROCOPY_BPF
-#include <machine/atomic.h>
-#endif
-
 #include <net/if.h>
 
 #ifdef _AIX
@@ -82,6 +75,16 @@ static const char usbus_prefix[] = "usbus";
 #include <net/bpf.h>
 #define _AIX
 
+/*
+ * If both BIOCROTZBUF and BPF_BUFMODE_ZBUF are defined, we have
+ * zero-copy BPF.
+ */
+#if defined(BIOCROTZBUF) && defined(BPF_BUFMODE_ZBUF)
+  #define HAVE_ZEROCOPY_BPF
+  #include <sys/mman.h>
+  #include <machine/atomic.h>
+#endif
+
 #include <net/if_types.h>              /* for IFT_ values */
 #include <sys/sysconfig.h>
 #include <sys/device.h>