问题
Recently I am trying to filter the inbound packet from the pcap file by libpcap in C/C++. Here is partial code.
pcap = pcap_open_offline(argv[0], errbuf);
if (pcap == NULL)
{
fprintf(stderr, "error reading pcap file: %s\n", errbuf);
exit(1);
}
char filter_exp[] = "inbound";
struct bpf_program pgm;
if (pcap_compile(pcap, &pgm, filter_exp, 0, PCAP_NETMASK_UNKNOWN) == -1) {
printf("Bad filter - %s\n", pcap_geterr(pcap));
return 1;
}
if (pcap_setfilter(pcap, &pgm) == -1) {
printf("Error setting filter - %s\n", pcap_geterr(pcap));
return 1;
}
But the error message is as following.
Bad filter - inbound/outbound not supported on linktype 1 when reading savefiles
Is there any way that can filter inbound packet in C/C++ ?
来源:https://stackoverflow.com/questions/50878253/how-to-filter-the-inbound-packet-by-libpcap-in-c