xref: /freebsd/contrib/libpcap/doc/README.windows.md (revision afdbf109c6a661a729938f68211054a0a50d38ac)
1*afdbf109SJoseph MingroneBuilding libpcap on Windows with Visual Studio
2*afdbf109SJoseph Mingrone==============================================
3*afdbf109SJoseph Mingrone
4*afdbf109SJoseph MingroneUnlike the UN*Xes on which libpcap can capture network traffic, Windows
5*afdbf109SJoseph Mingronehas no network traffic capture mechanism that libpcap can use.
6*afdbf109SJoseph MingroneTherefore, libpcap requires a driver, and a library to access the
7*afdbf109SJoseph Mingronedriver, provided by the Npcap or WinPcap projects.
8*afdbf109SJoseph Mingrone
9*afdbf109SJoseph MingroneThose projects include versions of libpcap built to use that driver and
10*afdbf109SJoseph Mingronelibrary; these instructions are for people who want to build libpcap
11*afdbf109SJoseph Mingronesource releases, or libpcap from the Git repository, as a replacement
12*afdbf109SJoseph Mingronefor the version provided with Npcap or WinPcap.
13*afdbf109SJoseph Mingrone
14*afdbf109SJoseph MingroneNpcap and WinPcap SDK
15*afdbf109SJoseph Mingrone---------------------
16*afdbf109SJoseph Mingrone
17*afdbf109SJoseph MingroneIn order to build libpcap, you will need to download Npcap and its
18*afdbf109SJoseph Mingronesoftware development kit (SDK) or WinPcap and its software development
19*afdbf109SJoseph Mingronekit.
20*afdbf109SJoseph Mingrone
21*afdbf109SJoseph MingroneNpcap is currently being developed and maintained, and offers many
22*afdbf109SJoseph Mingroneadditional capabilities that WinPcap does not.
23*afdbf109SJoseph Mingrone
24*afdbf109SJoseph MingroneWinPcap is no longer being developed or maintained; it should be used
25*afdbf109SJoseph Mingroneonly if there is some other requirement to use it rather than Npcap,
26*afdbf109SJoseph Mingronesuch as a requirement to support versions of Windows earlier than
27*afdbf109SJoseph MingroneWindows Vista, which is the earliest version supported by Npcap.
28*afdbf109SJoseph Mingrone
29*afdbf109SJoseph MingroneNpcap and its SDK can be downloaded from its home page:
30*afdbf109SJoseph Mingrone
31*afdbf109SJoseph Mingrone  https://npcap.com
32*afdbf109SJoseph Mingrone
33*afdbf109SJoseph MingroneThe SDK is a ZIP archive; create a folder on your C: drive, e.g.
34*afdbf109SJoseph MingroneC:\npcap-sdk, and put the contents of the ZIP archive into that folder.
35*afdbf109SJoseph Mingrone
36*afdbf109SJoseph MingroneThe WinPcap installer can be downloaded from
37*afdbf109SJoseph Mingrone
38*afdbf109SJoseph Mingrone  https://www.winpcap.org/install/default.htm
39*afdbf109SJoseph Mingrone
40*afdbf109SJoseph Mingroneand the WinPcap Developer's Kit can be downloaded from
41*afdbf109SJoseph Mingrone
42*afdbf109SJoseph Mingrone  https://www.winpcap.org/devel.htm
43*afdbf109SJoseph Mingrone
44*afdbf109SJoseph MingroneRequired build tools
45*afdbf109SJoseph Mingrone--------------------
46*afdbf109SJoseph Mingrone
47*afdbf109SJoseph MingroneThe Developer's Kit is a ZIP archive; it contains a folder named
48*afdbf109SJoseph MingroneWpdPack, which you should place on your C: drive, e.g. C:\WpdPack.
49*afdbf109SJoseph Mingrone
50*afdbf109SJoseph MingroneBuilding libpcap on Windows requires Visual Studio 2015 or later.  The
51*afdbf109SJoseph MingroneCommunity Edition of Visual Studio can be downloaded at no cost from
52*afdbf109SJoseph Mingrone
53*afdbf109SJoseph Mingrone  https://visualstudio.microsoft.com
54*afdbf109SJoseph Mingrone
55*afdbf109SJoseph MingroneAdditional tools are also required.  Chocolatey is a package manager for
56*afdbf109SJoseph MingroneWindows with which those tools, and other tools, can be installed; it
57*afdbf109SJoseph Mingronecan be downloaded from
58*afdbf109SJoseph Mingrone
59*afdbf109SJoseph Mingrone  https://chocolatey.org
60*afdbf109SJoseph Mingrone
61*afdbf109SJoseph MingroneIt is a command-line tool; a GUI tool, Chocolatey GUI, is provided as a
62*afdbf109SJoseph MingroneChocolatey package, which can be installed from the command line:
63*afdbf109SJoseph Mingrone
64*afdbf109SJoseph Mingrone	choco install chocolateygui
65*afdbf109SJoseph Mingrone
66*afdbf109SJoseph MingroneFor convenience, the "choco install" command can be run with the "-y"
67*afdbf109SJoseph Mingroneflag, forcing it to automatically answer all questions asked of the user
68*afdbf109SJoseph Mingronewith "yes":
69*afdbf109SJoseph Mingrone
70*afdbf109SJoseph Mingrone	choco install -y chocolateygui
71*afdbf109SJoseph Mingrone
72*afdbf109SJoseph MingroneThe required tools are:
73*afdbf109SJoseph Mingrone
74*afdbf109SJoseph Mingrone### CMake ###
75*afdbf109SJoseph Mingrone
76*afdbf109SJoseph Mingronelibpcap does not provide supported project files for Visual Studio
77*afdbf109SJoseph Mingrone(there are currently unsupported project files provided, but we do not
78*afdbf109SJoseph Mingroneguarantee that they will work or that we will continue to provide them).
79*afdbf109SJoseph MingroneIt does provide files for CMake, which is a cross-platform tool that
80*afdbf109SJoseph Mingroneruns on UN*Xes and on Windows and that can generate project files for
81*afdbf109SJoseph MingroneUN*X Make, the Ninja build system, and Visual Studio, among other build
82*afdbf109SJoseph Mingronesystems.
83*afdbf109SJoseph Mingrone
84*afdbf109SJoseph MingroneVisual Studio 2015 does not provide CMake; an installer can be
85*afdbf109SJoseph Mingronedownloaded from
86*afdbf109SJoseph Mingrone
87*afdbf109SJoseph Mingrone  https://cmake.org/download/
88*afdbf109SJoseph Mingrone
89*afdbf109SJoseph MingroneWhen you run the installer, you should choose to add CMake to the system
90*afdbf109SJoseph MingronePATH for all users and to create the desktop icon.
91*afdbf109SJoseph Mingrone
92*afdbf109SJoseph MingroneCMake can also be installed as the Chocolatey package "cmake":
93*afdbf109SJoseph Mingrone
94*afdbf109SJoseph Mingrone	choco install -y cmake
95*afdbf109SJoseph Mingrone
96*afdbf109SJoseph MingroneVisual Studio 2017 and later provide CMake, so you will not need to
97*afdbf109SJoseph Mingroneinstall CMake if you have installed Visual Studio 2017 or later.  They
98*afdbf109SJoseph Mingroneinclude built-in support for CMake-based projects:
99*afdbf109SJoseph Mingrone
100*afdbf109SJoseph Mingrone  https://devblogs.microsoft.com/cppblog/cmake-support-in-visual-studio/
101*afdbf109SJoseph Mingrone
102*afdbf109SJoseph MingroneFor Visual Studio 2017, make sure "Visual C++ tools for CMake" is
103*afdbf109SJoseph Mingroneinstalled; for Visual Studio 2019, make sure "C++ CMake tools for
104*afdbf109SJoseph MingroneWindows" is installed.
105*afdbf109SJoseph Mingrone
106*afdbf109SJoseph Mingrone### winflexbison ###
107*afdbf109SJoseph Mingrone
108*afdbf109SJoseph Mingronelibpcap uses the Flex lexical-analyzer generator and the Bison or
109*afdbf109SJoseph MingroneBerkeley YACC parser generators to generate the parser for filter
110*afdbf109SJoseph Mingroneexpressions.  Windows versions of Flex and Bison can be downloaded from
111*afdbf109SJoseph Mingrone
112*afdbf109SJoseph Mingrone  https://sourceforge.net/projects/winflexbison/
113*afdbf109SJoseph Mingrone
114*afdbf109SJoseph MingroneThe downloaded file is a ZIP archive; create a folder on your C: drive,
115*afdbf109SJoseph Mingronee.g. C:\Program Files\winflexbison, and put the contents of the ZIP
116*afdbf109SJoseph Mingronearchive into that folder.  Then add that folder to the system PATH
117*afdbf109SJoseph Mingroneenvironment variable.
118*afdbf109SJoseph Mingrone
119*afdbf109SJoseph MingroneGit
120*afdbf109SJoseph Mingrone---
121*afdbf109SJoseph Mingrone
122*afdbf109SJoseph MingroneAn optional tool, required only if you will be building from a Git
123*afdbf109SJoseph Mingronerepository rather than from a release source tarball, is Git.  Git is
124*afdbf109SJoseph Mingroneprovided as an optional installation component, "Git for Windows", with
125*afdbf109SJoseph MingroneVisual Studio 2017 and later.
126*afdbf109SJoseph Mingrone
127*afdbf109SJoseph MingroneBuilding from the Visual Studio GUI
128*afdbf109SJoseph Mingrone-----------------------------------
129*afdbf109SJoseph Mingrone
130*afdbf109SJoseph Mingrone### Visual Studio 2017 ###
131*afdbf109SJoseph Mingrone
132*afdbf109SJoseph MingroneOpen the folder containing the libpcap source with Open > Folder.
133*afdbf109SJoseph MingroneVisual Studio will run CMake; however, you will need to indicate where
134*afdbf109SJoseph Mingronethe Npcap or WinPcap SDK is installed.
135*afdbf109SJoseph Mingrone
136*afdbf109SJoseph MingroneTo do this, go to Project > "Change CMake Settings" > pcap and:
137*afdbf109SJoseph Mingrone
138*afdbf109SJoseph MingroneChoose which configuration type to build, if you don't want the default
139*afdbf109SJoseph MingroneDebug build.
140*afdbf109SJoseph Mingrone
141*afdbf109SJoseph MingroneIn the CMakeSettings.json tab, change cmakeCommandArgs to include
142*afdbf109SJoseph Mingrone
143*afdbf109SJoseph Mingrone	-DPacket_ROOT={path-to-sdk}
144*afdbf109SJoseph Mingrone
145*afdbf109SJoseph Mingronewhere {path-to-sdk} is the path of the directory containing the Npcap or
146*afdbf109SJoseph MingroneWinPcap SDK.  Note that backslashes in the path must be specified as two
147*afdbf109SJoseph Mingronebackslashes.
148*afdbf109SJoseph Mingrone
149*afdbf109SJoseph MingroneSave the configuration changes with File > "Save CMakeSettings.json" or
150*afdbf109SJoseph Mingronewith control-S.
151*afdbf109SJoseph Mingrone
152*afdbf109SJoseph MingroneVisual Studio will then re-run CMake.  If that completes without errors,
153*afdbf109SJoseph Mingroneyou can build with CMake > "Build All".
154*afdbf109SJoseph Mingrone
155*afdbf109SJoseph Mingrone### Visual Studio 2019 ###
156*afdbf109SJoseph Mingrone
157*afdbf109SJoseph MingroneOpen the folder containing the libpcap source with Open > Folder.
158*afdbf109SJoseph MingroneVisual Studio will run CMake; however, you will need to indicate where
159*afdbf109SJoseph Mingronethe Npcap or WinPcap SDK is installed.
160*afdbf109SJoseph Mingrone
161*afdbf109SJoseph MingroneTo do this, go to Project > "CMake Settings for pcap" and:
162*afdbf109SJoseph Mingrone
163*afdbf109SJoseph MingroneChoose which configuration type to build, if you don't want the default
164*afdbf109SJoseph MingroneDebug build.
165*afdbf109SJoseph Mingrone
166*afdbf109SJoseph MingroneScroll down to "Cmake variables and cache", scroll through the list
167*afdbf109SJoseph Mingronelooking for the entry for Packet_ROOT, and either type in the path of
168*afdbf109SJoseph Mingronethe directory containing the Npcap or WinPcap SDK or use the "Browse..."
169*afdbf109SJoseph Mingronebutton to browse for that directory.
170*afdbf109SJoseph Mingrone
171*afdbf109SJoseph MingroneSave the configuration changes with File > "Save CMakeSettings.json" or
172*afdbf109SJoseph Mingronewith control-S.
173*afdbf109SJoseph Mingrone
174*afdbf109SJoseph MingroneVisual Studio will then re-run CMake.  If that completes without errors,
175*afdbf109SJoseph Mingroneyou can build with Build > "Build All".
176*afdbf109SJoseph Mingrone
177*afdbf109SJoseph MingroneBuilding from the command line
178*afdbf109SJoseph Mingrone------------------------------
179*afdbf109SJoseph Mingrone
180*afdbf109SJoseph MingroneStart the appropriate Native Tools command line prompt.
181*afdbf109SJoseph Mingrone
182*afdbf109SJoseph MingroneChange to the directory into which you want to build libpcap, possibly
183*afdbf109SJoseph Mingroneafter creating it first.  One choice is to create it as a subdirectory
184*afdbf109SJoseph Mingroneof the libpcap source directory.
185*afdbf109SJoseph Mingrone
186*afdbf109SJoseph MingroneRun the command
187*afdbf109SJoseph Mingrone
188*afdbf109SJoseph Mingrone	cmake "-DPacket_ROOT={path-to-sdk}" {path-to-libpcap-source}
189*afdbf109SJoseph Mingrone
190*afdbf109SJoseph Mingronewhere {path-to-sdk} is the path of the directory containing the Npcap or
191*afdbf109SJoseph MingroneWinPcap SDK and {path-to-libpcap-source} is the pathname of the
192*afdbf109SJoseph Mingronetop-level source directory for libpcap.
193*afdbf109SJoseph Mingrone
194*afdbf109SJoseph MingroneRun the command
195*afdbf109SJoseph Mingrone
196*afdbf109SJoseph Mingrone	msbuild/m pcap.sln
197*afdbf109SJoseph Mingrone
198*afdbf109SJoseph Mingroneto compile libpcap.
199