lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-devel] byte order, packing, optimizations


From: Stéphane Lesage
Subject: RE: [lwip-devel] byte order, packing, optimizations
Date: Mon, 15 Feb 2010 03:22:19 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)


As we use ip_addr2 for compilers that don't support struct packing,
it means packing is not necessary for ethernet / ARP headers.

The proposed patch removes packing, and processes all addresses with u16_t accesses.



Index: core/ipv4/autoip.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/autoip.c,v
retrieving revision 1.28
diff -u -r1.28 autoip.c
--- core/ipv4/autoip.c  12 Feb 2010 16:42:02 -0000      1.28
+++ core/ipv4/autoip.c  14 Feb 2010 20:27:04 -0000
@@ -472,18 +472,20 @@
     */
     ip_addr_t sipaddr, dipaddr;
     struct eth_addr netifaddr;
-    netifaddr.addr[0] = netif->hwaddr[0];
-    netifaddr.addr[1] = netif->hwaddr[1];
-    netifaddr.addr[2] = netif->hwaddr[2];
-    netifaddr.addr[3] = netif->hwaddr[3];
-    netifaddr.addr[4] = netif->hwaddr[4];
-    netifaddr.addr[5] = netif->hwaddr[5];
+    netifaddr.byte[0] = netif->hwaddr[0];
+    netifaddr.byte[1] = netif->hwaddr[1];
+    netifaddr.byte[2] = netif->hwaddr[2];
+    netifaddr.byte[3] = netif->hwaddr[3];
+    netifaddr.byte[4] = netif->hwaddr[4];
+    netifaddr.byte[5] = netif->hwaddr[5];
 
     /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
      * structure packing (not using structure copy which breaks 
strict-aliasing rules).
      */
-    SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
-    SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
+    sipaddr.addrw[0] = hdr->sipaddr.addrw[0]; 
+    sipaddr.addrw[1] = hdr->sipaddr.addrw[1]; 
+    dipaddr.addrw[0] = hdr->dipaddr.addrw[0]; 
+    dipaddr.addrw[1] = hdr->dipaddr.addrw[1]; 
       
     if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
         ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
Index: include/ipv4/lwip/ip_addr.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/ipv4/lwip/ip_addr.h,v
retrieving revision 1.48
diff -u -r1.48 ip_addr.h
--- include/ipv4/lwip/ip_addr.h 14 Feb 2010 12:41:46 -0000      1.48
+++ include/ipv4/lwip/ip_addr.h 14 Feb 2010 20:46:16 -0000
@@ -44,7 +44,11 @@
 #endif
 PACK_STRUCT_BEGIN
 struct _ip_addr {
-  PACK_STRUCT_FIELD(u32_t addr);
+  union {
+    PACK_STRUCT_FIELD(u32_t addr);
+    PACK_STRUCT_FIELD(u16_t addrw[2]);
+    PACK_STRUCT_FIELD(u8_t addrb[4]);
+  };
 } PACK_STRUCT_STRUCT;
 PACK_STRUCT_END
 #ifdef PACK_STRUCT_USE_INCLUDES
@@ -57,17 +61,9 @@
  * struct ipaddr2 is used in the definition of the ARP packet format in
  * order to support compilers that don't have structure packing.
  */
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/bpstruct.h"
-#endif
-PACK_STRUCT_BEGIN
 struct ip_addr2 {
-  PACK_STRUCT_FIELD(u16_t addrw[2]);
-} PACK_STRUCT_STRUCT;
-PACK_STRUCT_END
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/epstruct.h"
-#endif
+  u16_t addrw[2];
+};
 
 /* Forward declaration to not include netif.h */
 struct netif;
@@ -195,10 +191,10 @@
                       ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
 
 /* Get one byte from the 4-byte address */
-#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
-#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
-#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
-#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
+#define ip4_addr1(ipaddr) (ipaddr)->addrb[0]
+#define ip4_addr2(ipaddr) (ipaddr)->addrb[1]
+#define ip4_addr3(ipaddr) (ipaddr)->addrb[2]
+#define ip4_addr4(ipaddr) (ipaddr)->addrb[3]
 /* These are cast to u16_t, with the intent that they are often arguments
  * to printf using the U16_F format from cc.h. */
 #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
Index: include/lwip/netif.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/netif.h,v
retrieving revision 1.57
diff -u -r1.57 netif.h
--- include/lwip/netif.h        14 Feb 2010 16:44:47 -0000      1.57
+++ include/lwip/netif.h        15 Feb 2010 02:20:27 -0000
@@ -182,7 +182,7 @@
   /** maximum transfer unit (in bytes) */
   u16_t mtu;
   /** number of bytes used in hwaddr */
-  u8_t hwaddr_len;
+  u16_t hwaddr_len;
   /** link level hardware address of this interface */
   u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
   /** flags (see NETIF_FLAG_ above) */
Index: include/netif/etharp.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/netif/etharp.h,v
retrieving revision 1.46
diff -u -r1.46 etharp.h
--- include/netif/etharp.h      14 Feb 2010 18:08:17 -0000      1.46
+++ include/netif/etharp.h      14 Feb 2010 20:25:59 -0000
@@ -56,80 +56,59 @@
 #define ETHARP_HWADDR_LEN     6
 #endif
 
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/bpstruct.h"
-#endif
-PACK_STRUCT_BEGIN
+#define ETHARP_HWADDR_NWORDS (ETHARP_HWADDR_LEN/2)
+
 struct eth_addr {
-  PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
-} PACK_STRUCT_STRUCT;
-PACK_STRUCT_END
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/epstruct.h"
-#endif
+  union {
+    u16_t word[ETHARP_HWADDR_NWORDS];
+    u8_t byte[ETHARP_HWADDR_LEN];
+  };
+};
 
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/bpstruct.h"
-#endif
-PACK_STRUCT_BEGIN
 /** Ethernet header */
 struct eth_hdr {
 #if ETH_PAD_SIZE
-  PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
-#endif
-  PACK_STRUCT_FIELD(struct eth_addr dest);
-  PACK_STRUCT_FIELD(struct eth_addr src);
-  PACK_STRUCT_FIELD(u16_t type);
-} PACK_STRUCT_STRUCT;
-PACK_STRUCT_END
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/epstruct.h"
+  u8_t padding[ETH_PAD_SIZE];
 #endif
+  struct eth_addr dest;
+  struct eth_addr src;
+  u16_t type;
+};
 
 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
 
 #if ETHARP_SUPPORT_VLAN
 
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/bpstruct.h"
-#endif
-PACK_STRUCT_BEGIN
 /** VLAN header inserted between ethernet header and payload
  * if 'type' in ethernet header is ETHTYPE_VLAN.
  * See IEEE802.Q */
 struct eth_vlan_hdr {
-  PACK_STRUCT_FIELD(u16_t tpid);
-  PACK_STRUCT_FIELD(u16_t prio_vid);
-} PACK_STRUCT_STRUCT;
-PACK_STRUCT_END
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/epstruct.h"
-#endif
+  u16_t tpid;
+  u16_t prio_vid;
+};
 
 #define SIZEOF_VLAN_HDR 4
 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
 
 #endif /* ETHARP_SUPPORT_VLAN */
 
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/bpstruct.h"
-#endif
-PACK_STRUCT_BEGIN
 /** the ARP message, see RFC 826 ("Packet format") */
 struct etharp_hdr {
-  PACK_STRUCT_FIELD(u16_t hwtype);
-  PACK_STRUCT_FIELD(u16_t proto);
-  PACK_STRUCT_FIELD(u16_t _hwlen_protolen);
-  PACK_STRUCT_FIELD(u16_t opcode);
-  PACK_STRUCT_FIELD(struct eth_addr shwaddr);
-  PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
-  PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
-  PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
-} PACK_STRUCT_STRUCT;
-PACK_STRUCT_END
-#ifdef PACK_STRUCT_USE_INCLUDES
-#  include "arch/epstruct.h"
-#endif
+  u16_t hwtype;
+  u16_t proto;
+  union {
+    u16_t _hwlen_protolen;
+    struct {
+      u8_t hwlen;
+      u8_t protolen;
+    };         
+  };
+  u16_t opcode;
+  struct eth_addr shwaddr;
+  struct ip_addr2 sipaddr;
+  struct eth_addr dhwaddr;
+  struct ip_addr2 dipaddr;
+};
 
 #define SIZEOF_ETHARP_HDR 28
 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
@@ -184,7 +163,7 @@
 
 err_t ethernet_input(struct pbuf *p, struct netif *netif);
 
-#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, 
ETHARP_HWADDR_LEN) == 0)
+#define eth_addr_cmp(addr1, addr2) (memcmp(addr1, addr2, ETHARP_HWADDR_LEN) == 
0)
 
 extern const struct eth_addr ethbroadcast, ethzero;
 
Index: netif/etharp.c
===================================================================
RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
retrieving revision 1.162
diff -u -r1.162 etharp.c
--- netif/etharp.c      14 Feb 2010 18:08:17 -0000      1.162
+++ netif/etharp.c      14 Feb 2010 20:57:14 -0000
@@ -62,8 +62,8 @@
 
 #include <string.h>
 
-const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
-const struct eth_addr ethzero = {{0,0,0,0,0,0}};
+const struct eth_addr ethbroadcast = {{0xffff,0xffff,0xffff}};
+const struct eth_addr ethzero = {{0,0,0}};
 
 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
 
@@ -83,11 +83,11 @@
 
 #define HWTYPE_ETHERNET 1
 
-#define ARPH_HWLEN(hdr) (ntohs((hdr)->_hwlen_protolen) >> 8)
-#define ARPH_PROTOLEN(hdr) (ntohs((hdr)->_hwlen_protolen) & 0xff)
+#define ARPH_HWLEN(hdr)    ((hdr)->hwlen)
+#define ARPH_PROTOLEN(hdr) ((hdr)->protolen)
 
-#define ARPH_HWLEN_SET(hdr, len) (hdr)->_hwlen_protolen = 
htons(ARPH_PROTOLEN(hdr) | ((len) << 8))
-#define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons((len) | 
(ARPH_HWLEN(hdr) << 8))
+#define ARPH_HWLEN_SET(hdr, len)    (hdr)->hwlen = (len)
+#define ARPH_PROTOLEN_SET(hdr, len) (hdr)->protolen = (len)
 
 enum etharp_state {
   ETHARP_STATE_EMPTY = 0,
@@ -436,11 +436,10 @@
 
   LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for 
etharp!",
               (netif->hwaddr_len == ETHARP_HWADDR_LEN));
-  k = ETHARP_HWADDR_LEN;
-  while(k > 0) {
-    k--;
-    ethhdr->dest.addr[k] = dst->addr[k];
-    ethhdr->src.addr[k]  = src->addr[k];
+
+  for (k=0; k<ETHARP_HWADDR_NWORDS; k++) {
+    ethhdr->dest.word[k] = dst->word[k];
+    ethhdr->src.word[k]  = src->word[k];
   }
   ethhdr->type = htons(ETHTYPE_IP);
   LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_send_ip: sending packet 
%p\n", (void *)p));
@@ -476,8 +475,8 @@
   LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == 
ETHARP_HWADDR_LEN);
   LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: 
%"U16_F".%"U16_F".%"U16_F".%"U16_F" - 
%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
     ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), 
ip4_addr4_16(ipaddr),
-    ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
-    ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
+    ethaddr->byte[0], ethaddr->byte[1], ethaddr->byte[2],
+    ethaddr->byte[3], ethaddr->byte[4], ethaddr->byte[5]));
   /* non-unicast address? */
   if (ip_addr_isany(ipaddr) ||
       ip_addr_isbroadcast(ipaddr, netif) ||
@@ -505,11 +504,7 @@
 
   LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: updating 
stable entry %"S16_F"\n", (s16_t)i));
   /* update address */
-  k = ETHARP_HWADDR_LEN;
-  while (k > 0) {
-    k--;
-    arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
-  }
+  arp_table[i].ethaddr = *ethaddr;
   /* reset time stamp */
   arp_table[i].ctime = 0;
 #if ARP_QUEUEING
@@ -634,10 +629,10 @@
   struct eth_hdr *ethhdr;
   /* these are aligned properly, whereas the ARP header fields might not be */
   ip_addr_t sipaddr, dipaddr;
-  u8_t i;
+  u8_t k;
   u8_t for_us;
 #if LWIP_AUTOIP
-  const u8_t * ethdst_hwaddr;
+  const struct eth_addr *ethdst_hwaddr;
 #endif /* LWIP_AUTOIP */
 
   LWIP_ERROR("netif != NULL", (netif != NULL), return;);
@@ -655,12 +650,13 @@
   }
 
   ethhdr = (struct eth_hdr *)p->payload;
-  hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR);
 #if ETHARP_SUPPORT_VLAN
   if (ethhdr->type == ETHTYPE_VLAN) {
     hdr = (struct etharp_hdr *)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR + 
SIZEOF_VLAN_HDR);
   }
+  else
 #endif /* ETHARP_SUPPORT_VLAN */
+  hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR);
 
   /* RFC 826 "Packet Reception": */
   if ((hdr->hwtype != htons(HWTYPE_ETHERNET)) ||
@@ -686,8 +682,10 @@
 
   /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
    * structure packing (not using structure copy which breaks strict-aliasing 
rules). */
-  SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
-  SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
+  sipaddr.addrw[0] = hdr->sipaddr.addrw[0]; 
+  sipaddr.addrw[1] = hdr->sipaddr.addrw[1]; 
+  dipaddr.addrw[0] = hdr->dipaddr.addrw[0]; 
+  dipaddr.addrw[1] = hdr->dipaddr.addrw[1]; 
 
   /* this interface is not configured? */
   if (ip_addr_isany(&netif->ip_addr)) {
@@ -726,28 +724,28 @@
          that would allocate a new pbuf. */
       hdr->opcode = htons(ARP_REPLY);
 
-      SMEMCPY(&hdr->dipaddr, &hdr->sipaddr, sizeof(ip_addr_t));
-      SMEMCPY(&hdr->sipaddr, &netif->ip_addr, sizeof(ip_addr_t));
+      hdr->dipaddr.addrw[0] = hdr->sipaddr.addrw[0]; 
+      hdr->dipaddr.addrw[1] = hdr->sipaddr.addrw[1]; 
+      hdr->sipaddr.addrw[0] = netif->ip_addr.addrw[0]; 
+      hdr->sipaddr.addrw[1] = netif->ip_addr.addrw[1]; 
 
       LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for 
etharp!",
                   (netif->hwaddr_len == ETHARP_HWADDR_LEN));
-      i = ETHARP_HWADDR_LEN;
 #if LWIP_AUTOIP
       /* If we are using Link-Local, ARP packets must be broadcast on the
        * link layer. (See RFC3927 Section 2.5) */
-      ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != 
AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr;
+      ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != 
AUTOIP_STATE_OFF)) ? &ethbroadcast : &hdr->shwaddr;
 #endif /* LWIP_AUTOIP */
 
-      while(i > 0) {
-        i--;
-        hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i];
+      for (k=0; k<ETHARP_HWADDR_NWORDS; k++)  {
+        hdr->dhwaddr.word[k] = hdr->shwaddr.word[k];
 #if LWIP_AUTOIP
-        ethhdr->dest.addr[i] = ethdst_hwaddr[i];
+        ethhdr->dest.word[k] = ethdst_hwaddr->word[k];
 #else  /* LWIP_AUTOIP */
-        ethhdr->dest.addr[i] = hdr->shwaddr.addr[i];
+        ethhdr->dest.word[k] = hdr->shwaddr.word[k];
 #endif /* LWIP_AUTOIP */
-        hdr->shwaddr.addr[i] = ethaddr->addr[i];
-        ethhdr->src.addr[i] = ethaddr->addr[i];
+        hdr->shwaddr.word[k] = ethaddr->word[k];
+        ethhdr->src.word[k] = ethaddr->word[k];
       }
 
       /* hwtype, hwaddr_len, proto, protolen and the type in the ethernet 
header
@@ -829,12 +827,12 @@
   /* multicast destination IP address? */
   } else if (ip_addr_ismulticast(ipaddr)) {
     /* Hash IP multicast address to MAC address.*/
-    mcastaddr.addr[0] = 0x01;
-    mcastaddr.addr[1] = 0x00;
-    mcastaddr.addr[2] = 0x5e;
-    mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f;
-    mcastaddr.addr[4] = ip4_addr3(ipaddr);
-    mcastaddr.addr[5] = ip4_addr4(ipaddr);
+    mcastaddr.byte[0] = 0x01;
+    mcastaddr.byte[1] = 0x00;
+    mcastaddr.byte[2] = 0x5e;
+    mcastaddr.byte[3] = ip4_addr2(ipaddr) & 0x7f;
+    mcastaddr.byte[4] = ip4_addr3(ipaddr);
+    mcastaddr.byte[5] = ip4_addr4(ipaddr);
     /* destination Ethernet address is multicast */
     dest = &mcastaddr;
   /* unicast destination IP address? */
@@ -1061,7 +1059,7 @@
   struct eth_hdr *ethhdr;
   struct etharp_hdr *hdr;
 #if LWIP_AUTOIP
-  const u8_t * ethdst_hwaddr;
+  const struct eth_addr *ethdst_hwaddr;
 #endif /* LWIP_AUTOIP */
 
   /* allocate a pbuf for the outgoing ARP request packet */
@@ -1083,31 +1081,31 @@
 
   LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for 
etharp!",
               (netif->hwaddr_len == ETHARP_HWADDR_LEN));
-  k = ETHARP_HWADDR_LEN;
 #if LWIP_AUTOIP
   /* If we are using Link-Local, ARP packets must be broadcast on the
    * link layer. (See RFC3927 Section 2.5) */
-  ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != 
AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : ethdst_addr->addr;
+  ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != 
AUTOIP_STATE_OFF)) ? &ethbroadcast : ethdst_addr;
 #endif /* LWIP_AUTOIP */
   /* Write MAC-Addresses (combined loop for both headers) */
-  while(k > 0) {
-    k--;
+  for (k=0; k<ETHARP_HWADDR_NWORDS; k++) {
     /* Write the ARP MAC-Addresses */
-    hdr->shwaddr.addr[k] = hwsrc_addr->addr[k];
-    hdr->dhwaddr.addr[k] = hwdst_addr->addr[k];
+    hdr->shwaddr.word[k] = hwsrc_addr->word[k];
+    hdr->dhwaddr.word[k] = hwdst_addr->word[k];
     /* Write the Ethernet MAC-Addresses */
 #if LWIP_AUTOIP
-    ethhdr->dest.addr[k] = ethdst_hwaddr[k];
+    ethhdr->dest.word[k] = ethdst_hwaddr->word[k];
 #else  /* LWIP_AUTOIP */
-    ethhdr->dest.addr[k] = ethdst_addr->addr[k];
+    ethhdr->dest.word[k] = ethdst_addr->word[k];
 #endif /* LWIP_AUTOIP */
-    ethhdr->src.addr[k]  = ethsrc_addr->addr[k];
+    ethhdr->src.word[k]  = ethsrc_addr->word[k];
   }
   /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
    * structure packing. */ 
-  SMEMCPY(&hdr->sipaddr, ipsrc_addr, sizeof(ip_addr_t));
-  SMEMCPY(&hdr->dipaddr, ipdst_addr, sizeof(ip_addr_t));
-
+  hdr->sipaddr.addrw[0] = ipsrc_addr->addrw[0];
+  hdr->sipaddr.addrw[1] = ipsrc_addr->addrw[1];
+  hdr->dipaddr.addrw[0] = ipdst_addr->addrw[0];
+  hdr->dipaddr.addrw[1] = ipdst_addr->addrw[1];
+  /* set hardware and protocol types */
   hdr->hwtype = htons(HWTYPE_ETHERNET);
   hdr->proto = htons(ETHTYPE_IP);
   /* set hwlen and protolen together */
@@ -1161,12 +1159,12 @@
   /* points to packet payload, which starts with an Ethernet header */
   ethhdr = (struct eth_hdr *)p->payload;
   LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
-    ("ethernet_input: dest:%02x:%02x:%02x:%02x:%02x:%02x, 
src:%02x:%02x:%02x:%02x:%02x:%02x, type:%2hx\n",
-     (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], 
(unsigned)ethhdr->dest.addr[2],
-     (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], 
(unsigned)ethhdr->dest.addr[5],
-     (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], 
(unsigned)ethhdr->src.addr[2],
-     (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], 
(unsigned)ethhdr->src.addr[5],
-     (unsigned)htons(ethhdr->type)));
+    ("ethernet_input: dest:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx, 
src:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx, type:%2hx\n",
+     (u16_t)ethhdr->dest.byte[0], (u16_t)ethhdr->dest.byte[1], 
(u16_t)ethhdr->dest.byte[2],
+     (u16_t)ethhdr->dest.byte[3], (u16_t)ethhdr->dest.byte[4], 
(u16_t)ethhdr->dest.byte[5],
+     (u16_t)ethhdr->src.byte[0], (u16_t)ethhdr->src.byte[1], 
(u16_t)ethhdr->src.byte[2],
+     (u16_t)ethhdr->src.byte[3], (u16_t)ethhdr->src.byte[4], 
(u16_t)ethhdr->src.byte[5],
+     (u16_t)get_ns(ethhdr->type)));
 
   type = htons(ethhdr->type);
 #if ETHARP_SUPPORT_VLAN


reply via email to

[Prev in Thread] Current Thread [Next in Thread]