Use winpcap for programming

Source: Internet
Author: User

After Winpcap is installed, the DLL file has been installed in the c: \ windows \ system32 directory. Some header files are required to use the Winpcap library. You need to download the SDK from Winpcap.

Decompress the package to a directory. In visual studio2010, right-click the project -- properties -- VC ++ directory and add wpdpack \ include to the include directory; add wpdpack \ Lib to the library file (note that this is also the 64-bit system, rather than \ 64); in the latest Winpcap (4.1.2), if you run the following example:

#define HAVE_REMOTE#include "pcap.h"#pragma comment(lib, "Packet.lib")#pragma comment(lib, "wpcap.lib")int main(){pcap_if_t *alldevs;pcap_if_t *d;int i = 0;char errbuf[PCAP_ERRBUF_SIZE];if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1){fprintf(stderr, "Error in pcap_findalldevs_ex:%s\n", errbuf);exit(1);}for (d = alldevs; d != NULL; d = d->next){printf("%d. %s", ++i, d->name);if (d->description)printf(" (%s)\n", d->description);elseprintf(" (No description available)\n");}if (i == 0){printf("\nNo interfaces found! Make sure WinPcap is installed.\n");return 1;}pcap_freealldevs(alldevs);return 0;}

Note that the header file contains some. The test result is as follows:

Reference link: http://blog.chinaunix.net/uid-11742111-id-2833604.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.