From 25f33c84442b0f7b41859bba705d3a0844a14522 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 16 May 2010 16:26:12 +0000 Subject: [PATCH] struct etharp_hdr: split _hwlen_protolen into two u8_t's to prevent using htons on little-endian platforms --- src/include/netif/etharp.h | 3 ++- src/netif/etharp.c | 16 ++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index 51d7b6ad..a4803ec4 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -115,7 +115,8 @@ PACK_STRUCT_BEGIN 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(u8_t hwlen); + PACK_STRUCT_FIELD(u8_t protolen); PACK_STRUCT_FIELD(u16_t opcode); PACK_STRUCT_FIELD(struct eth_addr shwaddr); PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); diff --git a/src/netif/etharp.c b/src/netif/etharp.c index da10abb0..f690ecd9 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -83,12 +83,6 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}}; #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_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)) - enum etharp_state { ETHARP_STATE_EMPTY = 0, ETHARP_STATE_PENDING, @@ -701,12 +695,13 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* RFC 826 "Packet Reception": */ if ((hdr->hwtype != PP_HTONS(HWTYPE_ETHERNET)) || - (hdr->_hwlen_protolen != PP_HTONS((ETHARP_HWADDR_LEN << 8) | sizeof(ip_addr_t))) || + (hdr->hwlen != ETHARP_HWADDR_LEN) || + (hdr->protolen != sizeof(ip_addr_t)) || (hdr->proto != PP_HTONS(ETHTYPE_IP)) || (ethhdr->type != PP_HTONS(ETHTYPE_ARP))) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("etharp_arp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n", - hdr->hwtype, ARPH_HWLEN(hdr), hdr->proto, ARPH_PROTOLEN(hdr), ethhdr->type)); + hdr->hwtype, hdr->hwlen, hdr->proto, hdr->protolen, ethhdr->type)); ETHARP_STATS_INC(etharp.proterr); ETHARP_STATS_INC(etharp.drop); pbuf_free(p); @@ -1153,8 +1148,9 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, hdr->hwtype = PP_HTONS(HWTYPE_ETHERNET); hdr->proto = PP_HTONS(ETHTYPE_IP); - /* set hwlen and protolen together */ - hdr->_hwlen_protolen = PP_HTONS((ETHARP_HWADDR_LEN << 8) | sizeof(ip_addr_t)); + /* set hwlen and protolen */ + hdr->hwlen = ETHARP_HWADDR_LEN; + hdr->protolen = sizeof(ip_addr_t); ethhdr->type = PP_HTONS(ETHTYPE_ARP); /* send ARP query */