1 cmake_minimum_required(VERSION 2.8.6)
4 # Apple doesn't build with an install_name starting with @rpath, and
5 # neither do we with autotools; don't do so with CMake, either, and
6 # suppress warnings about that.
9 cmake_policy(SET CMP0042 OLD)
12 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
17 # Try to enable as many C99 features as we can.
18 # At minimum, we want C++/C99-style // comments.
20 # Newer versions of compilers might default to supporting C99, but older
21 # versions may require a special flag.
23 # Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
24 # so, unless and until we require CMake 3.1 or later, we have to do it
25 # ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
28 # Note: with CMake 3.1 through 3.5, the only compilers for which CMake
29 # handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
30 # for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
31 # 3.10 adds support for Cray C and IAR C, but no version of CMake has
32 # support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
33 # compilers for which CMake supports it, we may still have to do it
34 # ourselves on other compilers.
36 # See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
37 # for a list of compiler IDs.
39 # We don't worry about MSVC; it doesn't have such a flag - either it
40 # doesn't support the C99 features we need at all, or it supports them
41 # regardless of the compiler flag.
43 # XXX - this just tests whether the option works and adds it if it does.
44 # We don't test whether it's necessary in order to get the C99 features
45 # that we use; if we ever have a user who tries to compile with a compiler
46 # that can't be made to support those features, we can add a test to make
47 # sure we actually *have* C99 support.
49 include(CheckCCompilerFlag)
50 macro(check_and_add_compiler_option _option)
51 message(STATUS "Checking C compiler flag ${_option}")
52 string(REPLACE "=" "-" _temp_option_variable ${_option})
53 string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
54 check_c_compiler_flag("${_option}" ${_option_variable})
55 if(${${_option_variable}})
56 set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
60 set(C_ADDITIONAL_FLAGS "")
61 if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
62 CMAKE_C_COMPILER_ID MATCHES "Clang")
63 check_and_add_compiler_option("-std=gnu99")
64 elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
66 # We want support for extensions picked up for GNU C compatibility,
67 # so we use -qlanglvl=extc99.
69 check_and_add_compiler_option("-qlanglvl=extc99")
70 elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
71 check_and_add_compiler_option("-AC99")
72 elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
73 check_and_add_compiler_option("-xc99")
74 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
75 check_and_add_compiler_option("-c99")
79 # Build all runtimes in the top-level binary directory; that way,
80 # on Windows, the executables will be in the same directory as
81 # the DLLs, so the system will find pcap.dll when any of the
82 # executables are run.
84 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
86 ###################################################################
88 ###################################################################
92 # On Windows, allow the library name to be overridden, for the
93 # benefit of projects that combine libpcap with their own
94 # kernel-mode code to support capturing.
96 set(LIBRARY_NAME pcap CACHE STRING "Library name")
99 # On UN*X, it's always been libpcap.
101 set(LIBRARY_NAME pcap)
104 option(INET6 "Enable IPv6" ON)
106 option(USE_STATIC_RT "Use static Runtime" ON)
108 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
110 set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
113 # To pacify those who hate the protochain instruction
114 option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
117 # Start out with the capture mechanism type unspecified; the user
118 # can explicitly specify it and, if they don't, we'll pick an
121 set(PCAP_TYPE "" CACHE STRING "Packet capture type")
124 # Default to having remote capture support on Windows and, for now, to
125 # not having it on UN*X.
128 option(ENABLE_REMOTE "Enable remote capture" ON)
130 option(ENABLE_REMOTE "Enable remote capture" OFF)
133 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
134 option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
135 option(BUILD_WITH_LIBNL "Build with libnl" ON)
139 # Additional capture modules.
141 option(DISABLE_USB "Disable USB sniffing support" OFF)
142 option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
143 option(DISABLE_NETMAP "Disable netmap support" OFF)
145 # We don't support D-Bus sniffing on macOS; see
147 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
150 option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
152 option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
154 option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
156 option(DISABLE_DAG "Disable Endace DAG card support" OFF)
158 option(DISABLE_SEPTEL "Disable Septel card support" OFF)
159 set(SEPTEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
161 option(DISABLE_SNF "Disable Myricom SNF support" OFF)
163 option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
168 option(BDEBUG "Build optimizer debugging code" OFF)
169 option(YYDEBUG "Build parser debugging code" OFF)
171 ###################################################################
173 ###################################################################
175 # Get, parse, format and set pcap's version string from [pcap_root]/VERSION
178 # Get MAJOR, MINOR, PATCH & SUFFIX
179 file(STRINGS ${pcap_SOURCE_DIR}/VERSION
181 LIMIT_COUNT 1 # Read only the first line
185 string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
187 # Get MAJOR, MINOR & PATCH
188 string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
191 # Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
192 string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
194 # Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
196 set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
199 set(PACKAGE_NAME "${LIBRARY_NAME}")
200 set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
202 ######################################
204 ######################################
206 add_definitions(-DHAVE_CONFIG_H)
209 ${CMAKE_CURRENT_BINARY_DIR}
213 include(CheckFunctionExists)
214 include(CMakePushCheckState)
215 include(CheckSymbolExists)
219 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
220 include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
221 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
225 set(HAVE_PACKET32 TRUE)
226 include_directories(${PACKET_INCLUDE_DIRS})
228 # Check whether we have the NPcap PacketIsLoopbackAdapter()
231 cmake_push_check_state()
232 set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
233 check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
234 cmake_pop_check_state()
237 message(STATUS "checking for Npcap's version.h")
238 check_symbol_exists(WINPCAP_PRODUCT_NAME "../../version.h" HAVE_VERSION_H)
240 message(STATUS "HAVE version.h")
242 message(STATUS "MISSING version.h")
243 endif(HAVE_VERSION_H)
248 add_definitions(-D__STDC__)
249 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
253 message(STATUS "Use STATIC runtime")
256 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
257 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
258 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
259 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
260 string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
263 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
266 message(STATUS "Use DYNAMIC runtime")
269 ###################################################################
270 # Detect available platform features
271 ###################################################################
273 include(CheckIncludeFile)
274 include(CheckIncludeFiles)
275 include(CheckStructHasMember)
276 include(CheckTypeSize)
279 # Tests are a bit expensive with Visual Studio on Windows, so, on
280 # Windows, we skip tests for UN*X-only headers and functions.
286 check_include_file(inttypes.h HAVE_INTTYPES_H)
287 check_include_file(stdint.h HAVE_STDINT_H)
288 check_include_file(unistd.h HAVE_UNISTD_H)
289 if(NOT HAVE_UNISTD_H)
290 add_definitions(-DYY_NO_UNISTD_H)
291 endif(NOT HAVE_UNISTD_H)
292 check_include_file(bitypes.h HAVE_SYS_BITYPES_H)
294 check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
295 check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
296 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
298 check_include_file(limits.h HAVE_LIMITS_H)
300 check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
301 check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
304 # Check for various PF actions.
306 check_c_source_compiles(
307 "#include <sys/types.h>
308 #include <sys/socket.h>
310 #include <net/pfvar.h>
315 return PF_NAT+PF_NONAT+PF_BINAT+PF_NOBINAT+PF_RDR+PF_NORDR;
318 HAVE_PF_NAT_THROUGH_PF_NORDR)
319 endif(HAVE_NET_PFVAR_H)
320 check_include_file(netinet/if_ether.h HAVE_NETINET_IF_ETHER_H)
321 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
322 check_include_file(linux/sockios.h HAVE_LINUX_SOCKIOS_H)
324 # linux/if_bonding.h requires sys/socket.h.
326 check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
333 check_function_exists(strerror HAVE_STRERROR)
334 check_function_exists(strerror_r HAVE_STRERROR_R)
337 # We have strerror_r; if we define _GNU_SOURCE, is it a
338 # POSIX-compliant strerror_r() or a GNU strerror_r()?
340 check_c_source_compiles(
344 /* Define it GNU-style; that will cause an error if it's not GNU-style */
345 extern char *strerror_r(int, char *, size_t);
354 if(NOT HAVE_GNU_STRERROR_R)
355 set(HAVE_POSIX_STRERROR_R YES)
356 endif(NOT HAVE_GNU_STRERROR_R)
357 else(HAVE_STRERROR_R)
359 # We don't have strerror_r; do we have strerror_s?
361 check_function_exists(strerror_s HAVE_STRERROR_S)
362 endif(HAVE_STRERROR_R)
363 check_function_exists(strlcpy HAVE_STRLCPY)
364 check_function_exists(strlcat HAVE_STRLCAT)
365 check_function_exists(snprintf HAVE_SNPRINTF)
366 check_function_exists(vsnprintf HAVE_VSNPRINTF)
367 check_function_exists(asprintf HAVE_ASPRINTF)
368 check_function_exists(vasprintf HAVE_VASPRINTF)
369 check_function_exists(strtok_r HAVE_STRTOK_R)
371 check_function_exists(vsyslog HAVE_VSYSLOG)
375 # These tests are for network applications that need socket functions
376 # and getaddrinfo()/getnameinfo()-ish functions. We now require
377 # getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
378 # versions of recvmsg() that conform to the Single UNIX Specification,
379 # so that we can check whether a datagram received with recvmsg() was
380 # truncated when received due to the buffer being too small.
382 # On Windows, getaddrinfo() is in the ws2_32 library.
384 # On most UN*X systems, they're available in the system library.
386 # Under Solaris, we need to link with libsocket and libnsl to get
387 # getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
388 # link with libxnet before libsocket to get a version of recvmsg()
389 # that conforms to the Single UNIX Specification.
391 # We use getaddrinfo() because we want a portable thread-safe way
392 # of getting information for a host name or port; there exist _r
393 # versions of gethostbyname() and getservbyname() on some platforms,
394 # but not on all platforms.
396 # NOTE: if you hand check_library_exists as its last argument a variable
397 # that's been set, it skips the test, so we need different variables.
399 set(PCAP_LINK_LIBRARIES "")
400 include(CheckLibraryExists)
403 # We need winsock2.h and ws2tcpip.h.
405 cmake_push_check_state()
406 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
407 check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
408 cmake_pop_check_state()
409 if(LIBWS2_32_HAS_GETADDRINFO)
410 set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
411 else(LIBWS2_32_HAS_GETADDRINFO)
412 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
413 endif(LIBWS2_32_HAS_GETADDRINFO)
416 # UN*X. First try the system libraries, then try the libraries
417 # for Solaris and possibly other systems that picked up the
418 # System V library split.
420 check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
421 if(NOT STDLIBS_HAVE_GETADDRINFO)
423 # Not found in the standard system libraries.
424 # Try libsocket, which requires libnsl.
426 cmake_push_check_state()
427 set(CMAKE_REQUIRED_LIBRARIES nsl)
428 check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
429 cmake_pop_check_state()
430 if(LIBSOCKET_HAS_GETADDRINFO)
432 # OK, we found it in libsocket.
434 set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
435 else(LIBSOCKET_HAS_GETADDRINFO)
439 message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
440 endif(LIBSOCKET_HAS_GETADDRINFO)
443 # OK, do we have recvmsg() in libxnet?
444 # We also link with libsocket and libnsl.
446 cmake_push_check_state()
447 set(CMAKE_REQUIRED_LIBRARIES socket nsl)
448 check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
449 cmake_pop_check_state()
450 if(LIBXNET_HAS_RECVMSG)
452 # Yes - link with it as well.
454 set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
455 endif(LIBXNET_HAS_RECVMSG)
456 endif(NOT STDLIBS_HAVE_GETADDRINFO)
458 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
459 check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
460 if(NOT STDLIBS_HAVE_PUTMSG)
461 check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
462 if(LIBSTR_HAS_PUTMSG)
463 set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
464 endif(LIBSTR_HAS_PUTMSG)
465 endif(NOT STDLIBS_HAVE_PUTMSG)
469 # Check for reentrant versions of getnetbyname_r(), as provided by
470 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
471 # If we don't find one, we just use getnetbyname(), which uses
472 # thread-specific data on many platforms, but doesn't use it on
473 # NetBSD or OpenBSD, and may not use it on older versions of other
476 # Only do the check if we have a declaration of getnetbyname_r();
477 # without it, we can't check which API it has. (We assume that
478 # if there's a declaration, it has a prototype, so that the API
481 cmake_push_check_state()
482 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
483 check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
484 if(NETDB_H_DECLARES_GETNETBYNAME_R)
485 check_c_source_compiles(
491 struct netent netent_buf;
493 struct netent *resultp;
496 return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
499 HAVE_LINUX_GETNETBYNAME_R)
500 if(NOT HAVE_LINUX_GETNETBYNAME_R)
501 check_c_source_compiles(
507 struct netent netent_buf;
510 return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
513 HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
514 if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
515 check_c_source_compiles(
521 struct netent netent_buf;
522 struct netent_data net_data;
524 return getnetbyname_r((const char *)0, &netent_buf, &net_data);
527 HAVE_AIX_GETNETBYNAME_R)
528 endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
529 endif(NOT HAVE_LINUX_GETNETBYNAME_R)
530 endif(NETDB_H_DECLARES_GETNETBYNAME_R)
531 cmake_pop_check_state()
534 # Check for reentrant versions of getprotobyname_r(), as provided by
535 # Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
536 # If we don't find one, we just use getprotobyname(), which uses
537 # thread-specific data on many platforms, but doesn't use it on
538 # NetBSD or OpenBSD, and may not use it on older versions of other
541 # Only do the check if we have a declaration of getprotobyname_r();
542 # without it, we can't check which API it has. (We assume that
543 # if there's a declaration, it has a prototype, so that the API
546 cmake_push_check_state()
547 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
548 check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
549 if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
550 check_c_source_compiles(
556 struct protoent protoent_buf;
558 struct protoent *resultp;
560 return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
563 HAVE_LINUX_GETPROTOBYNAME_R)
564 if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
565 check_c_source_compiles(
571 struct protoent protoent_buf;
574 return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
577 HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
578 if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
579 check_c_source_compiles(
585 struct protoent protoent_buf;
586 struct protoent_data proto_data;
588 return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
591 HAVE_AIX_GETPROTOBYNAME_R)
592 endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
593 endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
594 endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
595 cmake_pop_check_state()
600 # XXX - there's no check_type() macro that's like check_type_size()
601 # except that it only checks for the existence of the structure type,
602 # so we use check_type_size() and ignore the size.
604 cmake_push_check_state()
606 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
608 set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
610 check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
611 check_type_size("socklen_t" SOCKLEN_T)
612 cmake_pop_check_state()
618 check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
620 check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
624 # Do we have ffs(), and is it declared in <strings.h>?
626 check_function_exists(ffs HAVE_FFS)
629 # OK, we have ffs(). Is it declared in <strings.h>?
631 # This test fails if we don't have <strings.h> or if we do
632 # but it doesn't declare ffs().
634 check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
638 # This requires the libraries that we require, as ether_hostton might be
639 # in one of those libraries. That means we have to do this after
640 # we check for those libraries.
642 # You are in a twisty little maze of UN*Xes, all different.
643 # Some might not have ether_hostton().
644 # Some might have it and declare it in <net/ethernet.h>.
645 # Some might have it and declare it in <netinet/ether.h>
646 # Some might have it and declare it in <sys/ethernet.h>.
647 # Some might have it and declare it in <arpa/inet.h>.
648 # Some might have it and declare it in <netinet/if_ether.h>.
649 # Some might have it and not declare it in any header file.
651 # Before you is a C compiler.
653 cmake_push_check_state()
654 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
655 check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
656 if(HAVE_ETHER_HOSTTON)
658 # OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
660 # This test fails if we don't have <net/ethernet.h> or if we do
661 # but it doesn't declare ether_hostton().
663 check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
664 if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
666 # Yes - we have it declared.
668 set(HAVE_DECL_ETHER_HOSTTON TRUE)
673 if(NOT HAVE_DECL_ETHER_HOSTTON)
675 # No - how about <netinet/ether.h>, as on Linux?
677 # This test fails if we don't have <netinet/ether.h>
678 # or if we do but it doesn't declare ether_hostton().
680 check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
681 if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
683 # Yes - we have it declared.
685 set(HAVE_DECL_ETHER_HOSTTON TRUE)
691 if(NOT HAVE_DECL_ETHER_HOSTTON)
693 # No - how about <sys/ethernet.h>, as on Solaris 10 and later?
695 # This test fails if we don't have <sys/ethernet.h>
696 # or if we do but it doesn't declare ether_hostton().
698 check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
699 if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
701 # Yes - we have it declared.
703 set(HAVE_DECL_ETHER_HOSTTON TRUE)
709 if(NOT HAVE_DECL_ETHER_HOSTTON)
711 # No, how about <arpa/inet.h>, as on AIX?
713 # This test fails if we don't have <arpa/inet.h>
714 # or if we do but it doesn't declare ether_hostton().
716 check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
717 if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
719 # Yes - we have it declared.
721 set(HAVE_DECL_ETHER_HOSTTON TRUE)
727 if(NOT HAVE_DECL_ETHER_HOSTTON)
729 # No, how about <netinet/if_ether.h>?
730 # On some platforms, it requires <net/if.h> and
731 # <netinet/in.h>, and we always include it with
732 # both of them, so test it with both of them.
734 # This test fails if we don't have <netinet/if_ether.h>
735 # and the headers we include before it, or if we do but
736 # <netinet/if_ether.h> doesn't declare ether_hostton().
738 check_symbol_exists(ether_hostton "sys/types.h;sys/socket.h;net/if.h;netinet/in.h;netinet/if_ether.h" NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
739 if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
741 # Yes - we have it declared.
743 set(HAVE_DECL_ETHER_HOSTTON TRUE)
747 # After all that, is ether_hostton() declared?
749 if(NOT HAVE_DECL_ETHER_HOSTTON)
751 # No, we'll have to declare it ourselves.
752 # Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
754 # XXX - there's no check_type() macro that's like check_type_size()
755 # except that it only checks for the existence of the structure type,
756 # so we use check_type_size() and ignore the size.
758 cmake_push_check_state()
759 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
760 check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
761 cmake_pop_check_state()
764 cmake_pop_check_state()
767 # Large file support on UN*X, a/k/a LFS.
773 # Add the required #defines.
775 add_definitions(${LFS_DEFINITIONS})
779 # Check for fseeko as well.
786 # Add the required #defines.
788 add_definitions(${FSEEKO_DEFINITIONS})
793 message(STATUS "Support IPv6")
798 # We might need them, because some libraries we use might use them,
799 # but we don't necessarily need them.
800 # That's only on UN*X; on Windows, if they use threads, we assume
801 # they're native Windows threads.
804 set(CMAKE_THREAD_PREFER_PTHREAD ON)
805 find_package(Threads)
806 if(NOT CMAKE_USE_PTHREADS_INIT)
808 # If it's not pthreads, we won't use it; we use it for libraries
811 set(CMAKE_THREAD_LIBS_INIT "")
812 endif(NOT CMAKE_USE_PTHREADS_INIT)
815 ######################################
817 ######################################
819 set(PROJECT_SOURCE_LIST_C
837 # For now, we assume we don't have snprintf() or that it's not one
838 # that behaves enough like C99's snprintf() for our purposes (i.e.,
839 # it doesn't null-terminate the string if it truncates it to fit in
840 # the buffer), so we have to provide our own (a wrapper around
841 # _snprintf() that null-terminates the buffer).
843 # We also assume we don't have asprintf(), and provide an implementation
844 # that uses _vscprintf() to determine how big the string needs to be.
846 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
847 missing/win_snprintf.c missing/win_asprintf.c)
852 # we have snprintf() and vsnprintf(), and have asprintf() and
855 # we have snprintf() and vsnprintf(), but don't have asprintf()
858 # we have neither snprintf() nor vsnprintf(), and don't have
859 # asprintf() or vasprintf(), either.
861 # We assume that if we have asprintf() we have vasprintf(), as well
862 # as snprintf() and vsnprintf(), and that if we have snprintf() we
865 # For the first case, we don't need any replacement routines.
866 # For the second case, we need replacement asprintf()/vasprintf()
868 # For the third case, we need replacement snprintf()/vsnprintf() and
869 # asprintf()/vasprintf() routines.
871 if(NOT HAVE_SNPRINTF)
873 # We assume we have none of them; missing/snprintf.c supplies
876 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
877 elif(NOT HAVE_ASPRINTF)
879 # We assume we have snprintf()/vsnprintf() but lack
880 # asprintf()/vasprintf(); missing/asprintf.c supplies
881 # the latter (using vsnprintf()).
883 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/asprintf.c)
886 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcat.c)
887 endif(NOT HAVE_STRLCAT)
889 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strlcpy.c)
890 endif(NOT HAVE_STRLCPY)
891 if(NOT HAVE_STRTOK_R)
892 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
893 endif(NOT HAVE_STRTOK_R)
897 # Determine the main pcap-XXX.c file to use, and the libraries with
898 # which we need to link libpcap, if any.
904 # Has the user explicitly specified a capture type?
906 if(PCAP_TYPE STREQUAL "")
908 # The user didn't explicitly specify a capture mechanism.
909 # Check whether we have packet.dll.
913 # We have packet.dll.
914 # Set the capture type to NPF.
919 # We don't have any capture type we know about, so just use
920 # the null capture type, and only support reading (and writing)
930 # Figure out what type of packet capture mechanism we have, and
931 # what libraries we'd need to link libpcap with, if any.
935 # Has the user explicitly specified a capture type?
937 if(PCAP_TYPE STREQUAL "")
939 # Check for a bunch of headers for various packet capture mechanisms.
941 check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
944 # Does it define BIOCSETIF?
945 # I.e., is it a header for an LBL/BSD-style capture
946 # mechanism, or is it just a header for a BPF filter
947 # engine? Some versions of Arch Linux, for example,
948 # have a net/bpf.h that doesn't define BIOCSETIF;
949 # as it's a Linux, it should use packet sockets,
954 # sys/types.h, because FreeBSD 10's net/bpf.h
955 # requires that various BSD-style integer types
958 # sys/time.h, because AIX 5.2 and 5.3's net/bpf.h
959 # doesn't include it but does use struct timeval
960 # in ioctl definitions;
962 # sys/ioctl.h and, if we have it, sys/ioccom.h,
963 # because net/bpf.h defines ioctls;
965 # net/if.h, because it defines some structures
966 # used in ioctls defined by net/bpf.h;
968 # sys/socket.h, because OpenBSD 5.9's net/bpf.h
969 # defines some structure fields as being
972 # and net/bpf.h doesn't necessarily include all
973 # of those headers itself.
975 if(HAVE_SYS_IOCCOM_H)
976 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
977 else(HAVE_SYS_IOCCOM_H)
978 check_symbol_exists(BIOCSETIF "sys/types.h;sys/time.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
979 endif(HAVE_SYS_IOCCOM_H)
980 endif(HAVE_NET_BPF_H)
981 check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
982 check_include_file(net/enet.h HAVE_NET_ENET_H)
983 check_include_file(net/nit.h HAVE_NET_NIT_H)
984 check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
985 check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
986 check_include_file(net/raw.h HAVE_NET_RAW_H)
987 check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
989 if(BPF_H_DEFINES_BIOCSETIF)
992 # Check this before DLPI, so that we pick BPF on
993 # Solaris 11 and later.
996 elseif(HAVE_LINUX_SOCKET_H)
998 # No prizes for guessing this one.
1000 set(PCAP_TYPE linux)
1001 elseif(HAVE_NET_PFILT_H)
1003 # DEC OSF/1, Digital UNIX, Tru64 UNIX
1006 elseif(HAVE_NET_ENET_H)
1008 # Stanford Enetfilter.
1011 elseif(HAVE_NET_NIT_H)
1013 # SunOS 4.x STREAMS NIT.
1016 elseif(HAVE_SYS_NET_NIT_H)
1018 # Pre-SunOS 4.x non-STREAMS NIT.
1021 elseif(HAVE_NET_RAW_H)
1025 set(PCAP_TYPE snoop)
1026 elseif(HAVE_SYS_DLPI_H)
1028 # DLPI on pre-Solaris 11 SunOS 5, HP-UX, possibly others.
1033 # Nothing we support.
1039 message(STATUS "Packet capture mechanism type: ${PCAP_TYPE}")
1042 # Do capture-mechanism-dependent tests.
1045 if(PCAP_TYPE STREQUAL "npf")
1047 # Link with packet.dll before WinSock2.
1049 set(PCAP_LINK_LIBRARIES ${PACKET_LIBRARIES} ${PCAP_LINK_LIBRARIES})
1050 elseif(PCAP_TYPE STREQUAL "null")
1052 message(ERROR "${PCAP_TYPE} is not a valid pcap type")
1055 if(PCAP_TYPE STREQUAL "dlpi")
1057 # Needed for common functions used by pcap-[dlpi,libdlpi].c
1059 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} dlpisubs.c)
1062 # Checks for some header files.
1064 check_include_file(sys/bufmod.h HAVE_SYS_BUFMOD_H)
1065 check_include_file(sys/dlpi_ext.h HAVE_SYS_DLPI_EXT_H)
1068 # Checks to see if Solaris has the public libdlpi(3LIB) library.
1069 # Note: The existence of /usr/include/libdlpi.h does not mean it is the
1070 # public libdlpi(3LIB) version. Before libdlpi was made public, a
1071 # private version also existed, which did not have the same APIs.
1072 # Due to a gcc bug, the default search path for 32-bit libraries does
1073 # not include /lib, we add it explicitly here.
1074 # [http://bugs.opensolaris.org/view_bug.do?bug_id=6619485].
1075 # Also, due to the bug above applications that link to libpcap with
1076 # libdlpi will have to add "-L/lib" option to "configure".
1078 cmake_push_check_state()
1079 set(CMAKE_REQUIRED_FLAGS "-L/lib")
1080 set(CMAKE_REQUIRED_LIBRARIES dlpi)
1081 check_function_exists(dlpi_walk HAVE_LIBDLPI)
1082 cmake_pop_check_state()
1087 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} dlpi)
1088 set(PCAP_TYPE libdlpi)
1092 # This check is for Solaris with DLPI support for passive modes.
1093 # See dlpi(7P) for more details.
1095 # XXX - there's no check_type() macro that's like check_type_size()
1096 # except that it only checks for the existence of the structure type,
1097 # so we use check_type_size() and ignore the size.
1099 cmake_push_check_state()
1100 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/dlpi.h)
1101 check_type_size(dl_passive_req_t DL_PASSIVE_REQ_T)
1102 cmake_pop_check_state()
1103 elseif(PCAP_TYPE STREQUAL "linux")
1105 # Do we have the wireless extensions?
1106 # linux/wireless.h requires sys/socket.h.
1108 check_include_files("sys/socket.h;linux/wireless.h" HAVE_LINUX_WIRELESS_H)
1113 if(BUILD_WITH_LIBNL)
1115 # Try libnl 3.x first.
1117 cmake_push_check_state()
1118 set(CMAKE_REQUIRED_LIBRARIES nl-3)
1119 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1120 cmake_pop_check_state()
1123 # Yes, we have libnl 3.x.
1125 set(PCAP_LINK_LIBRARIES nl-genl-3 nl-3 ${PCAP_LINK_LIBRARIES})
1126 set(HAVE_LIBNL_3_x ON)
1127 set(HAVE_LIBNL_NLE ON)
1128 set(HAVE_LIBNL_SOCKETS ON)
1129 include_directories("/usr/include/libnl3")
1134 cmake_push_check_state()
1135 set(CMAKE_REQUIRED_LIBRARIES nl)
1136 check_function_exists(nl_socket_alloc HAVE_LIBNL)
1137 cmake_pop_check_state()
1140 # Yes, we have libnl 2.x.
1142 set(PCAP_LINK_LIBRARIES nl-genl nl ${PCAP_LINK_LIBRARIES})
1143 set(HAVE_LIBNL_2_x ON)
1144 set(HAVE_LIBNL_NLE ON)
1145 set(HAVE_LIBNL_SOCKETS ON)
1148 # No, we don't; do we have libnl 1.x?
1150 cmake_push_check_state()
1151 set(CMAKE_REQUIRED_LIBRARIES nl)
1152 check_function_exists(nl_handle_alloc HAVE_LIBNL)
1153 cmake_pop_check_state()
1155 set(PCAP_LINK_LIBRARIES nl ${PCAP_LINK_LIBRARIES})
1161 check_include_file(linux/ethtool.h HAVE_LINUX_ETHTOOL_H)
1164 # Checks to see if tpacket_stats is defined in linux/if_packet.h
1165 # If so then pcap-linux.c can use this to report proper statistics.
1167 # XXX - there's no check_type() macro that's like check_type_size()
1168 # except that it only checks for the existence of the structure type,
1169 # so we use check_type_size() and ignore the size.
1171 cmake_push_check_state()
1172 set(CMAKE_EXTRA_INCLUDE_FILES linux/if_packet.h)
1173 check_type_size("struct tpacket_stats" STRUCT_TPACKET_STATS)
1174 cmake_pop_check_state()
1176 check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
1177 elseif(PCAP_TYPE STREQUAL "bpf")
1179 # Check whether we have the *BSD-style ioctls.
1181 check_include_files("sys/types.h;net/if_media.h" HAVE_NET_IF_MEDIA_H)
1184 # Check whether we have struct BPF_TIMEVAL.
1186 # XXX - there's no check_type() macro that's like check_type_size()
1187 # except that it only checks for the existence of the structure type,
1188 # so we use check_type_size() and ignore the size.
1190 cmake_push_check_state()
1191 if(HAVE_SYS_IOCCOM_H)
1192 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/ioccom.h net/bpf.h)
1193 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1195 set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/bpf.h)
1196 check_type_size("struct BPF_TIMEVAL" STRUCT_BPF_TIMEVAL)
1198 cmake_pop_check_state()
1199 elseif(PCAP_TYPE STREQUAL "null")
1201 message(FATAL_ERROR "${PCAP_TYPE} is not a valid pcap type")
1205 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-${PCAP_TYPE}.c)
1208 # Now figure out how we get a list of interfaces and addresses,
1209 # if we support capturing. Don't bother if we don't support
1214 # UN*X - figure out what type of interface list mechanism we
1217 # If the capture type is null, that means we can't capture,
1218 # so we can't open any capture devices, so we won't return
1221 if(NOT PCAP_TYPE STREQUAL "null")
1222 cmake_push_check_state()
1223 set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
1224 check_function_exists(getifaddrs HAVE_GETIFADDRS)
1225 cmake_pop_check_state()
1226 if(NOT HAVE_GETIFADDRS)
1228 # It's not in the libraries that, at this point, we've
1229 # found we need to link libpcap with.
1231 # It's in libsocket on Solaris and possibly other OSes;
1232 # as long as we're not linking with libxnet, check there.
1234 # NOTE: if you hand check_library_exists as its last
1235 # argument a variable that's been set, it skips the test,
1236 # so we need different variables.
1238 if(NOT LIBXNET_HAS_GETHOSTBYNAME)
1239 check_library_exists(socket getifaddrs "" SOCKET_HAS_GETIFADDRS)
1240 if(SOCKET_HAS_GETIFADDRS)
1241 set(PCAP_LINK_LIBRARIES socket ${PCAP_LINK_LIBRARIES})
1242 set(HAVE_GETIFADDRS TRUE)
1248 # We have "getifaddrs()"; make sure we have <ifaddrs.h>
1249 # as well, just in case some platform is really weird.
1250 # It may require that sys/types.h be included first,
1251 # so include it first.
1253 check_include_files("sys/types.h;ifaddrs.h" HAVE_IFADDRS_H)
1256 # We have the header, so we use "getifaddrs()" to
1257 # get the list of interfaces.
1259 set(FINDALLDEVS_TYPE getad)
1262 # We don't have the header - give up.
1263 # XXX - we could also fall back on some other
1264 # mechanism, but, for now, this'll catch this
1265 # problem so that we can at least try to figure
1266 # out something to do on systems with "getifaddrs()"
1267 # but without "ifaddrs.h", if there is something
1268 # we can do on those systems.
1270 message(FATAL_ERROR "Your system has getifaddrs() but doesn't have a usable <ifaddrs.h>.")
1274 # Well, we don't have "getifaddrs()", at least not with the
1275 # libraries with which we've decided we need to link
1276 # libpcap with, so we have to use some other mechanism.
1278 # Note that this may happen on Solaris, which has
1279 # getifaddrs(), but in -lsocket, not in -lxnet, so we
1280 # won't find it if we link with -lxnet, which we want
1281 # to do for other reasons.
1283 # For now, we use either the SIOCGIFCONF ioctl or the
1284 # SIOCGLIFCONF ioctl, preferring the latter if we have
1285 # it; the latter is a Solarisism that first appeared
1286 # in Solaris 8. (Solaris's getifaddrs() appears to
1287 # be built atop SIOCGLIFCONF; using it directly
1288 # avoids a not-all-that-useful middleman.)
1290 try_compile(HAVE_SIOCGLIFCONF ${CMAKE_CURRENT_BINARY_DIR} "${pcap_SOURCE_DIR}/cmake/have_siocglifconf.c" )
1291 if(HAVE_SIOCGLIFCONF)
1292 set(FINDALLDEVS_TYPE glifc)
1294 set(FINDALLDEVS_TYPE gifc)
1297 message(STATUS "Find-interfaces mechanism type: ${FINDALLDEVS_TYPE}")
1298 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} fad-${FINDALLDEVS_TYPE}.c)
1302 # Check for hardware timestamp support.
1303 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1304 check_include_file(linux/net_tstamp.h HAVE_LINUX_NET_TSTAMP_H)
1308 # Check for additional native sniffing capabilities.
1311 # Check for USB sniffing support on Linux.
1312 # On FreeBSD, it uses BPF, so we don't need to do anything special here.
1314 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1315 set(PCAP_SUPPORT_USB TRUE)
1316 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
1317 set(LINUX_USB_MON_DEV /dev/usbmon)
1319 # Do we have a version of <linux/compiler.h> available?
1320 # If so, we might need it for <linux/usbdevice_fs.h>.
1322 check_include_files("linux/compiler.h" HAVE_LINUX_COMPILER_H)
1323 if(HAVE_LINUX_COMPILER_H)
1325 # Yes - include it when testing for <linux/usbdevice_fs.h>.
1327 check_include_files("linux/compiler.h;linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1328 else(HAVE_LINUX_COMPILER_H)
1329 check_include_files("linux/usbdevice_fs.h" HAVE_LINUX_USBDEVICE_FS_H)
1330 endif(HAVE_LINUX_COMPILER_H)
1331 if(HAVE_LINUX_USBDEVICE_FS_H)
1333 # OK, does it define bRequestType? Older versions of the kernel
1334 # define fields with names like "requesttype, "request", and
1335 # "value", rather than "bRequestType", "bRequest", and
1338 if(HAVE_LINUX_COMPILER_H)
1339 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/compiler.h;linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1340 else(HAVE_LINUX_COMPILER_H)
1341 check_struct_has_member("struct usbdevfs_ctrltransfer" bRequestType "linux/usbdevice_fs.h" HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE)
1342 endif(HAVE_LINUX_COMPILER_H)
1347 # Check for netfilter sniffing support.
1348 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1350 # Life's too short to deal with trying to get this to compile
1351 # if you don't get the right types defined with
1352 # __KERNEL_STRICT_NAMES getting defined by some other include.
1354 # Check whether the includes Just Work. If not, don't turn on
1355 # netfilter support.
1357 check_c_source_compiles(
1358 "#include <sys/socket.h>
1359 #include <netinet/in.h>
1360 #include <linux/types.h>
1362 #include <linux/netlink.h>
1363 #include <linux/netfilter.h>
1364 #include <linux/netfilter/nfnetlink.h>
1365 #include <linux/netfilter/nfnetlink_log.h>
1366 #include <linux/netfilter/nfnetlink_queue.h>
1374 PCAP_SUPPORT_NETFILTER)
1375 if(PCAP_SUPPORT_NETFILTER)
1376 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netfilter-linux.c)
1377 endif(PCAP_SUPPORT_NETFILTER)
1380 # Check for netmap sniffing support.
1381 if(NOT DISABLE_NETMAP)
1383 # Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
1384 # defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
1385 # is defined, for example, as it includes a non-existent malloc.h
1388 check_c_source_compiles(
1389 "#define NETMAP_WITH_LIBS
1390 #include <net/netmap_user.h>
1398 PCAP_SUPPORT_NETMAP)
1399 if(PCAP_SUPPORT_NETMAP)
1400 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-netmap.c)
1401 endif(PCAP_SUPPORT_NETMAP)
1404 # Check for Bluetooth sniffing support
1405 if(NOT DISABLE_BLUETOOTH)
1406 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
1407 check_include_file(bluetooth/bluetooth.h HAVE_BLUETOOTH_BLUETOOTH_H)
1408 if(HAVE_BLUETOOTH_BLUETOOTH_H)
1409 set(PCAP_SUPPORT_BT TRUE)
1410 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-linux.c)
1412 # OK, does struct sockaddr_hci have an hci_channel
1415 check_struct_has_member("struct sockaddr_hci" hci_channel "bluetooth/bluetooth.h;bluetooth/hci.h" HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1416 if(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1418 # OK, is HCI_CHANNEL_MONITOR defined?
1420 check_c_source_compiles(
1421 "#include <bluetooth/bluetooth.h>
1422 #include <bluetooth/hci.h>
1427 u_int i = HCI_CHANNEL_MONITOR;
1431 PCAP_SUPPORT_BT_MONITOR)
1432 if(PCAP_SUPPORT_BT_MONITOR)
1434 # Yes, so we can also support Bluetooth monitor
1437 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-bt-monitor-linux.c)
1438 endif(PCAP_SUPPORT_BT_MONITOR)
1439 endif(HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL)
1440 endif(HAVE_BLUETOOTH_BLUETOOTH_H)
1444 # Check for Bluetooth sniffing support
1445 if(NOT DISABLE_DBUS)
1447 # We don't support D-Bus sniffing on macOS; see
1449 # https://bugs.freedesktop.org/show_bug.cgi?id=74029
1452 message(FATAL_ERROR "Due to freedesktop.org bug 74029, D-Bus capture support is not available on macOS")
1454 include(FindPkgConfig)
1455 pkg_check_modules(DBUS dbus-1)
1457 set(PCAP_SUPPORT_DBUS TRUE)
1458 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dbus.c)
1459 include_directories(${DBUS_INCLUDE_DIRS})
1462 # This "helpfully" supplies DBUS_LIBRARIES as a bunch of
1463 # library names - not paths - and DBUS_LIBRARY_DIRS as
1464 # a bunch of directories.
1466 # CMake *really* doesn't like the notion of specifying "here are
1467 # the directories in which to look for libraries" except in
1468 # find_library() calls; it *really* prefers using full paths to
1469 # library files, rather than library names.
1471 # Find the libraries and add their full paths.
1473 set(DBUS_LIBRARY_FULLPATHS)
1474 foreach(_lib IN LISTS DBUS_LIBRARIES)
1476 # Try to find this library, so we get its full path.
1478 find_library(_libfullpath ${_lib} HINTS ${DBUS_LIBRARY_DIRS})
1479 list(APPEND DBUS_LIBRARY_FULLPATHS ${_libfullpath})
1481 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DBUS_LIBRARY_FULLPATHS})
1483 endif(NOT DISABLE_DBUS)
1485 # Check for RDMA sniffing support
1486 if(NOT DISABLE_RDMA)
1487 check_library_exists(ibverbs ibv_get_device_list "" LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1488 if(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1489 check_include_file(infiniband/verbs.h HAVE_INFINIBAND_VERBS_H)
1490 if(HAVE_INFINIBAND_VERBS_H)
1491 check_symbol_exists(ibv_create_flow infiniband/verbs.h PCAP_SUPPORT_RDMASNIFF)
1492 if(PCAP_SUPPORT_RDMASNIFF)
1493 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-rdmasniff.c)
1494 set(PCAP_LINK_LIBRARIES ibverbs ${PCAP_LINK_LIBRARIES})
1495 endif(PCAP_SUPPORT_RDMASNIFF)
1496 endif(HAVE_INFINIBAND_VERBS_H)
1497 endif(LIBIBVERBS_HAS_IBV_GET_DEVICE_LIST)
1498 endif(NOT DISABLE_RDMA)
1501 # Check for sniffing capabilities using third-party APIs.
1504 # Check for Endace DAG card support.
1507 # Try to find the DAG header file and library.
1517 # Check for various DAG API functions.
1519 cmake_push_check_state()
1520 set(CMAKE_REQUIRED_INCLUDES ${DAG_INCLUDE_DIRS})
1521 set(CMAKE_REQUIRED_LIBRARIES ${DAG_LIBRARIES})
1522 check_function_exists(dag_attach_stream HAVE_DAG_STREAMS_API)
1523 if(NOT HAVE_DAG_STREAMS_API)
1524 message(FATAL_ERROR "DAG library lacks streams support")
1526 check_function_exists(dag_attach_stream64 HAVE_DAG_LARGE_STREAMS_API)
1527 check_function_exists(dag_get_erf_types HAVE_DAG_GET_ERF_TYPES)
1528 check_function_exists(dag_get_stream_erf_types HAVE_DAG_GET_STREAM_ERF_TYPES)
1529 cmake_pop_check_state()
1531 include_directories(AFTER ${DAG_INCLUDE_DIRS})
1532 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dag.c)
1533 set(HAVE_DAG_API TRUE)
1534 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${DAG_LIBRARIES})
1536 if(HAVE_DAG_LARGE_STREAMS_API)
1537 get_filename_component(DAG_LIBRARY_DIR ${DAG_LIBRARY} PATH)
1538 check_library_exists(vdag vdag_set_device_info ${DAG_LIBRARY_DIR} HAVE_DAG_VDAG)
1540 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
1546 # Check for Septel card support.
1547 set(PROJECT_EXTERNAL_OBJECT_LIST "")
1548 if(NOT DISABLE_SEPTEL)
1550 # Do we have the msg.h header?
1552 set(SEPTEL_INCLUDE_DIRS "${SEPTEL_ROOT}/INC")
1553 cmake_push_check_state()
1554 set(CMAKE_REQUIRED_INCLUDES ${SEPTEL_INCLUDE_DIRS})
1555 check_include_file(msg.h HAVE_INC_MSG_H)
1556 cmake_pop_check_state()
1561 include_directories(AFTER ${SEPTEL_INCLUDE_DIRS})
1562 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-septel.c)
1563 set(PROJECT_EXTERNAL_OBJECT_LIST ${PROJECT_EXTERNAL_OBJECT_LIST} "${SEPTEL_ROOT}/asciibin.o ${SEPTEL_ROOT}/bit2byte.o ${SEPTEL_ROOT}/confirm.o ${SEPTEL_ROOT}/fmtmsg.o ${SEPTEL_ROOT}/gct_unix.o ${SEPTEL_ROOT}/hqueue.o ${SEPTEL_ROOT}/ident.o ${SEPTEL_ROOT}/mem.o ${SEPTEL_ROOT}/pack.o ${SEPTEL_ROOT}/parse.o ${SEPTEL_ROOT}/pool.o ${SEPTEL_ROOT}/sdlsig.o ${SEPTEL_ROOT}/strtonum.o ${SEPTEL_ROOT}/timer.o ${SEPTEL_ROOT}/trace.o")
1564 set(HAVE_SEPTEL_API TRUE)
1568 # Check for Myricom SNF support.
1571 # Try to find the SNF header file and library.
1582 include_directories(AFTER ${SNF_INCLUDE_DIRS})
1583 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-snf.c)
1584 set(HAVE_SNF_API TRUE)
1585 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${SNF_LIBRARIES})
1589 # Check for Riverbed TurboCap support.
1592 # Try to find the TurboCap header file and library.
1603 include_directories(AFTER ${TC_INCLUDE_DIRS})
1604 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-tc.c)
1605 set(HAVE_TC_API TRUE)
1606 set(PCAP_LINK_LIBRARIES "${PCAP_LINK_LIBRARIES} ${TC_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} stdc++")
1611 # Remote capture support.
1616 # Check for various members of struct msghdr.
1617 # We need to include ftmacros.h on some platforms, to make sure we
1618 # get the POSIX/Single USER Specification version of struct msghdr,
1619 # which has those members, rather than the backwards-compatible
1620 # version, which doesn't. That's not a system header file, and
1621 # at least some versions of CMake include it as <ftmacros.h>, which
1622 # won't check the current directory, so we add the top-level
1623 # source directory to the list of include directories when we do
1626 cmake_push_check_state()
1627 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})
1628 check_struct_has_member("struct msghdr" msg_control "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_CONTROL)
1629 check_struct_has_member("struct msghdr" msg_flags "ftmacros.h;sys/socket.h" HAVE_STRUCT_MSGHDR_MSG_FLAGS)
1630 cmake_pop_check_state()
1631 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C}
1632 pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c)
1633 endif(ENABLE_REMOTE)
1635 ###################################################################
1637 ###################################################################
1640 # Check and add warning options if we have a .devel file.
1642 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.devel OR EXISTS ${CMAKE_BINARY_DIR}/.devel)
1646 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1648 # MSVC, with Microsoft's front end and code generator.
1649 # "MSVC" is also set for Microsoft's compiler with a Clang
1650 # front end and their code generator ("Clang/C2"), so we
1651 # check for clang.exe and treat that differently.
1653 check_and_add_compiler_option(-Wall)
1655 # Disable some pointless warnings that /Wall turns on.
1657 # Unfortunately, MSVC does not appear to have an equivalent
1658 # to "__attribute__((unused))" to mark a particular function
1659 # parameter as being known to be unused, so that the compiler
1660 # won't warn about it (for example, the function might have
1661 # that parameter because a pointer to it is being used, and
1662 # the signature of that function includes that parameter).
1663 # C++ lets you give a parameter a type but no name, but C
1664 # doesn't have that.
1666 check_and_add_compiler_option(-wd4100)
1668 # In theory, we care whether somebody uses f() rather than
1669 # f(void) to declare a function with no arguments, but, in
1670 # practice, there are places in the Windows header files
1671 # that appear to do that, so we squelch that warning.
1673 check_and_add_compiler_option(-wd4255)
1675 # Windows FD_SET() generates this, so we suppress it.
1677 check_and_add_compiler_option(-wd4548)
1679 # Perhaps testing something #defined to be 0 with #ifdef is an
1680 # error, and it should be tested with #if, but perhaps it's
1681 # not, and Microsoft does that in its headers, so we squelch
1684 check_and_add_compiler_option(-wd4574)
1686 # The Windows headers also test not-defined values in #if, so
1687 # we don't want warnings about that, either.
1689 check_and_add_compiler_option(-wd4668)
1691 # We do *not* care whether some function is, or isn't, going to be
1694 check_and_add_compiler_option(-wd4710)
1695 check_and_add_compiler_option(-wd4711)
1697 # We do *not* care whether we're adding padding bytes after
1698 # structure members.
1700 check_and_add_compiler_option(-wd4820)
1703 # Other compilers, including MSVC with a Clang front end and
1704 # Microsoft's code generator. We currently treat them as if
1705 # they might support GCC-style -W options.
1707 check_and_add_compiler_option(-Wall)
1708 check_and_add_compiler_option(-Wsign-compare)
1709 check_and_add_compiler_option(-Wmissing-prototypes)
1710 check_and_add_compiler_option(-Wstrict-prototypes)
1711 check_and_add_compiler_option(-Wshadow)
1712 check_and_add_compiler_option(-Wdeclaration-after-statement)
1713 check_and_add_compiler_option(-Wused-but-marked-unused)
1714 check_and_add_compiler_option(-Wdocumentation)
1715 check_and_add_compiler_option(-Wcomma)
1716 check_and_add_compiler_option(-Wmissing-noreturn)
1717 # Warns about safeguards added in case the enums are extended
1718 # check_and_add_compiler_option(-Wcovered-switch-default)
1719 check_and_add_compiler_option(-Wmissing-variable-declarations)
1720 check_and_add_compiler_option(-Wunused-parameter)
1721 check_and_add_compiler_option(-Wformat-nonliteral)
1722 check_and_add_compiler_option(-Wunreachable-code)
1727 # Suppress some warnings we get with MSVC even without /Wall.
1729 if(MSVC AND NOT ${CMAKE_C_COMPILER} MATCHES "clang*")
1731 # Yes, we have some functions that never return but that
1732 # have a non-void return type. That's because, on some
1733 # platforms, they *do* return values but, on other
1734 # platforms, including Windows, they just fail and
1735 # longjmp out by calling bpf_error().
1737 check_and_add_compiler_option(-wd4646)
1740 file(GLOB PROJECT_SOURCE_LIST_H
1746 # Try to have the compiler default to hiding symbols, so that only
1747 # symbols explicitly exported with PCAP_API will be visible outside
1748 # (shared) libraries.
1750 # Not necessary with MSVC, as that's the default.
1752 # XXX - we don't use ADD_COMPILER_EXPORT_FLAGS, because, as of CMake
1753 # 2.8.12.2, it doesn't know about Sun C/Oracle Studio, and, as of
1754 # CMake 2.8.6, it only sets the C++ compiler flags, rather than
1755 # allowing an arbitrary variable to be set with the "hide symbols
1756 # not explicitly exported" flag.
1759 if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1761 # Sun C/Oracle Studio.
1763 check_and_add_compiler_option(-xldscope=hidden)
1766 # Try this for all other compilers; it's what GCC uses,
1767 # and a number of other compilers, such as Clang and Intel C,
1770 check_and_add_compiler_option(-fvisibility=hidden)
1775 # Flex/Lex and YACC/Berkeley YACC/Bison.
1776 # From a mail message to the CMake mailing list by Andy Cedilnik of
1781 # Try to find Flex, a Windows version of Flex, or Lex.
1783 find_program(LEX_EXECUTABLE NAMES flex win_flex lex)
1784 if(LEX_EXECUTABLE STREQUAL "LEX_EXECUTABLE-NOTFOUND")
1785 message(FATAL_ERROR "Neither flex nor win_flex nor lex was found.")
1787 message(STATUS "Lexical analyzer generator: ${LEX_EXECUTABLE}")
1790 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1791 SOURCE ${pcap_SOURCE_DIR}/scanner.l
1792 COMMAND ${LEX_EXECUTABLE} -P pcap_ --header-file=scanner.h --nounput -o${CMAKE_CURRENT_BINARY_DIR}/scanner.c ${pcap_SOURCE_DIR}/scanner.l
1793 DEPENDS ${pcap_SOURCE_DIR}/scanner.l
1797 # Since scanner.c does not exist yet when cmake is run, mark
1800 # Since scanner.c includes grammar.h, mark that as a dependency.
1802 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/scanner.c PROPERTIES
1804 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1808 # Add scanner.c to the list of sources.
1810 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/scanner.c)
1813 # Try to find YACC or Bison.
1815 find_program(YACC_EXECUTABLE NAMES bison win_bison byacc yacc)
1816 if(YACC_EXECUTABLE STREQUAL "YACC_EXECUTABLE-NOTFOUND")
1817 message(FATAL_ERROR "Neither bison nor win_bison nor byacc nor yacc was found.")
1819 message(STATUS "Parser generator: ${YACC_EXECUTABLE}")
1822 # Create custom command for the scanner.
1823 # Find out whether it's Bison or not by looking at the last component
1824 # of the path (without a .exe extension, if this is Windows).
1826 get_filename_component(YACC_NAME ${YACC_EXECUTABLE} NAME_WE)
1827 if("${YACC_NAME}" STREQUAL "bison" OR "${YACC_NAME}" STREQUAL "win_bison")
1828 set(YACC_COMPATIBILITY_FLAG "-y")
1831 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/grammar.c ${CMAKE_CURRENT_BINARY_DIR}/grammar.h
1832 SOURCE ${pcap_SOURCE_DIR}/grammar.y
1833 COMMAND ${YACC_EXECUTABLE} ${YACC_COMPATIBILITY_FLAG} -p pcap_ -o ${CMAKE_CURRENT_BINARY_DIR}/grammar.c -d ${pcap_SOURCE_DIR}/grammar.y
1834 DEPENDS ${pcap_SOURCE_DIR}/grammar.y
1838 # Since grammar.c does not exists yet when cmake is run, mark
1841 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/grammar.c PROPERTIES
1843 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/scanner.h
1847 # Add grammar.c to the list of sources.
1849 #set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
1852 # Assume, by default, no support for shared libraries and V7/BSD
1853 # convention for man pages (devices in section 4, file formats in
1854 # section 5, miscellaneous info in section 7, administrative commands
1855 # and daemons in section 8). Individual cases can override this.
1856 # Individual cases can override this.
1859 set(MAN_FILE_FORMATS 5)
1860 set(MAN_MISC_INFO 7)
1861 set(MAN_ADMIN_COMMANDS 8)
1862 if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
1863 # Workaround to enable certain features
1865 if(PCAP_TYPE STREQUAL "bpf")
1867 # If we're using BPF, we need libodm and libcfg, as
1868 # we use them to load the BPF module.
1870 set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} odm cfg)
1872 elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
1873 if(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*9\.[0-9]*")
1877 set(HAVE_HPUX9 TRUE)
1878 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.0")
1882 elseif(CMAKE_SYSTEM_VERSION MATCHES "[A-Z.]*10\.1")
1888 # HP-UX 10.20 and later.
1890 set(HAVE_HPUX10_20_OR_LATER TRUE)
1894 # Use System V conventions for man pages.
1896 set(MAN_ADMIN_COMMANDS 1m)
1897 set(MAN_FILE_FORMATS 4)
1898 set(MAN_MISC_INFO 5)
1899 elseif(CMAKE_SYSTEM_NAME STREQUAL "IRIX" OR CMAKE_SYSTEM_NAME STREQUAL "IRIX64")
1901 # Use IRIX conventions for man pages; they're the same as the
1902 # System V conventions, except that they use section 8 for
1903 # administrative commands and daemons.
1905 set(MAN_FILE_FORMATS 4)
1906 set(MAN_MISC_INFO 5)
1907 elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF1")
1909 # DEC OSF/1, a/k/a Digial UNIX, a/k/a Tru64 UNIX.
1910 # Use Tru64 UNIX conventions for man pages; they're the same as the
1911 # System V conventions except that they use section 8 for
1912 # administrative commands and daemons.
1914 set(MAN_FILE_FORMATS 4)
1915 set(MAN_MISC_INFO 5)
1917 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
1921 set(HAVE_SOLARIS TRUE)
1923 # Make sure errno is thread-safe, in case we're called in
1924 # a multithreaded program. We don't guarantee that two
1925 # threads can use the *same* pcap_t safely, but the
1926 # current version does guarantee that you can use different
1927 # pcap_t's in different threads, and even that pcap_compile()
1928 # is thread-safe (it wasn't thread-safe in some older versions).
1930 add_definitions(-D_TS_ERRNO)
1932 if(CMAKE_SYSTEM_VERSION STREQUAL "5.12")
1935 # Use System V conventions for man pages.
1937 set(MAN_ADMIN_COMMANDS 1m)
1938 set(MAN_FILE_FORMATS 4)
1939 set(MAN_MISC_INFO 5)
1944 source_group("Source Files" FILES ${PROJECT_SOURCE_LIST_C})
1945 source_group("Header Files" FILES ${PROJECT_SOURCE_LIST_H})
1949 # Add pcap-dll.rc to the list of sources.
1951 set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} ${pcap_SOURCE_DIR}/pcap-dll.rc)
1955 # Add subdirectories after we've set various variables, so they pick up
1956 # pick up those variables.
1959 add_subdirectory(rpcapd)
1960 endif(ENABLE_REMOTE)
1961 add_subdirectory(testprogs)
1963 ######################################
1965 ######################################
1968 # Special target to serialize the building of the generated source.
1972 # http://public.kitware.com/pipermail/cmake/2013-August/055510.html
1974 add_custom_target(SerializeTarget
1976 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1977 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1980 set_source_files_properties(${PROJECT_EXTERNAL_OBJECT_LIST} PROPERTIES
1981 EXTERNAL_OBJECT TRUE)
1983 if(BUILD_SHARED_LIBS)
1984 add_library(${LIBRARY_NAME} SHARED
1985 ${PROJECT_SOURCE_LIST_C}
1986 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
1987 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
1988 ${PROJECT_EXTERNAL_OBJECT_LIST}
1990 add_dependencies(${LIBRARY_NAME} SerializeTarget)
1991 set_target_properties(${LIBRARY_NAME} PROPERTIES
1992 COMPILE_DEFINITIONS BUILDING_PCAP)
1994 # No matter what the library is called - it might be called "wpcap"
1995 # in a Windows build - the symbol to define to indicate that we're
1996 # building the library, rather than a program using the library,
1997 # and thus that we're exporting functions defined in our public
1998 # header files, rather than importing those functions, is
2001 set_target_properties(${LIBRARY_NAME} PROPERTIES
2002 DEFINE_SYMBOL pcap_EXPORTS)
2003 endif(BUILD_SHARED_LIBS)
2005 add_library(${LIBRARY_NAME}_static STATIC
2006 ${PROJECT_SOURCE_LIST_C}
2007 ${CMAKE_CURRENT_BINARY_DIR}/grammar.c
2008 ${CMAKE_CURRENT_BINARY_DIR}/scanner.c
2009 ${PROJECT_EXTERNAL_OBJECT_LIST}
2011 add_dependencies(${LIBRARY_NAME}_static SerializeTarget)
2012 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2013 COMPILE_DEFINITIONS BUILDING_PCAP)
2016 if(BUILD_SHARED_LIBS)
2017 set_target_properties(${LIBRARY_NAME} PROPERTIES
2018 VERSION ${PACKAGE_VERSION_NOSUFFIX} # only MAJOR and MINOR are needed
2020 endif(BUILD_SHARED_LIBS)
2022 # XXX For DLLs, the TARGET_PDB_FILE generator expression can be used to locate
2023 # its PDB file's output directory for installation.
2024 # cmake doesn't offer a generator expression for PDB files generated by the
2025 # compiler (static libraries).
2026 # So instead of considering any possible output there is (there are many),
2027 # this will search for the PDB file in the compiler's initial output directory,
2028 # which is always ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles\wpcap_static.dir
2029 # regardless of architecture, build generator etc.
2030 # Quite hackish indeed.
2031 set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${LIBRARY_NAME}_static>)
2032 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2033 COMPILE_PDB_NAME ${LIBRARY_NAME}_static
2034 OUTPUT_NAME "${LIBRARY_NAME}_static"
2038 # For compatibility, build the shared library without the "lib" prefix on
2041 set_target_properties(${LIBRARY_NAME} PROPERTIES
2043 OUTPUT_NAME "${LIBRARY_NAME}"
2045 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2046 OUTPUT_NAME "${LIBRARY_NAME}"
2050 if(BUILD_SHARED_LIBS)
2052 set_target_properties(${LIBRARY_NAME} PROPERTIES
2053 VERSION ${PACKAGE_VERSION}
2057 set_target_properties(${LIBRARY_NAME} PROPERTIES
2058 VERSION ${PACKAGE_VERSION}
2059 SOVERSION ${PACKAGE_VERSION_MAJOR}
2062 endif(BUILD_SHARED_LIBS)
2063 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2064 OUTPUT_NAME "${LIBRARY_NAME}"
2068 if(BUILD_SHARED_LIBS)
2069 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2070 set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2072 target_link_libraries(${LIBRARY_NAME} ${PCAP_LINK_LIBRARIES})
2073 endif(BUILD_SHARED_LIBS)
2075 if(NOT C_ADDITIONAL_FLAGS STREQUAL "")
2076 set_target_properties(${LIBRARY_NAME}_static PROPERTIES COMPILE_FLAGS ${C_ADDITIONAL_FLAGS})
2080 # On macOS, build libpcap for the appropriate architectures, if
2081 # CMAKE_OSX_ARCHITECTURES isn't set (if it is, let that control
2082 # the architectures for which to build it).
2084 if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
2086 # Get the major version of Darwin.
2088 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
2090 if(SYSTEM_VERSION_MAJOR LESS 8)
2092 # Pre-Tiger. Build only for 32-bit PowerPC.
2094 set(OSX_LIBRARY_ARCHITECTURES "ppc")
2095 elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
2097 # Tiger. Is this prior to, or with, Intel support?
2099 # Get the minor version of Darwin.
2101 string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
2102 string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
2103 if(SYSTEM_VERSION_MINOR LESS 4)
2105 # Prior to Intel support. Build for 32-bit
2106 # PowerPC and 64-bit PowerPC, with 32-bit PowerPC
2107 # first. (I'm guessing that's what Apple does.)
2109 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64")
2110 elseif(SYSTEM_VERSION_MINOR LESS 7)
2112 # With Intel support but prior to x86-64 support.
2113 # Build for 32-bit PowerPC, 64-bit PowerPC, and 32-bit x86,
2114 # with 32-bit PowerPC first.
2115 # (I'm guessing that's what Apple does.)
2117 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386")
2120 # With Intel support including x86-64 support.
2121 # Build for 32-bit PowerPC, 64-bit PowerPC, 32-bit x86,
2122 # and x86-64, with 32-bit PowerPC first.
2123 # (I'm guessing that's what Apple does.)
2125 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2127 elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
2129 # Leopard. Build for 32-bit PowerPC, 64-bit
2130 # PowerPC, 32-bit x86, and x86-64, with 32-bit PowerPC
2131 # first. (That's what Apple does.)
2133 set(OSX_LIBRARY_ARCHITECTURES "ppc;ppc64;i386;x86_64")
2134 elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
2136 # Snow Leopard. Build for x86-64, 32-bit x86, and
2137 # 32-bit PowerPC, with x86-64 first. (That's
2138 # what Apple does, even though Snow Leopard
2139 # doesn't run on PPC, so PPC libpcap runs under
2140 # Rosetta, and Rosetta doesn't support BPF
2141 # ioctls, so PPC programs can't do live
2144 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386;ppc")
2147 # Post-Snow Leopard. Build for x86-64 and 32-bit x86,
2148 # with x86-64 first. (That's what Apple does)
2149 # XXX - update if and when Apple drops support
2150 # for 32-bit x86 code and if and when Apple adds
2151 # ARM-based Macs. (You're on your own for iOS etc.)
2153 # XXX - check whether we *can* build for i386 and, if not,
2154 # suggest that the user install the /usr/include headers if
2155 # they want to build fat.
2157 cmake_push_check_state()
2158 set(CMAKE_REQUIRED_FLAGS "-arch i386")
2159 check_c_source_compiles(
2166 X86_32_BIT_SUPPORTED)
2167 cmake_pop_check_state()
2168 if(X86_32_BIT_SUPPORTED)
2169 set(OSX_LIBRARY_ARCHITECTURES "x86_64;i386")
2171 set(OSX_LIBRARY_ARCHITECTURES "x86_64")
2172 if(SYSTEM_VERSION_MAJOR LESS 18)
2174 # Pre-Mojave; the command-line tools should be sufficient to
2175 # enable 32-bit x86 builds.
2177 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools")
2179 message(WARNING "Compiling for 32-bit x86 gives an error; try installing the command-line tools and, after that, installing the /usr/include headers from the /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg package")
2183 if(BUILD_SHARED_LIBS)
2184 set_target_properties(${LIBRARY_NAME} PROPERTIES
2185 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2186 endif(BUILD_SHARED_LIBS)
2187 set_target_properties(${LIBRARY_NAME}_static PROPERTIES
2188 OSX_ARCHITECTURES "${OSX_LIBRARY_ARCHITECTURES}")
2191 ######################################
2192 # Write out the config.h file
2193 ######################################
2195 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2197 ######################################
2198 # Install pcap library, include files, and man pages
2199 ######################################
2202 # "Define GNU standard installation directories", which actually
2203 # are also defined, to some degree, by autotools, and at least
2204 # some of which are general UN*X conventions.
2206 include(GNUInstallDirs)
2208 set(LIBRARY_NAME_STATIC ${LIBRARY_NAME}_static)
2210 function(install_manpage_symlink SOURCE TARGET MANDIR)
2212 find_program(LINK_EXECUTABLE ln)
2214 set(LINK_COMMAND "\"${LINK_EXECUTABLE}\" \"-s\" \"${SOURCE}\" \"${TARGET}\"")
2215 else(LINK_EXECUTABLE)
2216 message(FATAL_ERROR "ln (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html) not found.")
2217 endif(LINK_EXECUTABLE)
2219 set(LINK_COMMAND "\"${CMAKE_COMMAND}\" \"-E\" \"create_symlink\" \"${SOURCE}\" \"${TARGET}\"")
2223 "message(STATUS \"Symlinking: ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2225 COMMAND \"${CMAKE_COMMAND}\" \"-E\" \"remove\" \"${TARGET}\"
2226 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2229 COMMAND ${LINK_COMMAND}
2230 WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${MANDIR}
2231 RESULT_VARIABLE EXIT_STATUS
2233 if(NOT EXIT_STATUS EQUAL 0)
2234 message(FATAL_ERROR \"Could not create symbolic link from ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${SOURCE} to ${TARGET}\")
2236 set(CMAKE_INSTALL_MANIFEST_FILES \${CMAKE_INSTALL_MANIFEST_FILES} ${CMAKE_INSTALL_PREFIX}/${MANDIR}/${TARGET})")
2237 endfunction(install_manpage_symlink)
2239 set(MAN1_NOEXPAND pcap-config.1)
2242 pcap_compile.3pcap.in
2243 pcap_datalink.3pcap.in
2244 pcap_dump_open.3pcap.in
2245 pcap_get_tstamp_precision.3pcap.in
2246 pcap_list_datalinks.3pcap.in
2247 pcap_list_tstamp_types.3pcap.in
2248 pcap_open_dead.3pcap.in
2249 pcap_open_offline.3pcap.in
2250 pcap_set_immediate_mode.3pcap.in
2251 pcap_set_tstamp_precision.3pcap.in
2252 pcap_set_tstamp_type.3pcap.in
2254 set(MAN3PCAP_NOEXPAND
2256 pcap_breakloop.3pcap
2257 pcap_can_set_rfmon.3pcap
2260 pcap_datalink_name_to_val.3pcap
2261 pcap_datalink_val_to_name.3pcap
2263 pcap_dump_close.3pcap
2264 pcap_dump_file.3pcap
2265 pcap_dump_flush.3pcap
2266 pcap_dump_ftell.3pcap
2269 pcap_findalldevs.3pcap
2271 pcap_get_required_select_timeout.3pcap
2272 pcap_get_selectable_fd.3pcap
2275 pcap_is_swapped.3pcap
2276 pcap_lib_version.3pcap
2277 pcap_lookupdev.3pcap
2278 pcap_lookupnet.3pcap
2280 pcap_major_version.3pcap
2282 pcap_offline_filter.3pcap
2283 pcap_open_live.3pcap
2284 pcap_set_buffer_size.3pcap
2285 pcap_set_datalink.3pcap
2286 pcap_set_promisc.3pcap
2287 pcap_set_protocol_linux.3pcap
2288 pcap_set_rfmon.3pcap
2289 pcap_set_snaplen.3pcap
2290 pcap_set_timeout.3pcap
2291 pcap_setdirection.3pcap
2292 pcap_setfilter.3pcap
2293 pcap_setnonblock.3pcap
2296 pcap_statustostr.3pcap
2298 pcap_tstamp_type_name_to_val.3pcap
2299 pcap_tstamp_type_val_to_name.3pcap
2301 set(MANFILE_EXPAND pcap-savefile.manfile.in)
2303 pcap-filter.manmisc.in
2304 pcap-linktype.manmisc.in
2305 pcap-tstamp.manmisc.in
2308 if(NOT BUILD_SHARED_LIBS)
2310 endif(NOT BUILD_SHARED_LIBS)
2313 if(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2315 # Install 64-bit code built with MSVC in the amd64 subdirectories,
2316 # as that's where it expects it to be.
2318 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2319 RUNTIME DESTINATION bin/amd64
2320 LIBRARY DESTINATION lib/amd64
2321 ARCHIVE DESTINATION lib/amd64)
2323 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2324 DESTINATION bin/amd64 OPTIONAL)
2325 if(BUILD_SHARED_LIBS)
2326 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2327 DESTINATION bin/amd64 OPTIONAL)
2328 endif(BUILD_SHARED_LIBS)
2330 else(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2332 # Install 32-bit code, and 64-bit code not built with MSVC
2333 # in the top-level directories, as those are where they
2336 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC}
2337 RUNTIME DESTINATION bin
2338 LIBRARY DESTINATION lib
2339 ARCHIVE DESTINATION lib)
2341 install(FILES $<TARGET_FILE_DIR:${LIBRARY_NAME_STATIC}>/${LIBRARY_NAME_STATIC}.pdb
2342 DESTINATION bin OPTIONAL)
2343 if(BUILD_SHARED_LIBS)
2344 install(FILES $<TARGET_PDB_FILE:${LIBRARY_NAME}>
2345 DESTINATION bin OPTIONAL)
2346 endif(BUILD_SHARED_LIBS)
2348 endif(MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2350 install(TARGETS ${LIBRARY_NAME} ${LIBRARY_NAME_STATIC} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
2353 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pcap/ DESTINATION include/pcap)
2354 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap.h DESTINATION include)
2355 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-bpf.h DESTINATION include)
2356 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pcap-namedb.h DESTINATION include)
2358 # On UN*X, and on Windows when not using MSVC, generate libpcap.pc and
2359 # pcap-config and process man pages and arrange that they be installed.
2361 set(PACKAGE_NAME ${LIBRARY_NAME})
2362 set(prefix ${CMAKE_INSTALL_PREFIX})
2363 set(exec_prefix "\${prefix}")
2364 set(includedir "\${prefix}/include")
2365 set(libdir "\${exec_prefix}/lib")
2366 if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
2367 CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
2368 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
2369 CMAKE_SYSTEM_NAME STREQUAL "DragonFly BSD" OR
2370 CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
2371 CMAKE_SYSTEM_NAME STREQUAL "OSF1")
2373 # Platforms where the linker is the GNU linker
2374 # or accepts command-line arguments like
2375 # those the GNU linker accepts.
2377 set(V_RPATH_OPT "-Wl,-rpath,")
2378 elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
2382 # XXX - this assumes GCC is using the Sun linker,
2383 # rather than the GNU linker.
2385 set(V_RPATH_OPT "-Wl,-R,")
2388 # No option needed to set the RPATH.
2393 foreach(LIB ${PCAP_LINK_LIBRARIES})
2394 set(LIBS "${LIBS} -l${LIB}")
2396 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcap-config.in ${CMAKE_CURRENT_BINARY_DIR}/pcap-config @ONLY)
2397 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpcap.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc @ONLY)
2398 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pcap-config DESTINATION bin)
2399 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcap.pc DESTINATION lib/pkgconfig)
2404 # For each section of the manual for which we have man pages
2405 # that require macro expansion, do the expansion.
2408 foreach(MANPAGE ${MAN1_NOEXPAND})
2409 set(MAN1 ${MAN1} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2411 install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
2414 foreach(MANPAGE ${MAN3PCAP_NOEXPAND})
2415 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_SOURCE_DIR}/${MANPAGE})
2417 foreach(TEMPLATE_MANPAGE ${MAN3PCAP_EXPAND})
2418 string(REPLACE ".in" "" MANPAGE ${TEMPLATE_MANPAGE})
2419 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2420 set(MAN3PCAP ${MAN3PCAP} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2421 endforeach(TEMPLATE_MANPAGE)
2422 install(FILES ${MAN3PCAP} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
2423 install_manpage_symlink(pcap_datalink_val_to_name.3pcap pcap_datalink_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2424 install_manpage_symlink(pcap_dump_open.3pcap pcap_dump_fopen.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2425 install_manpage_symlink(pcap_findalldevs.3pcap pcap_freealldevs.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2426 install_manpage_symlink(pcap_geterr.3pcap pcap_perror.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2427 install_manpage_symlink(pcap_inject.3pcap pcap_sendpacket.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2428 install_manpage_symlink(pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2429 install_manpage_symlink(pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2430 install_manpage_symlink(pcap_loop.3pcap pcap_dispatch.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2431 install_manpage_symlink(pcap_major_version.3pcap pcap_minor_version.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2432 install_manpage_symlink(pcap_next_ex.3pcap pcap_next.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2433 install_manpage_symlink(pcap_open_dead.3pcap pcap_open_dead_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2434 install_manpage_symlink(pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2435 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2436 install_manpage_symlink(pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2437 install_manpage_symlink(pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2438 install_manpage_symlink(pcap_setnonblock.3pcap pcap_getnonblock.3pcap ${CMAKE_INSTALL_MANDIR}/man3)
2441 foreach(TEMPLATE_MANPAGE ${MANFILE_EXPAND})
2442 string(REPLACE ".manfile.in" ".${MAN_FILE_FORMATS}" MANPAGE ${TEMPLATE_MANPAGE})
2443 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2444 set(MANFILE ${MANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2445 endforeach(TEMPLATE_MANPAGE)
2446 install(FILES ${MANFILE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_FILE_FORMATS})
2449 foreach(TEMPLATE_MANPAGE ${MANMISC_EXPAND})
2450 string(REPLACE ".manmisc.in" ".${MAN_MISC_INFO}" MANPAGE ${TEMPLATE_MANPAGE})
2451 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEMPLATE_MANPAGE} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE} @ONLY)
2452 set(MANMISC ${MANMISC} ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE})
2453 endforeach(TEMPLATE_MANPAGE)
2454 install(FILES ${MANMISC} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_MISC_INFO})
2459 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
2460 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2463 add_custom_target(uninstall
2464 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)