네트워크 분석기를 작성 중이며 파일에 저장된 패킷을 필터링해야합니다. http 패킷을 필터링하는 코드를 작성했으나 사용하는 경우 작동하지 않을지 잘 모르겠습니다. PCAP 덤프에 내 코드는 결과는 5 개 패킷하지만 필터 와이어 샤크에서 쓰기 HTTP 나에게이 패킷을주고 내가 사용하는 경우 :pcap 덤프 파일의 패킷 필터링
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 파일 링크를 첨부 할 수 있습니까, 아니면 원인을 알기가 어렵습니다. –