各位朋友,我有两个问题:
1、winpcap是不是不需要在网络配置里加入驱动?
2、我调用的程序如下:
adapter=(char*)pcap_lookupdev(ebuf);
if(adapter == NULL)
{
printf(TEXT("PCAP error:%s\n"), ebuf);
return;
}
// Step 2: Open the adapter
fp = pcap_open_live(adapter, 2000, 1, 20, ebuf);
if(fp == NULL)
{
printf(TEXT("PCAP error:%s\n"), ebuf);
return;
}
// Step 3: Check the datalink.
if(pcap_datalink(fp) != DLT_EN10MB)
{
printf("Not Ethernet 10MB adapter!\n");
pcap_close(fp);
return;
} // Step 4: Start capturing.
         pcap_loop(fp, 0, dispatcher_handler, NULL);
printf("%d",header.len);
// Step 5: Close the adapter.
  pcap_close(fp);void dispatcher_handler(u_char *,const struct pcap_pkthdr *header, const u_char *pkt_data)
{
PETHHEADER eth_header = (PETHHEADER)pkt_data;
::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
printf("\r\nCaptured time:");
::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
printf("%ld:%ld",header->ts.tv_sec, header->ts.tv_usec);
::SetConsoleTextAttribute(hStdOut, ATTR_NORMAL);
printf("\r\nPacket Length:");
::SetConsoleTextAttribute(hStdOut, ATTR_VALUE);
printf("%ld",header->len);
//..................略
}
我前几步都正常,唯独第四步好像进入了死循环。也就是跟踪读取网卡,打开网卡操作都非常正常。而我在dispatcher_handler包处理函数中加入断点,一点反映也没有。我用pcap_next代替pcap_loop试过,结果返回的header长是-87493829 , 这是为什么呢?