]> The Tcpdump Group git mirrors - tcpdump/blob - doc/README.Win32.md
Merge pull request #827 from NanXiao/patch-1
[tcpdump] / doc / README.Win32.md
1 Building tcpdump on Windows with Visual Studio
2 ==============================================
3
4 Unlike the UN*Xes on which libpcap can capture network traffic, Windows
5 has no network traffic capture mechanism that libpcap can use.
6 Therefore, libpcap requires a driver, and a library to access the
7 driver, provided by the Npcap or WinPcap projects.
8
9 Those projects include versions of libpcap built to use that driver and
10 library; these instructions are for people who want to build libpcap
11 source releases, or libpcap from the Git repository, as a replacement
12 for the version provided with Npcap or WinPcap.
13
14 Npcap and WinPcap SDK
15 ---------------------
16
17 In order to build tcpdump, you will need to download Npcap and its
18 software development kit (SDK) or WinPcap and its software development
19 kit.
20
21 Npcap is currently being developed and maintained, and offers many
22 additional capabilities that WinPcap does not.
23
24 WinPcap is no longer being developed or maintained; it should be used
25 only if there is some other requirement to use it rather than Npcap,
26 such as a requirement to support versions of Windows earlier than
27 Windows Vista, which is the earliest version supported by Npcap.
28
29 Npcap and its SDK can be downloaded from its home page:
30
31 https://npcap.org
32
33 The SDK is a ZIP archive; create a folder on your C: drive, e.g.
34 C:\npcap-sdk, and put the contents of the ZIP archive into that folder.
35
36 The WinPcap installer can be downloaded from
37
38 https://www.winpcap.org/install/default.htm
39
40 and the WinPcap Developer's Kit can be downloaded from
41
42 https://www.winpcap.org/devel.htm
43
44 Required build tools
45 --------------------
46
47 The Developer's Kit is a ZIP archive; it contains a folder named
48 WpdPack, which you should place on your C: drive, e.g. C:\WpdPack.
49
50 Building tcpdumpp on Windows requires Visual Studio 2015 or later. The
51 Community Edition of Visual Studio can be downloaded at no cost from
52
53 https://visualstudio.microsoft.com
54
55 Additional tools are also required. Chocolatey is a package manager for
56 Windows with which those tools, and other tools, can be installed; it
57 can be downloaded from
58
59 https://chocolatey.org
60
61 It is a command-line tool; a GUI tool, Chocolatey GUI, is provided as a
62 Chocolatey package, which can be installed from the command line:
63
64 choco install chocolateygui
65
66 For convenience, the "choco install" command can be run with the "-y"
67 flag, forcing it to automatically answer all questions asked of the user
68 with "yes":
69
70 choco install -y chocolateygui
71
72 The required tools are:
73
74 ### CMake ###
75
76 libpcap does not provide supported project files for Visual Studio
77 (there are currently unsupported project files provided, but we do not
78 guarantee that they will work or that we will continue to provide them).
79 It does provide files for CMake, which is a cross-platform tool that
80 runs on UN*Xes and on Windows and that can generate project files for
81 UN*X Make, the Ninja build system, and Visual Studio, among other build
82 systems.
83
84 Visual Studio 2015 does not provide CMake; an installer can be
85 downloaded from
86
87 https://cmake.org/download/
88
89 When you run the installer, you should choose to add CMake to the system
90 PATH for all users and to create the desktop icon.
91
92 CMake can also be installed as the Chocolatey package "cmake":
93
94 choco install -y cmake
95
96 Visual Studio 2017 and later provide CMake, so you will not need to
97 install CMake if you have installed Visual Studio 2017 or later. They
98 include built-in support for CMake-based projects:
99
100 https://devblogs.microsoft.com/cppblog/cmake-support-in-visual-studio/
101
102 For Visual Studio 2017, make sure "Visual C++ tools for CMake" is
103 installed; for Visual Studio 2019, make sure "C++ CMake tools for
104 Windows" is intalled.
105
106 Git
107 ---
108
109 An optional tool, required only if you will be building from a Git
110 repository rather than from a release source tarball, is Git. Git is
111 provided as an optional installation component, "Git for Windows", with
112 Visual Studio 2017 and later.
113
114 Building from the Visual Studio GUI
115 -----------------------------------
116
117 ### Visual Studio 2017 ###
118
119 Open the folder containing the libpcap source with Open > Folder.
120 Visual Studio will run CMake; however, you will need to indicate where
121 the Npcap or WinPcap SDK is installed.
122
123 To do this, go to Project > "Change CMake Settings" > tcpdump and:
124
125 Choose which configuration type to build, if you don't want the default
126 Debug build.
127
128 In the CMakeSettings.json tab, change cmakeCommandArgs to include
129
130 -DPacket_ROOT={path-to-sdk}
131
132 where {path-to-sdk} is the path of the directory containing the Npcap or
133 WinPcap SDK. Note that backslashes in the path must be specified as two
134 backslashes.
135
136 Save the configuration changes with File > "Save CMakeSettings.json" or
137 with control-S.
138
139 Visual Studio will then re-run CMake. If that completes without errors,
140 you can build with CMake > "Build All".
141
142 ### Visual Studio 2019 ###
143
144 Open the folder containing the libpcap source with Open > Folder.
145 Visual Studio will run CMake; however, you will need to indicate where
146 the Npcap or WinPcap SDK is installed.
147
148 To do this, go to Project > "CMake Settings for tcpdump" and:
149
150 Choose which configuration type to build, if you don't want the default
151 Debug build.
152
153 Scroll down to "Cmake variables and cache", scroll through the list
154 looking for the entry for Packet_ROOT, and either type in the path of
155 the directory containing the Npcap or WinPcap SDK or use the "Browse..."
156 button to browse for that directory.
157
158 Save the configuration changes with File > "Save CMakeSettings.json" or
159 with control-S.
160
161 Visual Studio will then re-run CMake. If that completes without errors,
162 you can build with Build > "Build All".
163
164 Building from the command line
165 ------------------------------
166
167 Start the appropriate Native Tools command line prompt.
168
169 Change to the directory into which you want to build tcpdump, possibly
170 after creating it first. One choice is to create it as a subdirectory
171 of the tcpdump source directory.
172
173 Run the command
174
175 cmake "-DPacket_ROOT={path-to-sdk}" {path-to-tcpdump-source}
176
177 where {path-to-sdk} is the path of the directory containing the Npcap or
178 WinPcap SDK and {path-to-tcpdump-source} is the pathname of the
179 top-level source directory for tcpdump.
180
181 Run the command
182
183 msbuild/m tcpdump.sln
184
185 to compile tcpdump.