当前位置: 代码迷 >> VC >> 请问一个用WinPcap编写的例子
  详细解决方案

请问一个用WinPcap编写的例子

热度:4485   发布时间:2013-02-25 00:00:00.0
请教一个用WinPcap编写的例子
在网上找了一个调用WinPcap的例子,但是用VS2005编译得到下面的错误
1> netflow.cpp
1> c:\try\netflow\netflow\netflow.cpp(210)   :   error   C2664:   'localtime '   :   cannot   convert   parameter   1   from   'const   long   *__w64   '   to   'const   time_t   * '
1>                 Types   pointed   to   are   unrelated;   conversion   requires   reinterpret_cast,   C-style   cast   or   function-style   cast
1> ws2_32.lib
1> c1xx   :   fatal   error   C1083:   Cannot   open   source   file:   'ws2_32.lib ':   No   such   file   or   directory
1> wpcap.lib
1> c1xx   :   fatal   error   C1083:   Cannot   open   source   file:   'wpcap.lib ':   No   such   file   or   directory
1> Generating   Code...
1> Build   log   was   saved   at   "file://c:\try\netflow\netflow\Debug\BuildLog.htm "
1> netflow   -   3   error(s),   0   warning(s)
==========   Build:   0   succeeded,   1   failed,   0   up-to-date,   0   skipped   ==========

2005用的不熟,好像是语法不支持VC6.0的,请问该怎么该啊?
还有,就是这个程序用VC6.0编译成功后,在VC6.0的那台电脑(XP   HOME)上只能显示猫的网络适配器,100M和无线网卡都不显示。但是在另外一台电脑上(XP   PRO+2005NET)却能显示所有网络适配器。请问这是为什么啊?

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//下面是一个应用winpcap写的一个网络流量统计的例子,

//   nettraffic.cpp   :   Defines   the   entry   point   for   the   console   application.

//

#include   <pcap.h>

#include   <remote-ext.h>

#include   <iostream>

#include   <winsock2.h>


using   namespace   std;

//------------------------------------------------------------------------


//------------------------------------------------------------------------

void   dispatcher_handler(u_char*   user_data,   const   struct   pcap_pkthdr   *   pkthdr,   const   u_char   *pktdata);


//------------------------------------------------------------------------

int   main(int   argc,   char*   argv[])

{

                int                                                                                 i;

                pcap_if_t*                                                       alldevs;

                pcap_if_t*                                                       dev;

                char                                                             errorbuf[PCAP_ERRBUF_SIZE];