![]() |
|
WinPcap Library (Visiual Studio Setup) - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: WinPcap Library (Visiual Studio Setup) (/Thread-WinPcap-Library-Visiual-Studio-Setup) |
WinPcap Library (Visiual Studio Setup) - Ligeti - 03-09-2014 Hello and welcome Today I will be talking about WinPcap library, and I will be talking C/C++ here (mainly C), I am on Windows 7 (64 bits), and using Microsoft Visual C++ 2010 source: Jalal Sela (Ligeti++) So what is WinPcap: Quote:"WinPcap is an open source library for packet capture and network analysis for the Win32 platforms."--from the official documentation WinPcap is used in many non-commercial and yet very powerful software like WireShark and Nmap/Zenmap, WinPcap is the Windows version of libpcap (Unix). Quote:"WinPcap, even with a small amount of imagination, it can open doors to infinite ideas and opportunities"--Jalal Sela You can download WinPcap here: http://www.winpcap.org/devel.htm, make sure to download the Developer's Pack (the one I am using is version 4.1.2), make sure to read the documentation, there you can find a step by step tutorial. How to import the library to your project: As for Microsoft Visual C++ 2010: 1- Select "Project" in the menu then click on "Properties" ![]() 2- Go to "Configuration Properties" => "C/C++" => "General" ![]() 3- In "Additional Include Directories" you need to insert the path to the "Include" folder in WinPcap, for example "C:\WinPcap\Include" 4- Go to "Processor" => "Processor Definitions" and add:
![]() 5- After that go to "Linker" => "Additional Library Directories" and insert the path to the "Lib" directory if you are on 32 bits (x86) machine, or "\Lib\x64" if you are on 64 bits (x64) ![]() 6- Go to "Input" => "Additional Dependencies" and add:
![]() 7- finally, in your code, include "pcap.h" Notes:
Now you are ready to write your application using WinPcap library. Here is a quick example that you can test your configuration with: Code: #include <stdlib.h>
#include <stdio.h>
#include "pcap.h"
int main()
{
pcap_if_t * NetworkInterface = 0;
pcap_if_t * tmpNetworkInterface = 0;
int i = 0;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &NetworkInterface, errbuf) == -1)
{
fprintf(stderr,"Error: %s\n", errbuf);
exit(1);
}
for(tmpNetworkInterface= NetworkInterface; tmpNetworkInterface != NULL; tmpNetworkInterface=tmpNetworkInterface->next)
{
printf("Name: %s\n", tmpNetworkInterface->name);
if (tmpNetworkInterface->description)
{
printf("Description: %s\n", tmpNetworkInterface->description);
}
else
printf("N/A\n");
}
pcap_freealldevs(NetworkInterface);
return 0;
}Thank you, please leave your comments. Ligeti [Note] This is a reference that I will be using later in more detailed tutorials about WinPcap [Note] This is in fact the same mechanism used to load any dynamic library into visual studio (Win Sockets, WAV API... etc.) RE: WinPcap Library (Visiual Studio Setup) - ArkPhaze - 03-10-2014 Everything looks alright, except for this: Code: pcap_if_t * NetworkInterface;
pcap_if_t * tmpNetworkInterface;And those system calls. Personally, I wouldn't put everything at the top, but I would definitely initialize those to 0 until you assign to them if you're not going to assign them to an address immediately. RE: WinPcap Library (Visiual Studio Setup) - Ligeti - 03-10-2014 (03-10-2014, 12:32 AM)ArkPhaze Wrote: Everything looks alright, except for this: I could argue that, but I won't, because at the end you are right, it is a good practice to initiate everything (declare rather than define), as you can see, this is a very simple example to test the library setup! Not a real WinPcap library tutorial... But thanks for bringing it up! My next tutorial is about making a ping tool (based on ICMP), real coding... ![]() Thanks Ligeti [edit] I took the system calls out!
RE: WinPcap Library (Visiual Studio Setup) - ArkPhaze - 03-11-2014 I mentioned 0, because this is a typical/common indicator of a null pointer that is not meant to reference anything, if you don't initialize it to 0, it is initially undefined, and this may cause issues should you go to use it later in the code as though it should be referencing something, and this can result in undefined behavior. As for the system() call, most people think it's because it's a non portable function. That's about 10% of my concern with system()... There's much more risks that are far more trivial than the fact that system() will only work with Windows. RE: WinPcap Library (Visiual Studio Setup) - Ligeti - 03-11-2014 I see where you are going, you just can't let it go can you? lol OK, I will correct that as well! Thank you again
RE: WinPcap Library (Visiual Studio Setup) - TheUninvited_mybb_import15721 - 03-15-2014 Great post i will defiantly try this out
|