【发布时间】:2017-04-04 02:03:33
【问题描述】:
我目前正在将一个数据包分解为多个标头。
这是我当前的代码:
void analyse(struct pcap_pkthdr *header, const unsigned char *packet, int verbose) {
// Define headers and payload
const struct ether_header *ethernet = NULL;
const struct ether_arp *arp = NULL;
const struct ip *ip = NULL;
const struct tcphdr *tcp = NULL;
const char *payload = NULL;
/* Ethernet header is the first data block of packet **/
ethernet = ( struct ether_header* ) packet;
// ARP packet following
if( ntohs( ethernet->ether_type ) == ETHERTYPE_ARP ) {
arp = ( struct ether_arp* ) ( packet + ETH_HLEN );
// If the operation performed by the sender is a reply, we increment the ARP Response Counter
if( ntohs(arp->ea_hdr.ar_op ) == 2 ) {
arpResponsesCounter++;
}
} else { // IP packet following
ip = ( struct ip* ) ( packet + ETH_HLEN );
}
// ARP header and IP header don't have the same size
if( arp == NULL ) {
u_int shift_size = (ip->ip_hl)*4;
} else {
}
}
根据 http://unix.superglobalmegacorp.com/BSD4.4/newsrc/netinet/ip.h.html 和 http://unix.superglobalmegacorp.com/Net2/newsrc/netinet/if_ether.h.html ,IP 标头的大小由 (ip->ip_hl)*4; 给出,但我不知道如何获取 ARP 标头的大小。
我需要它来正确定义 TCP 标头指针。
谢谢
【问题讨论】:
-
ARP 与 TCP 无关。您不会在 ARP 数据包中找到 TCP 段。
标签: c networking tcp ip arp