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