From: Roy Marples Date: Wed, 9 Jul 2008 22:41:49 +0000 (+0000) Subject: Ensure that our ARP messages are at least 64 bytes so we're RFC compliant. X-Git-Tag: v4.0.2~219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23d8d9ce8aeac7dd87e3b4b65b929083ab97e7d7;p=thirdparty%2Fdhcpcd.git Ensure that our ARP messages are at least 64 bytes so we're RFC compliant. --- diff --git a/net.c b/net.c index fa1b7c92..e6ac96aa 100644 --- a/net.c +++ b/net.c @@ -618,19 +618,21 @@ int send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip) { struct arphdr *arp; - size_t arpsize; - unsigned char *p; + size_t arpsize, l; + uint8_t *p; int retval; arpsize = sizeof(*arp) + 2 * iface->hwlen + 2 *sizeof(sip); - + /* Ensure that our packet is of the minimum size */ + if (arpsize < ETHER_MIN_LEN - ETHER_HDR_LEN) + arpsize = ETHER_MIN_LEN - ETHER_HDR_LEN; arp = xmalloc(arpsize); arp->ar_hrd = htons(iface->family); arp->ar_pro = htons(ETHERTYPE_IP); arp->ar_hln = iface->hwlen; arp->ar_pln = sizeof(sip); arp->ar_op = htons(op); - p = (unsigned char *)arp; + p = (uint8_t *)arp; p += sizeof(*arp); memcpy(p, iface->hwaddr, iface->hwlen); p += iface->hwlen; @@ -641,6 +643,11 @@ send_arp(const struct interface *iface, int op, in_addr_t sip, in_addr_t tip) memset(p, 0xff, iface->hwlen); p += iface->hwlen; memcpy(p, &tip, sizeof(tip)); + p += sizeof(tip); + /* Zero pad if needed */ + l = p - (uint8_t *)arp; + if (l < arpsize) + memset(p, 0, arpsize - l); retval = send_raw_packet(iface, ETHERTYPE_ARP, arp, arpsize); free(arp);