diff --git a/Makefile b/Makefile index 37004f5..04b31fb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Makefile to generate dhtest CC=gcc -CFLAGS=-Wall -O3 -g -fno-strict-aliasing +CFLAGS=-Wall -O3 -g dhtest: dhtest.o functions.o $(CC) dhtest.o functions.o -o dhtest diff --git a/functions.c b/functions.c index e187b1f..543441a 100644 --- a/functions.c +++ b/functions.c @@ -921,11 +921,11 @@ int check_packet(int pkt_type) map_all_layer_ptr(ARP_MAP); if(!vlan) { - if((ntohs(arp_hg->ar_op)) == ARPOP_REQUEST && (htonl(ip_address)) == (*((u_int32_t *)(arp_hg->target_ip)))) { + if((ntohs(arp_hg->ar_op)) == ARPOP_REQUEST && htonl(ip_address) == arp_hg->target_ip32) { return ARP_RCVD; } } else if(vlan && ntohs(vlan) == vlan_hg->vlan_priority_c_vid) { - if((ntohs(arp_hg->ar_op)) == ARPOP_REQUEST && (htonl(ip_address)) == (*((u_int32_t *)(arp_hg->target_ip)))) { + if((ntohs(arp_hg->ar_op)) == ARPOP_REQUEST && htonl(ip_address) == arp_hg->target_ip32) { fprintf(stdout, "Arp request received\n"); return ARP_RCVD; } diff --git a/headers.h b/headers.h index 0335e4c..9727ddf 100644 --- a/headers.h +++ b/headers.h @@ -92,9 +92,15 @@ struct arp_hdr #define ARPOP_INVREQUEST 8 /* req to identify peer */ #define ARPOP_INVREPLY 9 /* resp identifying peer */ u_int8_t sender_mac[ETHER_ADDR_LEN]; - u_int8_t sender_ip[IP_ADDR_LEN]; + union { + u_int8_t sender_ip[IP_ADDR_LEN]; + u_int32_t sender_ip32; + }; u_int8_t target_mac[ETHER_ADDR_LEN]; - u_int8_t target_ip[IP_ADDR_LEN]; + union { + u_int8_t target_ip[IP_ADDR_LEN]; + u_int32_t target_ip32; + }; }; /*