0
在我在做,可以收到ACK和建立连接的TCP程序尝试我碰到这个功能在一个示例程序来:了解功能。 PCAP和BPF
void *pth_capture_run(void *arg)
{
pcap_t *pd;
char *filter = "dst host 172.17.14.90 and ip";
char *dev = "fxp0";
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 netp;
bpf_u_int32 maskp;
struct bpf_program fprog; /* Filter Program */
int dl = 0, dl_len = 0;
if ((pd = pcap_open_live(dev, 1514, 1, 500, errbuf)) == NULL) {
fprintf(stderr, "cannot open device %s: %s\n", dev, errbuf);
exit(1);
}
pcap_lookupnet(dev, &netp, &maskp, errbuf);
pcap_compile(pd, &fprog, filter, 0, netp);
if (pcap_setfilter(pd, &fprog) == -1) {
fprintf(stderr, "cannot set pcap filter %s: %s\n", filter, errbuf);
exit(1);
}
pcap_freecode(&fprog);
dl = pcap_datalink(pd);
switch(dl) {
case 1:
dl_len = 14;
break;
default:
dl_len = 14;
break;
}
if (pcap_loop(pd, -1, raw_packet_receiver, (u_char *)dl_len) < 0) {
fprintf(stderr, "cannot get raw packet: %s\n", pcap_geterr(pd));
exit(1);
}
}
现在我已经收集这个函数打开一个BPF设备和设置数据包过滤器,然后等待数据包到达。然而,对于网络编程我很陌生,我不熟悉各种pcap函数,并且还不清楚这个函数的功能,简而言之,它是如何工作的以及它是如何工作的。我已阅读本教程:http://yuba.stanford.edu/~casado/pcap/section1.html 但我仍然有点困惑。你们中的任何一个都可以用更简单的术语来解释吗谢谢!
哪一部分正是混淆了你? – RedX 2012-07-25 23:04:17
@RedX绝大多数是诚实的,但特别是前两个if语句和中间的位。我知道我在这里有点泛泛,但正如我所说,这对我来说都是新鲜事。 – youjustreadthis 2012-07-25 23:26:24