关键词: winpcap
今天开始使用winpcap做一些研究,安装好winpcap的驱动后,运行开发包中附带的例程/examples/iflist,编译器报错如下:
--------------------Configuration: iflist - Win32 Debug--------------------
Compiling...
iflist.c
d:/wpdpack/examples/iflist/iflist.c(151) : error C2065: 'socklen_t' : undeclared identifier
d:/wpdpack/examples/iflist/iflist.c(151) : error C2146: syntax error : missing ';' before identifier 'sockaddrlen'
d:/wpdpack/examples/iflist/iflist.c(151) : error C2065: 'sockaddrlen' : undeclared identifier
d:/wpdpack/examples/iflist/iflist.c(160) : warning C4013: 'getnameinfo' undefined; assuming extern returning int
d:/wpdpack/examples/iflist/iflist.c(166) : error C2065: 'NI_NUMERICHOST' : undeclared identifier
Error executing cl.exe.
iflist.exe - 4 error(s), 1 warning(s)
上网查找了一下相关资料,说错误是因为Winpcap从 IPv4 向 IPv6 迁移,使用 Visual C++6 编译程序时 winsock2.h 等文件太老了,不认得一些新的结构和函数,因此,winpcap 自带的例程在 VC++6 下编译时会出错。
为了解决这一问题,要么安装新的编译环境,如.net等。因为我懒,再加上习惯了在VC6下工作,我采用了另一种方法,安装支持VC6的最新platform sdk。安装完毕后,将其中的Include和lib文件夹中的文件覆盖vc中的相应文件夹中的文件即可。此后程序可以顺利执行。