我寫網絡分析儀和我需要過濾保存在文件包,我已經寫了一些代碼來過濾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