В настоящее время я разлагаю пакет данных на несколько заголовков.Получить размер 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.
Thanks
ARP не имеет ничего общего с TCP. Вы не найдете сегмент TCP внутри пакета ARP. –