// hello.cpp : 定义控制台应用程序的入口点。
//
#define WPCAP
#define HAVE_REMOTE
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
/*
* we do not want the warnings about the old deprecated and unsecure CRT functions
* since these examples can be compiled under *nix as well
*/
#include "pcap.h"
void main()
{
pcap_if_t *alldevs,*d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
/* PCAP_ERRBUF_SIZE =256,在pcap.h中定义*/
if (pcap_findalldevs(&alldevs, errbuf) == -1) /* 这个API用来获得网卡的列表*/
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
//errbuf参数当有异常情况发生时这个参数会被填充为某个特定的错误字串
return;
}
/* 显示列表的响应字段的内容*/
for(d=alldevs;d;d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description) printf(" (%s)\n", d->description);
else printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return;
}
/*We don't need any more the device list. Free it */
pcap_freealldevs(alldevs); //释放掉内存资源
}