Wireshark-users: [Wireshark-users] Pcap library (Portability between linux and windows)
Hello,
I don't know if I'm on the good mailing list to post this thread but as this software use correctly the two libraries I thought about posting here.
I'm trying to create a protocol (directly on the MAC layer) to communicate between FPGA and PC. And i would like it to be compatible between linux and windows. My code compile and seems to work correctly but the libpcap function doesn't act the same way as the winpcap function.
I want to use the pcap_next_ex() function to look if there is packet on the interface and return if true or after a timeout. It works correctly on windows, however on linux I need to set pcap to non blocking and I'm loosing a lot of packet. Did someone as the same problem? How the wireshark function works on linux because I can see all the packet using wireshark?
Here you have a sample of the code use for windows and linux.
//Open the interface.
#ifdef WIN32
adhandle= pcap_open(ifname, SIZEIB_MTU, PCAP_OPENFLAG_PROMISCUOUS, timeout, NULL,errbuf);
#else
adhandle = pcap_open_live(ifname,SIZEIB_MTU,PCAP_OPENFLAG_PROMISCUOUS,timeout,errbuf);
pcap_setnonblock(adhandle,timeout,errbuf);
#endif
....
while(TRUE) {
#ifdef WIN32
ret = pcap_next_ex(adhandle, &(header), (const u_char**)(&p_pkt));
#else
pcap_next_ex(adhandle, &(header), (const u_char**)(&p_pkt));
ret = header->len;
#endif
if(ret > 0) {
count++;
printf("pkt %d has size %d\n",count,ret);
}
}
--
Benoit RAT
www.neub.co.nr