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