How to filter the inbound packet by libpcap in C

时光怂恿深爱的人放手 提交于 2019-12-11 07:30:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!