Hello all, I face a strange problem of libpcap.
On my WRT54GL with openwrt RC6, I can run "tcpdump ether src aa:bb:cc:dd:ee:ff" successfully, the tcpdump grabs packets from the source aa:bb:cc:dd:ee:ff , no matter what the type of packet is. Then when I run a self-design program which use libpcap to do the same job, i.e. set the filter with "ether src aa:bb:cc:dd:ee:ff", the program cannot work probably. For the ICMP (ping) packets, the program can only the grab first 6 packets, after that it can't grab any ICMP packet anymore. For the TCP packets, it can only grab part of the packet, some packets is missed.
Anyone knows what I should do? (I attached the simplified code of my program)
Thanks a lot.
-------------------------------------------
#define MONITOR "prism0"
#include<stdio.h>
#include<stdlib.h>
#include <pcap.h>
int main(){
pcap_t *hIf;
struct bpf_program filter;
char filter_str[]="ether src AA:BB:CC:DD:EE:FF\0";
const unsigned char *packet;
struct pcap_pkthdr header;
char pcapErrBuf[PCAP_ERRBUF_SIZE];
int count = 0;
hIf = pcap_open_live(MONITOR, BUFSIZ, 1, 0, pcapErrBuf);
if (!hIf){
return 0;
}
if ( pcap_compile(hIf, &filter, filter_str, 0, 0) == -1 ){
return 0;
}
if ( pcap_setfilter(hIf, &filter) == -1){
return 0;
}
while (count < 10) {
int read = 0;
packet = pcap_next(hIf, &header);
if ( packet ){
printf("Count = %d\n",++count);
}
}
pcap_close(hIf);
}