From: Martin Schwenke Date: Tue, 14 Aug 2018 02:36:25 +0000 (+1000) Subject: ctdb-common: Use struct ether_arp to avoid manual offset calculations X-Git-Tag: tdb-1.3.17~1973 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b1e9a43dcd0e4aa158f1e03351b9fefc2db1162;p=thirdparty%2Fsamba.git ctdb-common: Use struct ether_arp to avoid manual offset calculations Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index c60243e9801..a6c5f5c093d 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -198,8 +198,8 @@ static int arp_build(uint8_t *buffer, { size_t l = ARP_BUFFER_SIZE; struct ether_header *eh; + struct ether_arp *ea; struct arphdr *ah; - char *ptr; if (addr->sin_family != AF_INET) { return EINVAL; @@ -216,7 +216,8 @@ static int arp_build(uint8_t *buffer, memcpy(eh->ether_shost, hwaddr, ETH_ALEN); eh->ether_type = htons(ETHERTYPE_ARP); - ah = (struct arphdr *)&buffer[sizeof(struct ether_header)]; + ea = (struct ether_arp *)&buffer[sizeof(struct ether_header)]; + ah = &ea->ea_hdr; ah->ar_hrd = htons(ARPHRD_ETHER); ah->ar_pro = htons(ETH_P_IP); ah->ar_hln = ETH_ALEN; @@ -224,26 +225,16 @@ static int arp_build(uint8_t *buffer, if (! reply) { ah->ar_op = htons(ARPOP_REQUEST); - ptr = (char *)&ah[1]; - memcpy(ptr, hwaddr, ETH_ALEN); - ptr+=ETH_ALEN; - memcpy(ptr, &addr->sin_addr, 4); - ptr+=4; - memset(ptr, 0, ETH_ALEN); - ptr+=ETH_ALEN; - memcpy(ptr, &addr->sin_addr, 4); - ptr+=4; + memcpy(ea->arp_sha, hwaddr, ETH_ALEN); + memcpy(ea->arp_spa, &addr->sin_addr, sizeof(ea->arp_spa)); + memset(ea->arp_tha, 0, ETH_ALEN); + memcpy(ea->arp_tpa, &addr->sin_addr, sizeof(ea->arp_tpa)); } else { ah->ar_op = htons(ARPOP_REPLY); - ptr = (char *)&ah[1]; - memcpy(ptr, hwaddr, ETH_ALEN); - ptr+=ETH_ALEN; - memcpy(ptr, &addr->sin_addr, 4); - ptr+=4; - memcpy(ptr, hwaddr, ETH_ALEN); - ptr+=ETH_ALEN; - memcpy(ptr, &addr->sin_addr, 4); - ptr+=4; + memcpy(ea->arp_sha, hwaddr, ETH_ALEN); + memcpy(ea->arp_spa, &addr->sin_addr, sizeof(ea->arp_spa)); + memcpy(ea->arp_tha, hwaddr, ETH_ALEN); + memcpy(ea->arp_tpa, &addr->sin_addr, sizeof(ea->arp_tpa)); } *ether_dhost = (struct ether_addr *)eh->ether_dhost;