forked from the-tcpdump-group/libpcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
2296 lines (2138 loc) · 78.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 2.8.6)
#
# Apple doesn't build with an install_name starting with @rpath, and
# neither do we with autotools; don't do so with CMake, either, and
# suppress warnings about that.
#
if(POLICY CMP0042)
cmake_policy(SET CMP0042 OLD)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
project(pcap)
#
# Try to enable as many C99 features as we can.
# At minimum, we want C++/C99-style // comments.
#
# Newer versions of compilers might default to supporting C99, but older
# versions may require a special flag.
#
# Prior to CMake 3.1, setting CMAKE_C_STANDARD will not have any effect,
# so, unless and until we require CMake 3.1 or later, we have to do it
# ourselves on pre-3.1 CMake, so we just do it ourselves on all versions
# of CMake.
#
# Note: with CMake 3.1 through 3.5, the only compilers for which CMake
# handles CMAKE_C_STANDARD are GCC and Clang. 3.6 adds support only
# for Intel C; 3.9 adds support for PGI C, Sun C, and IBM XL C, and
# 3.10 adds support for Cray C and IAR C, but no version of CMake has
# support for HP C. Therefore, even if we use CMAKE_C_STANDARD with
# compilers for which CMake supports it, we may still have to do it
# ourselves on other compilers.
#
# See the CMake documentation for the CMAKE_<LANG>_COMPILER_ID variables
# for a list of compiler IDs.
#
# We don't worry about MSVC; it doesn't have such a flag - either it
# doesn't support the C99 features we need at all, or it supports them
# regardless of the compiler flag.
#
# XXX - this just tests whether the option works and adds it if it does.
# We don't test whether it's necessary in order to get the C99 features
# that we use; if we ever have a user who tries to compile with a compiler
# that can't be made to support those features, we can add a test to make
# sure we actually *have* C99 support.
#
include(CheckCCompilerFlag)
macro(check_and_add_compiler_option _option)
message(STATUS "Checking C compiler flag ${_option}")
string(REPLACE "=" "-" _temp_option_variable ${_option})
string(REGEX REPLACE "^-" "" _option_variable ${_temp_option_variable})
check_c_compiler_flag("${_option}" ${_option_variable})
if(${${_option_variable}})
set(C_ADDITIONAL_FLAGS "${C_ADDITIONAL_FLAGS} ${_option}")
endif()
endmacro()
set(C_ADDITIONAL_FLAGS "")
if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
check_and_add_compiler_option("-std=gnu99")
elseif(CMAKE_C_COMPILER_ID MATCHES "XL")
#
# We want support for extensions picked up for GNU C compatibility,
# so we use -qlanglvl=extc99.
#
check_and_add_compiler_option("-qlanglvl=extc99")
elseif(CMAKE_C_COMPILER_ID MATCHES "HP")
check_and_add_compiler_option("-AC99")
elseif(CMAKE_C_COMPILER_ID MATCHES "Sun")
check_and_add_compiler_option("-xc99")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
check_and_add_compiler_option("-c99")
endif()
#
# Build all runtimes in the top-level binary directory; that way,
# on Windows, the executables will be in the same directory as
# the DLLs, so the system will find pcap.dll when any of the
# executables are run.
#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run)
###################################################################
# Parameters
###################################################################
if(WIN32)
#
# On Windows, allow the library name to be overridden, for the
# benefit of projects that combine libpcap with their own
# kernel-mode code to support capturing.
#
set(LIBRARY_NAME pcap CACHE STRING "Library name")
else()
#
# On UN*X, it's always been libpcap.
#
set(LIBRARY_NAME pcap)
endif()
option(INET6 "Enable IPv6" ON)
if(WIN32)
option(USE_STATIC_RT "Use static Runtime" ON)
endif(WIN32)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
if(WIN32)
set(PACKET_DLL_DIR "" CACHE PATH "Path to directory with include and lib subdirectories for packet.dll")
endif(WIN32)
# To pacify those who hate the protochain instruction
option(NO_PROTOCHAIN "Disable protochain instruction" OFF)
#
# Start out with the capture mechanism type unspecified; the user
# can explicitly specify it and, if they don't, we'll pick an
# appropriate one.
#
set(PCAP_TYPE "" CACHE STRING "Packet capture type")
#
# Default to having remote capture support on Windows and, for now, to
# not having it on UN*X.
#
if(WIN32)
option(ENABLE_REMOTE "Enable remote capture" ON)
else()
option(ENABLE_REMOTE "Enable remote capture" OFF)
endif(WIN32)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(PCAP_SUPPORT_PACKET_RING "Enable Linux packet ring support" ON)
option(BUILD_WITH_LIBNL "Build with libnl" ON)
endif()
#
# By default, build universal with the appropriate set of architectures
# for the OS on which we're doing the build.
#
if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
#
# Get the major version of Darwin.
#
string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MAJOR "${CMAKE_SYSTEM_VERSION}")
if(SYSTEM_VERSION_MAJOR LESS 8)
#
# Pre-Tiger. Build only for 32-bit PowerPC.
#
set(CMAKE_OSX_ARCHITECTURES "ppc")
elseif(SYSTEM_VERSION_MAJOR EQUAL 8)
#
# Tiger. Is this prior to, or with, Intel support?
#
# Get the minor version of Darwin.
#
string(REPLACE "${SYSTEM_VERSION_MAJOR}." "" SYSTEM_MINOR_AND_PATCH_VERSION ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+)" SYSTEM_VERSION_MINOR "${SYSTEM_MINOR_AND_PATCH_VERSION}")
if(SYSTEM_VERSION_MINOR LESS 4)
#
# Prior to Intel support. Build for 32-bit
# PowerPC and 64-bit PowerPC, with 32-bit PowerPC
# first. (I'm guessing that's what Apple does.)
#
set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64")
elseif(SYSTEM_VERSION_MINOR LESS 7)
#
# With Intel support but prior to x86-64 support.
# Build for 32-bit PowerPC, 64-bit PowerPC, and x86,
# with 32-bit PowerPC first.
# (I'm guessing that's what Apple does.)
#
set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386")
else()
#
# With Intel support including x86-64 support.
# Build for 32-bit PowerPC, 64-bit PowerPC, x86,
# and x86-64, with 32-bit PowerPC first.
# (I'm guessing that's what Apple does.)
#
set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
endif()
elseif(SYSTEM_VERSION_MAJOR EQUAL 9)
#
# Leopard. Build for 32-bit PowerPC, 64-bit
# PowerPC, x86, and x86-64, with 32-bit PowerPC
# first. (That's what Apple does.)
#
set(CMAKE_OSX_ARCHITECTURES "ppc;ppc64;i386;x86_64")
elseif(SYSTEM_VERSION_MAJOR EQUAL 10)
#
# Snow Leopard. Build for x86-64, x86, and
# 32-bit PowerPC, with x86-64 first. (That's
# what Apple does, even though Snow Leopard
# doesn't run on PPC, so PPC libpcap runs under
# Rosetta, and Rosetta doesn't support BPF
# ioctls, so PPC programs can't do live
# captures.)
#
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386;ppc")
else()
#
# Post-Snow Leopard. Build for x86-64 and
# x86, with x86-64 first. (That's probably what
# Apple does, given that Rosetta is gone.)
# XXX - update if and when Apple drops support
# for 32-bit x86 code.
#
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
endif()
endif()
#
# Additional capture modules.
#
option(DISABLE_USB "Disable USB sniffing support" OFF)
option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
option(DISABLE_NETMAP "Disable netmap support" OFF)
#
# We don't support D-Bus sniffing on macOS; see
#
# https://bugs.freedesktop.org/show_bug.cgi?id=74029
#
if(APPLE)
option(DISABLE_DBUS "Disable D-Bus sniffing support" ON)
else(APPLE)
option(DISABLE_DBUS "Disable D-Bus sniffing support" OFF)
endif(APPLE)
option(DISABLE_RDMA "Disable RDMA sniffing support" OFF)
option(DISABLE_DAG "Disable Endace DAG card support" OFF)
option(DISABLE_SEPTEL "Disable Septel card support" OFF)
set(SEPTEL_ROOT "${CMAKE_SOURCE_DIR}/../septel" CACHE PATH "Path to directory with include and lib subdirectories for Septel API")
option(DISABLE_SNF "Disable Myricom SNF support" OFF)
option(DISABLE_TC "Disable Riverbed TurboCap support" OFF)
#
# Debugging options.
#
option(BDEBUG "Build optimizer debugging code" OFF)
option(YYDEBUG "Build parser debugging code" OFF)
###################################################################
# Versioning
###################################################################
# Get, parse, format and set pcap's version string from [pcap_root]/VERSION
# for later use.
# Get MAJOR, MINOR, PATCH & SUFFIX
file(STRINGS ${pcap_SOURCE_DIR}/VERSION
PACKAGE_VERSION
LIMIT_COUNT 1 # Read only the first line
)
# Get "just" MAJOR
string(REGEX MATCH "^([0-9]+)" PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION}")
# Get MAJOR, MINOR & PATCH
string(REGEX MATCH "^([0-9]+.)?([0-9]+.)?([0-9]+)" PACKAGE_VERSION_NOSUFFIX "${PACKAGE_VERSION}")
if(WIN32)
# Convert PCAP_VERSION_NOSUFFIX to Windows preferred version format
string(REPLACE "." "," PACKAGE_VERSION_PREDLL ${PACKAGE_VERSION_NOSUFFIX})
# Append NANO (used for Windows internal versioning) to PCAP_VERSION_PREDLL
# 0 means unused.
set(PACKAGE_VERSION_DLL ${PACKAGE_VERSION_PREDLL},0)
endif(WIN32)
set(PACKAGE_NAME "${LIBRARY_NAME}")
set(PACKAGE_STRING "${LIBRARY_NAME} ${PACKAGE_VERSION}")
######################################
# Project settings
######################################
add_definitions(-DHAVE_CONFIG_H)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${pcap_SOURCE_DIR}
)
include(CheckFunctionExists)
include(CMakePushCheckState)
if(WIN32)
if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
include_directories(${CMAKE_HOME_DIRECTORY}/../../Common)
endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/../../Common)
find_package(Packet)
if(PACKET_FOUND)
set(HAVE_PACKET32 TRUE)
include_directories(${PACKET_INCLUDE_DIRS})
#
# Check whether we have the NPcap PacketIsLoopbackAdapter()
# function.
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${PACKET_LIBRARIES})
check_function_exists(PacketIsLoopbackAdapter HAVE_PACKET_IS_LOOPBACK_ADAPTER)
cmake_pop_check_state()
endif(PACKET_FOUND)
endif(WIN32)
if(MSVC)
add_definitions(-D__STDC__)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
if(USE_STATIC_RT)
message(STATUS "Use STATIC runtime")
if(MSVC)
foreach(RT_FLAG
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MD" "/MT" ${RT_FLAG} "${${RT_FLAG}}")
endforeach(RT_FLAG)
elseif(MINGW)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
endif()
else (USE_STATIC_RT)
message(STATUS "Use DYNAMIC runtime")
endif(USE_STATIC_RT)
###################################################################
# Detect available platform features
###################################################################
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckStructHasMember)
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)
if(NOT WIN32)
check_include_file(sys/ioccom.h HAVE_SYS_IOCCOM_H)
check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
check_include_file(sys/select.h HAVE_SYS_SELECT_H)
endif(NOT WIN32)
check_include_file(limits.h HAVE_LIMITS_H)
if(NOT WIN32)
check_include_file(netpacket/packet.h HAVE_NETPACKET_PACKET_H)
check_include_files("sys/types.h;sys/socket.h;net/if.h;net/pfvar.h" HAVE_NET_PFVAR_H)
if(HAVE_NET_PFVAR_H)
#
# Check for various PF actions.
#
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(HAVE_NET_PFVAR_H)
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)
#
# linux/if_bonding.h requires sys/socket.h.
#
check_include_files("sys/socket.h;linux/if_bonding.h" HAVE_LINUX_IF_BONDING_H)
endif()
endif(NOT WIN32)
#
# Functions.
#
check_function_exists(strerror HAVE_STRERROR)
check_function_exists(strerror_r HAVE_STRERROR_R)
check_function_exists(strerror_s HAVE_STRERROR_S)
check_function_exists(strlcpy HAVE_STRLCPY)
check_function_exists(strlcat HAVE_STRLCAT)
check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(strtok_r HAVE_STRTOK_R)
#
# These tests are for network applications that need socket functions
# and getaddrinfo()/getnameinfo()-ish functions. We now require
# getaddrinfo() and getnameinfo(). On UN*X systems, we also prefer
# versions of recvmsg() that conform to the Single UNIX Specification,
# so that we can check whether a datagram received with recvmsg() was
# truncated when received due to the buffer being too small.
#
# On Windows, getaddrinfo() is in the ws2_32 library.
# On most UN*X systems, they're available in the system library.
#
# Under Solaris, we need to link with libsocket and libnsl to get
# getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
# link with libxnet before libsocket to get a version of recvmsg()
# that conforms to the Single UNIX Specification.
#
# We use getaddrinfo() because we want a portable thread-safe way
# of getting information for a host name or port; there exist _r
# versions of gethostbyname() and getservbyname() on some platforms,
# but not on all platforms.
#
# NOTE: if you hand check_library_exists as its last argument a variable
# that's been set, it skips the test, so we need different variables.
#
set(PCAP_LINK_LIBRARIES "")
include(CheckLibraryExists)
include(CheckSymbolExists)
if(WIN32)
#
# We need winsock2.h and ws2tcpip.h.
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" LIBWS2_32_HAS_GETADDRINFO)
cmake_pop_check_state()
if(LIBWS2_32_HAS_GETADDRINFO)
set(PCAP_LINK_LIBRARIES ws2_32 ${PCAP_LINK_LIBRARIES})
else(LIBWS2_32_HAS_GETADDRINFO)
message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
endif(LIBWS2_32_HAS_GETADDRINFO)
else(WIN32)
#
# UN*X. First try the system libraries, then try the libraries
# for Solaris and possibly other systems that picked up the
# System V library split.
#
check_function_exists(getaddrinfo STDLIBS_HAVE_GETADDRINFO)
if(NOT STDLIBS_HAVE_GETADDRINFO)
#
# Not found in the standard system libraries.
# Try libsocket, which requires libnsl.
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES nsl)
check_library_exists(socket getaddrinfo "" LIBSOCKET_HAS_GETADDRINFO)
cmake_pop_check_state()
if(LIBSOCKET_HAS_GETADDRINFO)
#
# OK, we found it in libsocket.
#
set(PCAP_LINK_LIBRARIES socket nsl ${PCAP_LINK_LIBRARIES})
else(LIBSOCKET_HAS_GETADDRINFO)
#
# We didn't find it.
#
message(FATAL_ERROR "getaddrinfo is required, but wasn't found")
endif(LIBSOCKET_HAS_GETADDRINFO)
#
# OK, do we have recvmsg() in libxnet?
# We also link with libsocket and libnsl.
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES socket nsl)
check_library_exists(xnet recvmsg "" LIBXNET_HAS_RECVMSG)
cmake_pop_check_state()
if(LIBXNET_HAS_RECVMSG)
#
# Yes - link with it as well.
#
set(PCAP_LINK_LIBRARIES xnet ${PCAP_LINK_LIBRARIES})
endif(LIBXNET_HAS_RECVMSG)
endif(NOT STDLIBS_HAVE_GETADDRINFO)
# DLPI needs putmsg under HPUX so test for -lstr while we're at it
check_function_exists(putmsg STDLIBS_HAVE_PUTMSG)
if(NOT STDLIBS_HAVE_PUTMSG)
check_library_exists(str putmsg "" LIBSTR_HAS_PUTMSG)
if(LIBSTR_HAS_PUTMSG)
set(PCAP_LINK_LIBRARIES str ${PCAP_LINK_LIBRARIES})
endif(LIBSTR_HAS_PUTMSG)
endif(NOT STDLIBS_HAVE_PUTMSG)
endif(WIN32)
#
# Check for reentrant versions of getnetbyname_r(), as provided by
# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
# If we don't find one, we just use getnetbyname(), which uses
# thread-specific data on many platforms, but doesn't use it on
# NetBSD or OpenBSD, and may not use it on older versions of other
# platforms.
#
# Only do the check if we have a declaration of getnetbyname_r();
# without it, we can't check which API it has. (We assume that
# if there's a declaration, it has a prototype, so that the API
# can be checked.)
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
check_symbol_exists(getnetbyname_r netdb.h NETDB_H_DECLARES_GETNETBYNAME_R)
if(NETDB_H_DECLARES_GETNETBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct netent netent_buf;
char buf[1024];
struct netent *resultp;
int h_errnoval;
return getnetbyname_r((const char *)0, &netent_buf, buf, sizeof buf, &resultp, &h_errnoval);
}
"
HAVE_LINUX_GETNETBYNAME_R)
if(NOT HAVE_LINUX_GETNETBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct netent netent_buf;
char buf[1024];
return getnetbyname_r((const char *)0, &netent_buf, buf, (int)sizeof buf) != NULL;
}
"
HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
if(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct netent netent_buf;
struct netent_data net_data;
return getnetbyname_r((const char *)0, &netent_buf, &net_data);
}
"
HAVE_AIX_GETNETBYNAME_R)
endif(NOT HAVE_SOLARIS_IRIX_GETNETBYNAME_R)
endif(NOT HAVE_LINUX_GETNETBYNAME_R)
endif(NETDB_H_DECLARES_GETNETBYNAME_R)
cmake_pop_check_state()
#
# Check for reentrant versions of getprotobyname_r(), as provided by
# Linux (glibc), Solaris/IRIX, and AIX (with three different APIs!).
# If we don't find one, we just use getprotobyname(), which uses
# thread-specific data on many platforms, but doesn't use it on
# NetBSD or OpenBSD, and may not use it on older versions of other
# platforms.
#
# Only do the check if we have a declaration of getprotobyname_r();
# without it, we can't check which API it has. (We assume that
# if there's a declaration, it has a prototype, so that the API
# can be checked.)
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
check_symbol_exists(getprotobyname_r netdb.h NETDB_H_DECLARES_GETPROTOBYNAME_R)
if(NETDB_H_DECLARES_GETPROTOBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct protoent protoent_buf;
char buf[1024];
struct protoent *resultp;
return getprotobyname_r((const char *)0, &protoent_buf, buf, sizeof buf, &resultp);
}
"
HAVE_LINUX_GETPROTOBYNAME_R)
if(NOT HAVE_LINUX_GETPROTOBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct protoent protoent_buf;
char buf[1024];
return getprotobyname_r((const char *)0, &protoent_buf, buf, (int)sizeof buf) != NULL;
}
"
HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
if(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
check_c_source_compiles(
"#include <netdb.h>
int
main(void)
{
struct protoent protoent_buf;
struct protoent_data proto_data;
return getprotobyname_r((const char *)0, &protoent_buf, &proto_data);
}
"
HAVE_AIX_GETPROTOBYNAME_R)
endif(NOT HAVE_SOLARIS_IRIX_GETPROTOBYNAME_R)
endif(NOT HAVE_LINUX_GETPROTOBYNAME_R)
endif(NETDB_H_DECLARES_GETPROTOBYNAME_R)
cmake_pop_check_state()
#
# Data types.
#
# XXX - there's no check_type() macro that's like check_type_size()
# except that it only checks for the existence of the structure type,
# so we use check_type_size() and ignore the size.
#
cmake_push_check_state()
if(WIN32)
set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
else(WIN32)
set(CMAKE_EXTRA_INCLUDE_FILES unistd.h sys/socket.h)
endif(WIN32)
check_type_size("struct sockaddr_storage" STRUCT_SOCKADDR_STORAGE)
check_type_size("socklen_t" SOCKLEN_T)
cmake_pop_check_state()
#
# Structure fields.
#
if(WIN32)
check_struct_has_member("struct sockaddr" sa_len winsock2.h HAVE_STRUCT_SOCKADDR_SA_LEN)
else(WIN32)
check_struct_has_member("struct sockaddr" sa_len sys/socket.h HAVE_STRUCT_SOCKADDR_SA_LEN)
endif(WIN32)
#
# Do we have ffs(), and is it declared in <strings.h>?
#
check_function_exists(ffs HAVE_FFS)
if(HAVE_FFS)
#
# OK, we have ffs(). Is it declared in <strings.h>?
#
# This test fails if we don't have <strings.h> or if we do
# but it doesn't declare ffs().
#
check_symbol_exists(ffs strings.h STRINGS_H_DECLARES_FFS)
endif()
#
# This requires the libraries that we require, as ether_hostton might be
# in one of those libraries. That means we have to do this after
# we check for those libraries.
#
# You are in a twisty little maze of UN*Xes, all different.
# Some might not have ether_hostton().
# Some might have it and declare it in <net/ethernet.h>.
# Some might have it and declare it in <netinet/ether.h>
# Some might have it and declare it in <sys/ethernet.h>.
# Some might have it and declare it in <arpa/inet.h>.
# Some might have it and declare it in <netinet/if_ether.h>.
# Some might have it and not declare it in any header file.
#
# Before you is a C compiler.
#
cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LINK_LIBRARIES})
check_function_exists(ether_hostton HAVE_ETHER_HOSTTON)
if(HAVE_ETHER_HOSTTON)
#
# OK, we have ether_hostton(). Is it declared in <net/ethernet.h>?
#
# This test fails if we don't have <net/ethernet.h> or if we do
# but it doesn't declare ether_hostton().
#
check_symbol_exists(ether_hostton net/ethernet.h NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
if(NET_ETHERNET_H_DECLARES_ETHER_HOSTTON)
#
# Yes - we have it declared.
#
set(HAVE_DECL_ETHER_HOSTTON TRUE)
endif()
#
# Did that succeed?
#
if(NOT HAVE_DECL_ETHER_HOSTTON)
#
# No - how about <netinet/ether.h>, as on Linux?
#
# This test fails if we don't have <netinet/ether.h>
# or if we do but it doesn't declare ether_hostton().
#
check_symbol_exists(ether_hostton netinet/ether.h NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
if(NETINET_ETHER_H_DECLARES_ETHER_HOSTTON)
#
# Yes - we have it declared.
#
set(HAVE_DECL_ETHER_HOSTTON TRUE)
endif()
endif()
#
# Did that succeed?
#
if(NOT HAVE_DECL_ETHER_HOSTTON)
#
# No - how about <sys/ethernet.h>, as on Solaris 10 and later?
#
# This test fails if we don't have <sys/ethernet.h>
# or if we do but it doesn't declare ether_hostton().
#
check_symbol_exists(ether_hostton sys/ethernet.h SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
if(SYS_ETHERNET_H_DECLARES_ETHER_HOSTTON)
#
# Yes - we have it declared.
#
set(HAVE_DECL_ETHER_HOSTTON TRUE)
endif()
endif()
#
# Did that succeed?
#
if(NOT HAVE_DECL_ETHER_HOSTTON)
#
# No, how about <arpa/inet.h>, as on AIX?
#
# This test fails if we don't have <arpa/inet.h>
# or if we do but it doesn't declare ether_hostton().
#
check_symbol_exists(ether_hostton arpa/inet.h ARPA_INET_H_DECLARES_ETHER_HOSTTON)
if(ARPA_INET_H_DECLARES_ETHER_HOSTTON)
#
# Yes - we have it declared.
#
set(HAVE_DECL_ETHER_HOSTTON TRUE)
endif()
endif()
#
# Did that succeed?
#
if(NOT HAVE_DECL_ETHER_HOSTTON)
#
# No, how about <netinet/if_ether.h>?
# On some platforms, it requires <net/if.h> and
# <netinet/in.h>, and we always include it with
# both of them, so test it with both of them.
#
# This test fails if we don't have <netinet/if_ether.h>
# and the headers we include before it, or if we do but
# <netinet/if_ether.h> doesn't declare ether_hostton().
#
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)
if(NETINET_IF_ETHER_H_DECLARES_ETHER_HOSTTON)
#
# Yes - we have it declared.
#
set(HAVE_DECL_ETHER_HOSTTON TRUE)
endif()
endif()
#
# After all that, is ether_hostton() declared?
#
if(NOT HAVE_DECL_ETHER_HOSTTON)
#
# No, we'll have to declare it ourselves.
# Do we have "struct ether_addr" if we include <netinet/if_ether.h>?
#
# XXX - there's no check_type() macro that's like check_type_size()
# except that it only checks for the existence of the structure type,
# so we use check_type_size() and ignore the size.
#
cmake_push_check_state()
set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h net/if.h netinet/in.h netinet/if_ether.h)
check_type_size("struct ether_addr" STRUCT_ETHER_ADDR)
cmake_pop_check_state()
endif()
endif()
cmake_pop_check_state()
#
# Large file support on UN*X, a/k/a LFS.
#
if(NOT WIN32)
include(FindLFS)
if(LFS_FOUND)
#
# Add the required #defines.
#
add_definitions(${LFS_DEFINITIONS})
endif()
#
# Check for fseeko as well.
#
include(FindFseeko)
if(FSEEKO_FOUND)
set(HAVE_FSEEKO ON)
#
# Add the required #defines.
#
add_definitions(${FSEEKO_DEFINITIONS})
endif()
endif()
if(INET6)
message(STATUS "Support IPv6")
endif(INET6)
#
# Pthreads.
# We might need them, because some libraries we use might use them,
# but we don't necessarily need them.
# That's only on UN*X; on Windows, if they use threads, we assume
# they're native Windows threads.
#
if(NOT WIN32)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads)
if(NOT CMAKE_USE_PTHREADS_INIT)
#
# If it's not pthreads, we won't use it; we use it for libraries
# that require it.
#
set(CMAKE_THREAD_LIBS_INIT "")
endif(NOT CMAKE_USE_PTHREADS_INIT)
endif(NOT WIN32)
######################################
# Input files
######################################
set(PROJECT_SOURCE_LIST_C
bpf_dump.c
bpf_filter.c
bpf_image.c
etherent.c
fmtutils.c
gencode.c
nametoaddr.c
optimize.c
pcap-common.c
pcap.c
savefile.c
sf-pcapng.c
sf-pcap.c
)
if(WIN32)
set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/win_snprintf.c)
else()
if(NOT HAVE_SNPRINTF)
set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/snprintf.c)
endif(NOT HAVE_SNPRINTF)
if(NOT HAVE_STRTOK_R)
set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} missing/strtok_r.c)
endif(NOT HAVE_STRTOK_R)
endif(WIN32)
#
# Determine the main pcap-XXX.c file to use, and the libraries with
# which we need to link libpcap, if any.
#
if(WIN32)
#
# Windows.
#
# Has the user explicitly specified a capture type?
#
if(PCAP_TYPE STREQUAL "")
#
# The user didn't explicitly specify a capture mechanism.
# Check whether we have packet.dll.
#
if(HAVE_PACKET32)
#
# We have packet.dll.
# Set the capture type to NPF.
#
set(PCAP_TYPE npf)
else()
#
# We don't have any capture type we know about, so just use
# the null capture type, and only support reading (and writing)
# capture files.
#
set(PCAP_TYPE null)
endif()
endif()
else()
#
# UN*X.
#
# Figure out what type of packet capture mechanism we have, and
# what libraries we'd need to link libpcap with, if any.
#
#
# Has the user explicitly specified a capture type?
#
if(PCAP_TYPE STREQUAL "")
#
# Check for a bunch of headers for various packet capture mechanisms.
#
check_include_files("sys/types.h;net/bpf.h" HAVE_NET_BPF_H)
if(HAVE_NET_BPF_H)
#
# Does it define BIOCSETIF?
# I.e., is it a header for an LBL/BSD-style capture
# mechanism, or is it just a header for a BPF filter
# engine? Some versions of Arch Linux, for example,
# have a net/bpf.h that doesn't define BIOCSETIF;
# as it's a Linux, it should use packet sockets,
# instead.
#
#
# We need:
#
# sys/types.h, because FreeBSD 10's net/bpf.h
# requires that various BSD-style integer types
# be defined;
#
# sys/ioctl.h and, if we have it, sys/ioccom.h,
# because net/bpf.h defines ioctls;
#
# net/if.h, because it defines some structures
# used in ioctls defined by net/bpf.h;
#
# sys/socket.h, because OpenBSD 5.9's net/bpf.h
# defines some structure fields as being
# struct sockaddrs;
#
# and net/bpf.h doesn't necessarily include all
# of those headers itself.
#
if(HAVE_SYS_IOCCOM_H)
check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;sys/ioccom.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
else(HAVE_SYS_IOCCOM_H)
check_symbol_exists(BIOCSETIF "sys/types.h;sys/ioctl.h;sys/socket.h;net/bpf.h;net/if.h" BPF_H_DEFINES_BIOCSETIF)
endif(HAVE_SYS_IOCCOM_H)
endif(HAVE_NET_BPF_H)
check_include_file(net/pfilt.h HAVE_NET_PFILT_H)
check_include_file(net/enet.h HAVE_NET_ENET_H)
check_include_file(net/nit.h HAVE_NET_NIT_H)
check_include_file(sys/net/nit.h HAVE_SYS_NET_NIT_H)
check_include_file(linux/socket.h HAVE_LINUX_SOCKET_H)
check_include_file(net/raw.h HAVE_NET_RAW_H)
check_include_file(sys/dlpi.h HAVE_SYS_DLPI_H)
if(BPF_H_DEFINES_BIOCSETIF)
#
# BPF.
# Check this before DLPI, so that we pick BPF on
# Solaris 11 and later.
#
set(PCAP_TYPE bpf)
elseif(HAVE_LINUX_SOCKET_H)
#
# No prizes for guessing this one.
#
set(PCAP_TYPE linux)
elseif(HAVE_NET_PFILT_H)
#
# DEC OSF/1, Digital UNIX, Tru64 UNIX
#
set(PCAP_TYPE pf)
elseif(HAVE_NET_ENET_H)
#
# Stanford Enetfilter.
#
set(PCAP_TYPE enet)
elseif(HAVE_NET_NIT_H)
#
# SunOS 4.x STREAMS NIT.
#
set(PCAP_TYPE snit)
elseif(HAVE_SYS_NET_NIT_H)
#
# Pre-SunOS 4.x non-STREAMS NIT.
#
set(PCAP_TYPE nit)
elseif(HAVE_NET_RAW_H)