1

hai..am 在 vc++ 中使用 pcap 编写简单的 tcp 嗅探器。所以如何阻止或过滤来自任何 ip 的所有传入口袋

请提出您的建议

谢谢你

4

1 回答 1

1
 PcapHandle = pcap_open_live(device, 65535, 1, 0, errbuf);
  if (PcapHandle == NULL) {
// Error handling
  }
  /* Compile and apply the filter */
  sprintf(FilterExp, "dst host %s", sDestIp); // sDestIp your IP to filter
  if (pcap_compile(m_pPcapHandle, &fp, FilterExp, 1, mask) < 0) {
    printf("Couldn't parse filter '%s': %s\n", FilterExp, pcap_geterr(PcapHandle));
    pcap_close(PcapHandle);
// Error handling
  }
  if (pcap_setfilter(PcapHandle, &fp) < 0) {
    printf("Couldn't install filter '%s': %s\n", FilterExp, pcap_geterr(PcapHandle));
    pcap_freecode(&fp);
    pcap_close(m_pPcapHandle);
// Error handling
  }
  pcap_loop(...)
于 2010-09-30T21:13:30.883 回答