diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index ebf7a318e2..b0c879ded1 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -495,9 +495,25 @@ static void uncompress_addr(FAR const struct netdev_varaddr_s *addr, /* If the postcount is even then take extra care with endian-ness */ destndx = 8 - (postcount >> 1); - endndx = 8 - (postcount & 1); - for (i = destndx; i < endndx; i++) + /* Handle any odd byte first */ + + if ((postcount & 1) != 0) + { +#ifdef CONFIG_BIG_ENDIAN + /* Preserve big-endian, network order */ + + ipaddr[destndx - 1] = (uint16_t)(*srcptr) << 8; +#else + /* Preserve big-endian, network order */ + + ipaddr[destndx - 1] = (uint16_t)(*srcptr); +#endif + + srcptr++; + } + + for (i = destndx; i < 8; i++) { #ifdef CONFIG_BIG_ENDIAN /* Preserve big-endian, network order */ @@ -511,13 +527,6 @@ static void uncompress_addr(FAR const struct netdev_varaddr_s *addr, srcptr += 2; } - /* Handle any remaining odd byte */ - - if ((postcount & 1) != 0) - { - ipaddr[7] = (uint16_t)(*srcptr) << 8; - } - /* If the was a standard MAC based address then toggle */ if (fullmac)