我写网络分析仪和我需要过滤保存在文件包,我已经写了一些代码来过滤HTTP数据包,但我不知道,如果它工作,因为它应该,因为当我使用我在PCAP转储代码的结果是5包,但在过滤器Wireshark的书面HTTP给了我2个包,如果我用:过滤包
tcpdump port http -r trace-1.pcap
它给了我11个包。
好吧,3个不同的结果,这有点混乱。
过滤器和在我的代码数据包处理:
...
if (pcap_compile(handle, &fcode, "tcp port 80", 1, netmask) < 0)
...
while ((packet = pcap_next(handle,&header))) {
u_char *pkt_ptr = (u_char *)packet;
//parse the first (ethernet) header, grabbing the type field
int ether_type = ((int)(pkt_ptr[12]) << 8) | (int)pkt_ptr[13];
int ether_offset = 0;
if (ether_type == ETHER_TYPE_IP) // ethernet II
ether_offset = 14;
else if (ether_type == ETHER_TYPE_8021Q) // 802
ether_offset = 18;
else
fprintf(stderr, "Unknown ethernet type, %04X, skipping...\n", ether_type);
//parse the IP header
pkt_ptr += ether_offset; //skip past the Ethernet II header
struct ip_header *ip_hdr = (struct ip_header *)pkt_ptr;
int packet_length = ntohs(ip_hdr->tlen);
printf("\n%d - packet length: %d, and the capture lenght: %d\n", cnt++,packet_length, header.caplen);
}
我的问题是,为什么有过滤HTTP时,3种不同的结果呢?和/或如果我过滤错了,那么我该怎么做对,也有一种方法来过滤http(或ssh,ftp,telnet ...)数据包使用别的不同端口号?
谢谢
你比较各色nce或结果?或者你可以附加pcap文件链接,否则很难说明原因。 – 2012-02-26 10:32:49