forked from gvanem/libpcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.Windows
2104 lines (1733 loc) · 57.5 KB
/
Makefile.Windows
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
#
# libpcap Makefile for MinGW, MSVC or clang-cl (Win32/Win64).
#
# By G. Vanem <[email protected]> 2003 - 2020.
#
VPATH = Win32 missing testprogs testprogs/fuzz
THIS_FILE = Makefile.Windows
comma := ,
define Usage
Usage: "$(MAKE) -f Makefile.Windows CC=[gcc | cl | clang-cl] <CPU=x86|x64>
[all | clean | vclean | realclean | depend | install]"
endef
export Usage
#
# Build using NPcap instead of WinPcap's Packet32.c etc.
#
USE_NPCAP ?= 0
#
# Build using Win10Pcap instead of WinPcap's Packet32.c etc.
#
USE_WIN10PCAP ?= 0
#
# Options, change to suite:
#
# Set "USE_PCAP_REMOTE=1" to enable remote packet-capture.
# Also enables building 'rpcapd/rpcapd.exe'.
#
USE_PCAP_REMOTE ?= 1
#
# Enable AirPcap WiFi sniffing.
#
USE_AIRPCAP ?= 1
#
# If 'USE_AIRPCAP=1', link with it's static library?
#
USE_AIRPCAP_STATIC ?= 1
#
# Needed for the 'USE_PCAP_REMOTE = 1' and 'rpcapd/rpcapd.exe' only.
#
USE_OPENSSL ?= 1
#
# Set to 1 to build with 'WanPacket.cpp'. Since it doesn't compile with MinGW,
# we load 'WanPacket.dll' indirectly via 'Win32/WanPacket_imp.c'.
#
# But the WanPacket API stopped working in Win-8 (?)
#
USE_WANPACKET ?= 1
#
# Enable WinPcap plugin support.
#
USE_PLUGINS ?= 1
#
# Build with CACE Tech's TurboCap API.
# MSVC / clang-cl only.
#
USE_TC_API ?= 0
#
# Build with CACE Tech's DAG API. Untested since I don't have it.
#
USE_DAG_API ?= 0
#
# MinGW: no effect.
# MSVC/clang: 0: Use the Universal CRT (-MD or -MDd).
# 1: Use the static CRT (-MT or -MTd).
#
USE_CRT_STATIC ?= 0
#
# MSVC: debug-model (-MDd / -MTd) or release (-MD / -MT).
# MinGW: debug-model (-O0 -g) or release (-O2 -fomit-frame-pointer).
#
USE_CRT_DEBUG ?= 0
#
# Use Decnet's 'getnodebyname.c' in nametoaddr.c to support lookup of Decnet
# addresses in gencode.c. Little value today?
#
USE_DECNET ?= 0
#
# Use the tracing Wsock_trace lib (and not ws2_32.lib).
# Currently works best for MSVC/clang-cl.
# Ref: https://github.com/gvanem/wsock-trace/
#
USE_WSOCK_TRACE ?= 1
#
# Include trace in Packet32.c.
#
USE_PACKET32_DEBUG ?= 0
#
# Use "Visual Leak Detector" for all programs:
# https://kinddragon.github.io/vld/
# https://github.com/KindDragon/vld/
#
USE_VLD ?= 0
VLD_ROOT ?= f:/ProgramFiler/VisualLeakDetector
#
# Include 'PCAP_TRACE()' code in wpcap + rpcapd + plugins.
# Also defines 'BDEBUG' and 'YYDEBUG'.
# See below.
#
USE_PCAP_DEBUG ?= 2
#
# Option for the C/C++ preprocessing macros.
#
USE_CLANG_FORMAT ?= 1
#
# Compile for C89 (clang-cl only)
#
USE_C89_CHECK ?= 0
#
# Compile all wpcap.dll sources in one go.
# For MSVC only.
#
USE_MP_COMPILE ?= 1
ifneq ($(CC),cl)
USE_MP_COMPILE = 0
endif
ifeq ($(USE_NPCAP),1)
USE_MP_COMPILE = 0
endif
ifeq ($(CC),gcc)
USE_VLD = 0
endif
#
# Enable WinPcap-plugins:
# Build 'WinPcap-Plugins/BlueTooth' -> WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).dll
# 'WinPcap-Plugins/USB-pcap' -> WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).dll
# 'WinPcap-Plugins/Firewall' -> WinPcap-Plugins/winpcap_firewall_plugin$(X64_SUFFIX).dll (todo)
#
ifeq ($(USE_PLUGINS),1)
HAVE_BLUETOOTH = 1
HAVE_FW_MONITOR = 1
HAVE_USB_PCAP = 1
endif
#
# Python is only needed in the below '%.i' rule.
#
PYTHON ?= python
#
# WinPcap base path.
#
WINPCAP_ROOT ?= ./WinPcap
#
# NPcap base path (very experimental).
# Ref:
# https://github.com/nmap/npcap.git
#
NPCAP_ROOT ?= ./NPcap
#
# Win10Pcap base path.
#
WIN10PCAP_ROOT ?= ./Win10Pcap
#
# AirPcap base path.
#
AIRPCAP_ROOT ?= ./AirPcap
#
# Netmap's libpcap .c-file base path.
#
NETMAP_ROOT ?= ./libpcap-apps/netmap
#
# TurboCap base path.
#
TC_API_ROOT ?= 'c:/Program Files (x86)/Riverbed/TurboCap'
#
# DAG API base path.
#
DAG_API_ROOT ?= "c:/Program Files (x86)/Riverbed/DagApi"
#
# OpenSSL base path.
#
OPENSSL_ROOT ?= $(MINGW_ROOT)/src/inet/Crypto/OpenSSL
#
# USBPcap base path.
# Ref:
# https://github.com/desowin/usbpcap
#
USBPCAP_ROOT ?= $(MINGW_ROOT)/src/USB/USBPcap
#
# Where is 'netdnet/getnodebyname.c' located?
#
DECNET_ROOT = ./missing
#
# Modify above 'HAVE_x' to avoid using such features with 'gcc'.
# They won't work.!
#
ifeq ($(CC),gcc)
ifeq ($(USE_TC_API),1)
$(warning 'USE_TC_API=1' is impossible with gcc.)
USE_TC_API := 0
endif
ifeq ($(HAVE_BLUETOOTH),1)
$(warning 'HAVE_BLUETOOTH=1' is impossible with gcc.)
HAVE_BLUETOOTH := 0
endif
endif
#
# The following codes used in macro 'colour_msg' assumes you have
# MSys/Cygwin's echo with colour support.
#
BRIGHT_GREEN = \e[1;32m
BRIGHT_YELLOW = \e[1;33m
BRIGHT_WHITE = \e[1;37m
colour_msg = @echo -e "$(1)\e[0m"
yellow_msg = $(call colour_msg,$(BRIGHT_YELLOW)$(strip $(1)))
green_msg = $(call colour_msg,$(BRIGHT_GREEN)$(strip $(1)))
green_msg0 = $(call colour_msg,$(BRIGHT_GREEN)$(1))
VERSION = $(shell cat ./VERSION)
TODAY = $(shell date +%d-%B-%Y)
MINGW_ROOT = $(realpath $(MINGW32))
VC_ROOT = $(realpath $(VCToolkitInstallDir))
cpp_to_obj = $(addprefix $(OBJ_DIR)/, \
$(notdir $(1:.cpp=.$(O))))
c_to_obj = $(addprefix $(OBJ_DIR)/, \
$(notdir $(1:.c=.$(O))))
#
# Used when "force including" the Win32/config.h file on every compile.
#
ifeq ($(CC),gcc)
FORCE_INC = --include Win32/config.h
else
FORCE_INC = -FI./Win32/config.h
endif
#
# If '$(CPU)=x64', build only 64-bit .dll, libraries and programs.
# Otherwise 32-bit programs.
#
ifeq ($(CPU),)
#
# Default CPU is 'x86'.
#
CPU := x86
#
# Only 32-bit supported with clang-cl.
#
else ifeq ($(CC),clang-cl)
CPU := x86
endif
#
# GNU Make handles environment variables in a case-sensitive manner.
#
ifeq ($(CPU),X64)
BITS = 64
else ifeq ($(CPU),x64)
BITS = 64
else ifeq ($(CPU),x86)
BITS = 32
else ifeq ($(CPU),X86)
BITS = 32
else
$(error Unsupported $$(CPU)=$(CPU))
endif
ifeq ($(BITS),64)
LIB_SUBDIR = x64/
X64_SUFFIX = _64
endif
ifeq ($(CC),cl)
#
# Select correct cl.exe and link.exe based on $(CPU) without
# the 'vcvarsall.bat' non-sense.
#
# Note: This assumes you have Visual-Studio 2017 where '%VCToolkitInstallDir%'
# defines the base directory for the tools.
#
# Note: 'rc.exe' doesn't care about bitness.
#
CL_CC = $(VC_ROOT)/bin/HostX86/$(CPU)/cl.exe
CFLAGS = -nologo -Ot -W2
LDFLAGS = -nologo -map -incremental:no -verbose
RCFLAGS = -D_MSC_VER
O = obj
OBJ_DIR = MSVC_obj
else ifeq ($(CC),clang-cl)
#
# Incase '%CL' is set to e.g. '-MP', undefine it.
#
export CL=
CFLAGS = -nologo -Zi -Zo -Ot -fms-compatibility
ifeq ($(USE_C89_CHECK),1)
CFLAGS += -clang:-std=c89 -Wno-variadic-macros -Wno-comment
endif
CFLAGS += -GS- -ferror-limit=5 -Wall \
-Wno-reserved-id-macro \
-Wno-nonportable-system-include-path \
-Wno-sign-conversion \
-Wno-format-nonliteral \
-Wno-format-non-iso \
-Wno-unused-value \
-Wno-unused-variable \
-Wno-unused-macros \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-conditional-uninitialized \
-Wno-unreachable-code \
-Wno-unreachable-code-break \
-Wno-strict-prototypes \
-Wno-documentation \
-Wno-conversion \
-Wno-cast-align \
-Wno-language-extension-token \
-Wno-unreachable-code-return \
-Wno-missing-prototypes \
-Wno-cast-qual \
-Wno-nonportable-include-path \
-Wno-\#pragma-messages \
-Wno-covered-switch-default \
-Wno-missing-variable-declarations \
-Wno-used-but-marked-unused \
-Wno-switch-enum \
-Wno-extra-semi-stmt \
-Wno-implicit-fallthrough
#
# Turn off warnings like:
# ./AirPcap/include\airpcap.h(208,18):
# warning: zero size arrays are an extension [-Wzero-length-array]
# AirpcapKey Keys[0]; //< Array of nKeys keys.
#
ifeq ($(USE_AIRPCAP),1)
CFLAGS += -Wno-zero-length-array
endif
#
# The messy NPcap code generates even more warnings.
#
ifeq ($(USE_NPCAP),1)
CFLAGS += -Wno-static-in-inline \
-Wno-ignored-attributes \
-Wno-missing-field-initializers \
-Wno-zero-as-null-pointer-constant \
-Wno-c++98-compat-pedantic \
-Wno-old-style-cast \
-Wno-undef \
-Wno-comment
endif
#
# These warnings are kinda important. Leave them enabled.
#
# CFLAGS += -Wno-incompatible-pointer-types \
# -Wno-format-security \
# -Wno-pointer-sign
#
# 'CPU=x64' using 'clang-cl' is untested.
#
LDFLAGS = -nologo -map -incremental:no -verbose
RCFLAGS = -D__clang__
O = obj
OBJ_DIR = clang_obj
else ifeq ($(CC),gcc)
CFLAGS = -m$(BITS)
LDFLAGS = -m$(BITS)
RCFLAGS = -D__MINGW32__
O = o
OBJ_DIR = MinGW_obj
CFLAGS += -Wno-unused-function \
-Wno-unused-value \
-Wno-strict-aliasing \
-Wno-unknown-pragmas \
-Wno-incompatible-pointer-types
ifeq ($(BITS),64)
RCFLAGS += --target=pe-x86-64
else
RCFLAGS += --target=pe-i386
endif
else
$(error $(Usage))
endif
RCFLAGS += -I.
#
# Names of libraries and DLLs we produce:
#
ifeq ($(CC),gcc)
WPCAP_STAT_LIB = libwpcap$(X64_SUFFIX)_static.a
WPCAP2_STAT_LIB = libwpcap2$(X64_SUFFIX)_static.a
WPCAP_IMP_LIB = libwpcap$(X64_SUFFIX).a
WPCAP2_IMP_LIB = libwpcap2$(X64_SUFFIX).a
WPCAP_DLL = wpcap$(X64_SUFFIX).dll
WPCAP2_DLL = wpcap2$(X64_SUFFIX).dll
MSVC_TYPE = 0
lib_select = $(2)
sys_libs = $(addprefix -l, $(strip $(1:.lib=)))
else
WPCAP_STAT_LIB = wpcap$(X64_SUFFIX)_static.lib
WPCAP2_STAT_LIB = wpcap2$(X64_SUFFIX)_static.lib
WPCAP_IMP_LIB = wpcap$(X64_SUFFIX).lib
WPCAP2_IMP_LIB = wpcap2$(X64_SUFFIX).lib
WPCAP_DLL = wpcap$(X64_SUFFIX).dll
WPCAP2_DLL = wpcap2$(X64_SUFFIX).dll
MSVC_TYPE = 1
lib_select = $(1)
sys_libs = $(1)
endif
#
# Use the correct '-libpath' for 'cl' and 'clang-cl' targets.
#
# No need to specify the correct directory for 'link.exe' and the specific CPU since
# all (?) modern MSVC's link programs can handle both 'x86' and 'x64'.
#
ifeq ($(MSVC_TYPE),1)
#
# The paths for the CRT library (msvcrt.lib):
#
CL_LIBS = -libpath:$(VC_ROOT)/lib/$(CPU)
#
# 'WindowsKits' root is in $(WK_ROOT) and
# 'WindowsKits' version is in $(WK_VER).
#
# Hence the User-Mode libraries for 'x86' is in:
# $(WK_ROOT)/Lib/$(WK_VER)/um/x86/
#
CL_LIBS += -libpath:$(realpath $(WK_ROOT)/Lib/$(WK_VER)/um/$(CPU))
#
# Ditto mess for the UCRT libraries: for 'x86' the UCRT libs are in:
# $(WK_ROOT)/Lib/$(WK_VER)/ucrt/x86/
#
CL_LIBS += -libpath:$(realpath $(WK_ROOT)/Lib/$(WK_VER)/ucrt/$(CPU))
ifeq ($(USE_VLD),1)
CFLAGS += -Zi -DUSE_VLD -DVLD_FORCE_ENABLE -I$(VLD_ROOT)/include
LDFLAGS += -debug
CL_LIBS += $(VLD_ROOT)/lib/Win$(BITS)/vld.lib
else
#
# This causes a much faster compile and link using MSVC-2019.
# But breaks the "Visual Leak Detector".
#
CFLAGS += -Z7 -Zo
LDFLAGS += -debug:fastlink
endif
endif
###########################################################################################
ifeq ($(USE_WIN10PCAP),1)
VPATH += $(WIN10PCAP_ROOT)/Packet_dll
else ifeq ($(USE_NPCAP),1)
VPATH += $(NPCAP_ROOT)/PacketWin7/Dll \
$(NPCAP_ROOT)/PacketWin7/Helper/NPcapHelperTest
else
VPATH += $(WINPCAP_ROOT)/PacketNtx/Dll
endif
#
# $(INSTALL_BIN_DIR): Final location of wpcap2$(X64_SUFFIX).dll + rpcapd$(X64_SUFFIX).exe
# $(INSTALL_MAN3_DIR): Final location of the *.3 man-pages.
#
INSTALL_BIN_DIR = $(realpath $(SystemRoot))/System32
INSTALL_MAN3_DIR = $(MINGW_ROOT)/share/man/man3
#
# Flex/Yacc commands
#
FLEX = flex -P pcap_
YACC = bison -p pcap_
CFLAGS += -DHAVE_CONFIG_H -DHAVE_VERSION_H -I. -I./Win32 -I./missing $(FORCE_INC)
ifeq ($(USE_WIN10PCAP),1)
CFLAGS += -I$(WIN10PCAP_ROOT) -I$(WIN10PCAP_ROOT)/Packet_dll -DUSE_WIN10PCAP
ifeq ($(USE_WANPACKET),1)
CFLAGS += -I$(WINPCAP_ROOT)/PacketNtx/Dll
endif
RCFLAGS += -DUSE_WIN10PCAP
else ifeq ($(USE_NPCAP),1)
CFLAGS += -I$(NPCAP_ROOT) \
-I$(NPCAP_ROOT)/Common \
-I$(NPCAP_ROOT)/PacketWin7/Dll \
-DHAVE_PACKET_IS_LOOPBACK_ADAPTER \
-DHAVE_PACKET_GET_TIMESTAMP_MODES \
-DUSE_NPCAP \
-DNPF_NPCAP_RUN_IN_WINPCAP_MODE \
-D__STRSAFE_GCC__383773443
ifeq ($(USE_WANPACKET),1)
CFLAGS += -I$(WINPCAP_ROOT)/PacketNtx/Dll
endif
RCFLAGS += -DUSE_NPCAP
else
CFLAGS += -I$(WINPCAP_ROOT) \
-I$(WINPCAP_ROOT)/Include \
-I$(WINPCAP_ROOT)/PacketNtx/Dll
RCFLAGS += -DUSE_WINPCAP
endif
ifeq ($(CC),gcc)
#
# Since some functions prototypes conflicts with those in the Win-SDK 8.0+,
# we must pretend we're on Win-XP.
#
ifeq ($(USE_WIN10PCAP),0)
#
# For '#include <strsafe.h>'
#
CFLAGS += -I$(WINPCAP_ROOT)/Include/MinGW -D__STRSAFE_GCC__383773443
endif
CFLAGS += -DEAFNOSUPPORT=WSAEAFNOSUPPORT
endif
#
# The targets with the '2' suffix are combinations of traditional
# libpcap + WinPcap + AirPcap.
#
TARGETS = $(WPCAP_DLL) $(WPCAP2_DLL) $(WPCAP_STAT_LIB) $(WPCAP2_STAT_LIB) $(WPCAP_IMP_LIB) $(WPCAP2_IMP_LIB)
#
# BIN_TARGETS: Targets that should be copied to $(INSTALL_BIN_DIR):
# LINK_CRAP: Files to delete on 'make realclean':
#
BIN_TARGETS = $(WPCAP_DLL) $(WPCAP2_DLL)
LINK_CRAP = $(WPCAP_DLL:.dll=.map) $(WPCAP2_DLL:.dll=.map)
ifeq ($(MSVC_TYPE),1)
BIN_TARGETS += $(WPCAP_DLL:.dll=.pdb) $(WPCAP2_DLL:.dll=.pdb)
LINK_CRAP += $(WPCAP_DLL:.dll=.pdb) $(WPCAP2_DLL:.dll=.pdb) vc1*.pdb
endif
ifeq ($(USE_NPCAP),1)
TARGETS += NpcapHelperTest.exe
BIN_TARGETS += NpcapHelperTest.pdb
LINK_CRAP += NpcapHelperTest.pdb
$(OBJ_DIR)/NpcapHelperTest.$(O) \
NpcapHelperTest.i: EXTRA_CFLAGS += -DCOMPILING_NPCAPHELPERTEST_C
ifeq ($(CC),clang-cl)
$(OBJ_DIR)/NpcapHelperTest.$(O) \
NpcapHelperTest.i: EXTRA_CFLAGS += -Wno-format -Wno-bad-function-cast
endif
endif
WPCAP_SRC = bpf_dump.c \
bpf_filter.c \
bpf_image.c \
charconv.c \
etherent.c \
fmtutils.c \
scanner.c \
grammar.c \
gencode.c \
nametoaddr.c \
optimize.c \
pcap.c \
pcap-common.c \
pcap-npf.c \
pcap-namedb.c \
savefile.c \
sf-pcap.c \
sf-pcapng.c \
missing/win_asprintf.c
#
# Don't add this for MSVC/clang since 'strtok_r' is a macro in 'portability.h'.
#
ifeq ($(CC),gcc)
WPCAP_SRC += missing/strtok_r.c
endif
#
# Which Packet32 sources to use?
#
ifeq ($(USE_WIN10PCAP),1)
FEATURES += "Win10Pcap by Daiyuu Nobori, "
PACKET32_C_SRC = $(addprefix $(WIN10PCAP_ROOT)/Packet_dll/, \
Ms.c \
NdisDriverUser.c \
Packet32.c \
SeMemory.c \
SeStr.c) \
Win32/Win10pcap_hack.c
else ifeq ($(USE_NPCAP),1)
FEATURES += "NPcap by Yang Luo, "
#
# All these must be compiled as UNICODE.
#
PACKET32_CPP_SRC = $(addprefix $(NPCAP_ROOT)/PacketWin7/Dll/, \
AdInfo.cpp \
Packet32.cpp \
ProtInstall.cpp \
netcfgapi.cpp)
else
PACKET32_C_SRC = $(addprefix $(WINPCAP_ROOT)/PacketNtx/Dll/, \
Packet32.c \
AdInfo.c)
endif
ifeq ($(CC),gcc)
ifeq ($(USE_CRT_DEBUG),1)
CFLAGS += -O0 -gcoff
else
CFLAGS += -O2 -ffast-math -fomit-frame-pointer
endif
else
ifeq ($(USE_CRT_STATIC),1)
CRT = MT
else
CRT = MD
endif
ifeq ($(USE_CRT_DEBUG),1)
FEATURES += "Debug build,"
D = d
else
FEATURES += "Release build,"
CFLAGS += -DNDEBUG
D =
endif
CFLAGS += -$(CRT)$(D)
endif
ifeq ($(USE_PACKET32_DEBUG),1)
FEATURES += "Packet32.c tracing,"
CFLAGS += -D_DEBUG_TO_FILE
endif
#
# If '$(USE_PCAP_DEBUG)=1 or = 2':
#
# 1) Enable debug-code in optimize.c and testprogs/filtertest.c ('-DBDEBUG').
#
# 2) Enable more verbose debug-code in grammar.c ('-DYYDEBUG=1')
# when $(USE_PCAP_DEBUG) == 2.
#
# 3) Enables the 'PCAP_TRACE()' macro in "pcap-trace.h" thus
# activating trace-code in pcap-trace.c and the plugins
# in 'WinPcap-plugins/*.c'.
#
ifeq ($(USE_PCAP_DEBUG),1)
FEATURES += "PCAP_DEBUG=1,"
CFLAGS += -DBDEBUG \
-DUSE_PCAP_TRACE \
-DPCAP_DEBUG=1
WPCAP_SRC += pcap-trace.c
RPCAPD_SRC += pcap-trace.c
else ifeq ($(USE_PCAP_DEBUG),2)
FEATURES += "YYDEBUG,"
CFLAGS += -DBDEBUG \
-DUSE_PCAP_TRACE \
-DYYDEBUG=1
WPCAP_SRC += pcap-trace.c
RPCAPD_SRC += pcap-trace.c
endif
ifeq ($(USE_AIRPCAP),1)
FEATURES += "AirPcap,"
WPCAP_SRC += pcap-airpcap.c
CFLAGS += -DHAVE_AIRPCAP -DHAVE_AIRPCAP_API -I$(AIRPCAP_ROOT)/include
ifeq ($(USE_AIRPCAP_STATIC),1)
CFLAGS += -DPCAP_USE_STATIC_AIRPCAP
AIRPCAP_LIB = $(AIRPCAP_ROOT)/lib/airpcap_static.lib
endif
endif
ifeq ($(USE_DAG_API),1)
FEATURES += "Dag API,"
CFLAGS += -DHAVE_DAG_API -I$(DAG_API_ROOT)/include
endif
ifeq ($(USE_PLUGINS),1)
FEATURES += "Plug-in support,"
VPATH += WinPcap-Plugins WinPcap-Plugins/example
CFLAGS += -DPCAP_SUPPORT_PLUGINS -I./WinPcap-Plugins
PLUGIN_SRC += WinPcap-Plugins/example/example_plugin.c
WPCAP_SRC += WinPcap-Plugins/pcap-plugin.c
TARGETS += WinPcap-Plugins/winpcap_example_plugin$(X64_SUFFIX).dll
BIN_TARGETS += WinPcap-Plugins/winpcap_example_plugin$(X64_SUFFIX).dll
LINK_CRAP += WinPcap-Plugins/winpcap_example_plugin$(X64_SUFFIX).map
ifeq ($(MSVC_TYPE),1)
BIN_TARGETS += WinPcap-Plugins/winpcap_example_plugin$(X64_SUFFIX).pdb
LINK_CRAP += WinPcap-Plugins/winpcap_example_plugin$(X64_SUFFIX).pdb
endif
#
# Currently MSVC/clang-cl only:
# Win-Vista is required to link and use
# winpcap_btooth_plugin$(X64_SUFFIX).dll
#
ifeq ($(HAVE_BLUETOOTH),1)
FEATURES += "BlueTooth plug-in,"
CFLAGS += -DHAVE_BLUETOOTH
VPATH += WinPcap-Plugins/Bluetooth
PLUGIN_SRC += WinPcap-Plugins/BlueTooth/win_btooth.c
TARGETS += WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).dll
BIN_TARGETS += WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).dll
LINK_CRAP += WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).map
ifeq ($(MSVC_TYPE),1)
BIN_TARGETS += WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).pdb
LINK_CRAP += WinPcap-Plugins/winpcap_btooth_plugin$(X64_SUFFIX).pdb
endif
endif
ifeq ($(HAVE_USB_PCAP),1)
CFLAGS += -DHAVE_USB_PCAP -I$(USBPCAP_ROOT)/USBPcapDriver/include
FEATURES += "USBPcap plug-in,"
VPATH += WinPcap-Plugins/USB-pcap
PLUGIN_SRC += $(addprefix WinPcap-Plugins/USB-pcap/, \
enum.c \
filters.c \
roothubs.c \
thread.c \
win_usbpcap.c)
TARGETS += WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).dll
BIN_TARGETS += WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).dll
LINK_CRAP += WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).map
ifeq ($(MSVC_TYPE),1)
BIN_TARGETS += WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).pdb
LINK_CRAP += WinPcap-Plugins/winpcap_usb_plugin$(X64_SUFFIX).pdb
endif
endif
else
#
# If 'HAVE_PLUGIN=0' delete these on a 'make vclean' anyway.
#
LINK_CRAP += WinPcap-Plugins/winpcap_*.map \
WinPcap-Plugins/winpcap_*.pdb
endif
ifeq ($(USE_PCAP_REMOTE),1)
FEATURES += "Remote capture,"
VPATH += rpcapd
CFLAGS += -DLIBPCAP_REMOTE -DENABLE_REMOTE
RCFLAGS += -I./rpcapd
PACKET32_C_SRC += pcap-new.c pcap-rpcap.c sockutils.c rpcap-protocol.c
WPCAP_SRC += pcap-new.c pcap-rpcap.c sockutils.c rpcap-protocol.c
TARGETS += rpcapd/rpcapd$(X64_SUFFIX).exe
BIN_TARGETS += rpcapd/rpcapd$(X64_SUFFIX).exe
LINK_CRAP += rpcapd/rpcapd$(X64_SUFFIX).map
ifeq ($(MSVC_TYPE),1)
BIN_TARGETS += rpcapd/rpcapd$(X64_SUFFIX).pdb
LINK_CRAP += rpcapd/rpcapd$(X64_SUFFIX).pdb
endif
ifeq ($(USE_OPENSSL),1)
CFLAGS += -DHAVE_OPENSSL -I$(OPENSSL_ROOT)/include
WPCAP_SRC += sslutils.c
PACKET32_C_SRC += sslutils.c
EX_LIBS += $(call lib_select, $(OPENSSL_ROOT)/lib$(BITS)/libcrypto_imp.lib \
$(OPENSSL_ROOT)/lib$(BITS)/libssl_imp.lib, \
$(OPENSSL_ROOT)/lib$(BITS)/libcrypto.dll.a \
$(OPENSSL_ROOT)/lib$(BITS)/libssl.dll.a)
endif
RPCAPD_SRC += $(addprefix rpcapd/, \
rpcapd.c \
daemon.c \
fileconf.c \
log.c \
win32-svc.c)
RPCAPD_SRC += sslutils.c \
missing/getopt.c
#
# These .c-files are in $(WPCAP_STAT_LIB) if it was built with
# 'ENABLE_REMOTE' I.e. 'USE_PCAP_REMOTE = 1.
#
# But if we use the $(WPCAP_IMP_LIB) library, the functions in those files
# are not exported. Hence we must add the .$(O)-files when linking 'rpcapd.exe'
#
# An alternative would be to use a generated .def-files and add 'EXPORTS'
# for these functions too (as I do for functions in 'wpcap2.dll').
#
RPCAPD_SRC += charconv.c \
fmtutils.c \
rpcap-protocol.c \
sockutils.c
RPCAPD_OBJ = $(call c_to_obj, $(RPCAPD_SRC))
RPCAPD_I = $(notdir $(RPCAPD_SRC:.c=.i))
#
# Extra CFLAGS for building 'rpcapd/rpcapd.exe'.
#
$(RPCAPD_OBJ) $(RPCAPD_I): EXTRA_CFLAGS += -DCOMPILING_RPCAPD_CODE -DPCAP_DLL
#
# We should possibly build the rpcap client DLL+program too?
# Ref files in ./libpcap-apps/rpcap-0.23
#
# Or build 'rpcap' into WinPcap as a plugin?
#
endif
ifeq ($(USE_TC_API),1)
FEATURES += "TurboCap,"
WPCAP_SRC += pcap-tc.c
CFLAGS += -DHAVE_TC_API -I$(TC_API_ROOT)/devpack/include
endif
ifeq ($(USE_WANPACKET),1)
FEATURES += "WAN support,"
CFLAGS += -DHAVE_WANPACKET_API
PACKET32_C_SRC += Win32/WanPacket_imp.c
endif
ifeq ($(USE_DECNET),1)
FEATURES += "Decnet names,"
VPATH += $(DECNET_ROOT)/netdnet
CFLAGS += -DDECNETLIB -I$(DECNET_ROOT)
WPCAP_SRC += $(DECNET_ROOT)/netdnet/getnodebyname.c
endif
MAN3_PAGES = $(wildcard *.3pcap.in) \
$(wildcard *.3pcap)
MAN3_PAGES := $(MAN3_PAGES:.3pcap.in=.3pcap)
MAN3_PAGES := $(addprefix doc/, $(MAN3_PAGES:.3pcap=.3) pcap-savefile.3)
MAN3_PAGES += $(addprefix doc/, pcap-filter.3 pcap-linktype.3 pcap-tstamp.3)
#
# Generated from 'rpcapd/rpcapd-config.manfile.in':
#
MAN3_PAGES += doc/rpcapd-config.3 \
doc/rpcapd.3
TARGETS += $(MAN3_PAGES)
#
# At minimum, we need these external Windows libs:
#
EX_LIBS += $(call lib_select, \
version.lib advapi32.lib iphlpapi.lib, \
-lversion -ladvapi32 -liphlpapi)
#
# Not needed for MinGW
#
EX_LIBS += $(call lib_select, user32.lib,)
ifeq ($(CC),gcc)
EX_LIBS += -lws2_32
else ifeq ($(USE_WSOCK_TRACE),1)
#
# These MUST be in %LIB%-path.
#
ifeq ($(BITS),64)
EX_LIBS += wsock_trace_x64.lib
else
EX_LIBS += wsock_trace.lib
endif
else
EX_LIBS += ws2_32.lib
endif
ifeq ($(USE_NPCAP),1)
EX_LIBS += $(call lib_select, shell32.lib shlwapi.lib setupapi.lib, -lshlwapi -lsetupapi)
else ifeq ($(USE_WIN10PCAP),1)
EX_LIBS += $(call lib_select, winmm.lib, -lwinmm)
endif
#
# And now the 'Packet.lib / libpacket.a' messy stuff.
#
ifeq ($(MSVC_TYPE),1)
ifeq ($(USE_WIN10PCAP),1)
#
# This is a static-library for Win10Pcap's Packet code.
#
PACKET_LIB = $(WIN10PCAP_ROOT)/Packet_dll/Packet$(X64_SUFFIX).lib
else ifeq ($(USE_NPCAP),1)
#
# Since NPcap has no Packet.lib to link to, we use the extra .$(O)-files.
#
PACKET_LIB =
else
#
# This is an *import* library for CACE Tech's (Riverbed's) Packet.dll.
#
PACKET_LIB = $(WINPCAP_ROOT)/lib/$(LIB_SUBDIR)Packet.lib
endif
else ifeq ($(CC),gcc)
#
# This is an *import* library for CACE Tech's (Riverbed's) Packet.dll.
#
# To create this (in case it doesn't exist), do:
# cd $(WINPCAP_ROOT)\PacketNtx\Dll\Project
# make CC="gcc -m32"
# make CC="gcc -m64"
#
PACKET_LIB = $(WINPCAP_ROOT)/lib/$(LIB_SUBDIR)libpacket.a
endif
#
# Put config.h under Win32 so that programs using libpcap is less
# likely to pick up the wrong "config.h" file.
#
GENERATED = Win32/config.h grammar.y grammar.c grammar.h scanner.c scanner.h $(CC).args