From patchwork Tue Mar 27 23:42:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 149116 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4FA2CB6EEF for ; Wed, 28 Mar 2012 15:34:49 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 71C0E282DB; Wed, 28 Mar 2012 06:33:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s0d4wStJh7lm; Wed, 28 Mar 2012 06:33:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A6DA42836E; Wed, 28 Mar 2012 06:28:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5A23528277 for ; Wed, 28 Mar 2012 02:53:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Zy6LdPFnujoZ for ; Wed, 28 Mar 2012 02:53:19 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller05.natinst.com (mailserver5.natinst.com [130.164.80.5]) by theia.denx.de (Postfix) with ESMTP id 78BFD28276 for ; Wed, 28 Mar 2012 02:53:17 +0200 (CEST) Received: from mailserv59-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller05.natinst.com (8.14.4/8.14.4) with ESMTP id q2RNgrYK029583; Tue, 27 Mar 2012 18:42:53 -0500 Received: from localhost.localdomain ([130.164.14.197]) by mailserv59-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012032718425339-1291156 ; Tue, 27 Mar 2012 18:42:53 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Tue, 27 Mar 2012 18:42:52 -0500 Message-Id: <1332891772-17279-22-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1327020811-1538-1-git-send-email-joe.hershberger@ni.com> References: <1327020811-1538-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ59-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 03/27/2012 06:42:53 PM, Serialize by Router on MailServ59-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 03/27/2012 06:42:53 PM, Serialize complete at 03/27/2012 06:42:53 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.6.7498, 1.0.260, 0.0.0000 definitions=2012-03-27_08:2012-03-27, 2012-03-27, 1970-01-01 signatures=0 X-Mailman-Approved-At: Wed, 28 Mar 2012 06:28:13 +0200 Cc: Joe Hershberger Subject: [U-Boot] [PATCH v2 21/21] net: cosmetic: Replace magic numbers in arp.c with constants X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Joe Hershberger Cc: Joe Hershberger Cc: Simon Glass Cc: Mike Frysinger --- Changes for v2: - Split from "Improve variable names and code readability" include/net.h | 6 ++++++ net/arp.c | 34 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/net.h b/include/net.h index 3314b4e..bb41f5e 100644 --- a/include/net.h +++ b/include/net.h @@ -258,7 +258,9 @@ struct ARP_hdr { # define ARP_ETHER 1 /* Ethernet hardware address */ ushort ar_pro; /* Format of protocol address */ uchar ar_hln; /* Length of hardware address */ +# define ARP_HLEN 6 uchar ar_pln; /* Length of protocol address */ +# define ARP_PLEN 4 ushort ar_op; /* Operation */ # define ARPOP_REQUEST 1 /* Request to resolve address */ # define ARPOP_REPLY 2 /* Response to previous request */ @@ -272,6 +274,10 @@ struct ARP_hdr { * specific hardware/protocol combinations. */ uchar ar_data[0]; +#define ar_sha ar_data[0] +#define ar_spa ar_data[ARP_HLEN] +#define ar_tha ar_data[ARP_HLEN + ARP_PLEN] +#define ar_tpa ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN] #if 0 uchar ar_sha[]; /* Sender hardware address */ uchar ar_spa[]; /* Sender protocol address */ diff --git a/net/arp.c b/net/arp.c index f994e7d..6e3d7ab 100644 --- a/net/arp.c +++ b/net/arp.c @@ -63,16 +63,16 @@ void ArpRequest(void) arp->ar_hrd = htons(ARP_ETHER); arp->ar_pro = htons(PROT_IP); - arp->ar_hln = 6; - arp->ar_pln = 4; + arp->ar_hln = ARP_HLEN; + arp->ar_pln = ARP_PLEN; arp->ar_op = htons(ARPOP_REQUEST); /* source ET addr */ - memcpy(&arp->ar_data[0], NetOurEther, 6); + memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN); /* source IP addr */ - NetWriteIP((uchar *) &arp->ar_data[6], NetOurIP); + NetWriteIP(&arp->ar_spa, NetOurIP); /* dest ET addr = 0 */ - memset(&arp->ar_data[10], '\0', 6); + memset(&arp->ar_tha, 0, ARP_HLEN); if ((NetArpWaitPacketIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) { if (NetOurGatewayIP == 0) { @@ -85,7 +85,7 @@ void ArpRequest(void) NetArpWaitReplyIP = NetArpWaitPacketIP; } - NetWriteIP((uchar *) &arp->ar_data[16], NetArpWaitReplyIP); + NetWriteIP(&arp->ar_tpa, NetArpWaitReplyIP); (void) eth_send(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); } @@ -139,15 +139,15 @@ void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len) return; if (ntohs(arp->ar_pro) != PROT_IP) return; - if (arp->ar_hln != 6) + if (arp->ar_hln != ARP_HLEN) return; - if (arp->ar_pln != 4) + if (arp->ar_pln != ARP_PLEN) return; if (NetOurIP == 0) return; - if (NetReadIP(&arp->ar_data[16]) != NetOurIP) + if (NetReadIP(&arp->ar_tpa) != NetOurIP) return; switch (ntohs(arp->ar_op)) { @@ -157,10 +157,10 @@ void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len) pkt = (uchar *)et; pkt += NetSetEther(pkt, et->et_src, PROT_ARP); arp->ar_op = htons(ARPOP_REPLY); - memcpy(&arp->ar_data[10], &arp->ar_data[0], 6); - NetCopyIP(&arp->ar_data[16], &arp->ar_data[6]); - memcpy(&arp->ar_data[0], NetOurEther, 6); - NetCopyIP(&arp->ar_data[6], &NetOurIP); + memcpy(&arp->ar_tha, &arp->ar_sha, ARP_HLEN); + NetCopyIP(&arp->ar_tpa, &arp->ar_spa); + memcpy(&arp->ar_sha, NetOurEther, ARP_HLEN); + NetCopyIP(&arp->ar_spa, &NetOurIP); (void) eth_send((uchar *)et, (pkt - (uchar *)et) + ARP_HDR_SIZE); return; @@ -173,12 +173,12 @@ void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len) #ifdef CONFIG_KEEP_SERVERADDR if (NetServerIP == NetArpWaitPacketIP) { char buf[20]; - sprintf(buf, "%pM", arp->ar_data); + sprintf(buf, "%pM", arp->ar_sha); setenv("serveraddr", buf); } #endif - reply_ip_addr = NetReadIP(&arp->ar_data[6]); + reply_ip_addr = NetReadIP(&arp->ar_spa); /* matched waiting packet's address */ if (reply_ip_addr == NetArpWaitReplyIP) { @@ -187,14 +187,14 @@ void ArpReceive(struct Ethernet_hdr *et, struct IP_UDP_hdr *ip, int len) /* save address for later use */ memcpy(NetArpWaitPacketMAC, - &arp->ar_data[0], 6); + &arp->ar_sha, ARP_HLEN); #ifdef CONFIG_NETCONSOLE NetGetHandler()(0, 0, 0, 0, 0); #endif /* modify header, and transmit it */ memcpy(((struct Ethernet_hdr *)NetArpWaitTxPacket)-> - et_dest, NetArpWaitPacketMAC, 6); + et_dest, NetArpWaitPacketMAC, ARP_HLEN); (void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);