demo 1:
#define WPCAP
#define HAVE_REMOTE
// http://www.cnblogs.com/phinecos/archive/2008/10/20/1315176.html
// http://wenku.baidu.com/view/ede0fc886529647d272852e8.html
// http://www.ferrisxu.com/WinPcap/html/index.html
#include "stdafx.h"
#pragma comment(lib,"wpcap.lib")
#pragma comment(lib,"packet.lib")
#pragma comment(lib,"ws2_32.lib")
#include<pcap.h>
// 获取适配器列表
int _tmain(int argc, _TCHAR* argv[])
{
pcap_if_t* allAdapters = NULL; // 适配器
pcap_if_t* pAdapter = NULL;
char errBuffer[PCAP_ERRBUF_SIZE] = {0};
if(pcap_findalldevs(&allAdapters,errBuffer) == -1)
{
//printf("find all devs fuail!")
fprintf(stderr,"Error in the pcap_findalldevs: function:%s.\n",errBuffer);
return -1;
}
if(allAdapters == NULL)
{ // 没有找到任何适配器
fprintf(stderr,"non't find the devs.\n");
return 0;
}
int crtAdapter = 0;
for(pAdapter = allAdapters; pAdapter != NULL;pAdapter = pAdapter->next)
{ //遍历输入适配器信息(名称和描述信息)
printf("\n%d.%s",crtAdapter,pAdapter->name);
printf("\n--%s",pAdapter->description);
crtAdapter++;
}
printf("\n");
pcap_freealldevs(allAdapters);
return 0;
}