私は現在、データパケットをいくつかのヘッダに分解しています。ここでARPパケットのサイズを取得
は私の現在のコードです:
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セグメントを見つけることはできません。 –