http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/lowpan6.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/lowpan6.c 
b/net/ip/lwip_base/src/netif/lowpan6.c
index 407848c..9a84cbc 100644
--- a/net/ip/lwip_base/src/netif/lowpan6.c
+++ b/net/ip/lwip_base/src/netif/lowpan6.c
@@ -160,13 +160,13 @@ lowpan6_get_address_mode(const ip6_addr_t *ip6addr, const 
struct ieee_802154_add
   if (mac_addr->addr_len == 2) {
     if ((ip6addr->addr[2] == (u32_t)PP_HTONL(0x000000ff)) &&
       ((ip6addr->addr[3]  & PP_HTONL(0xffff0000)) == PP_NTOHL(0xfe000000))) {
-      if ((ip6addr->addr[3]  & PP_HTONL(0x0000ffff)) == 
ntohl((mac_addr->addr[0] << 8) | mac_addr->addr[1])) {
+      if ((ip6addr->addr[3]  & PP_HTONL(0x0000ffff)) == 
lwip_ntohl((mac_addr->addr[0] << 8) | mac_addr->addr[1])) {
         return 3;
       }
     }
   } else if (mac_addr->addr_len == 8) {
-    if ((ip6addr->addr[2] == ntohl(((mac_addr->addr[0] ^ 2) << 24) | 
(mac_addr->addr[1] << 16) | mac_addr->addr[2] << 8 | mac_addr->addr[3])) &&
-      (ip6addr->addr[3] == ntohl((mac_addr->addr[4] << 24) | 
(mac_addr->addr[5] << 16) | mac_addr->addr[6] << 8 | mac_addr->addr[7]))) {
+    if ((ip6addr->addr[2] == lwip_ntohl(((mac_addr->addr[0] ^ 2) << 24) | 
(mac_addr->addr[1] << 16) | mac_addr->addr[2] << 8 | mac_addr->addr[3])) &&
+      (ip6addr->addr[3] == lwip_ntohl((mac_addr->addr[4] << 24) | 
(mac_addr->addr[5] << 16) | mac_addr->addr[6] << 8 | mac_addr->addr[7]))) {
       return 3;
     }
   }
@@ -611,12 +611,13 @@ lowpan4_output(struct netif *netif, struct pbuf *q, const 
ip4_addr_t *ipaddr)
  * @param q The pbuf(s) containing the IP packet to be sent.
  * @param ip6addr The IP address of the packet destination.
  *
- * @return
+ * @return err_t
  */
 err_t
 lowpan6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr)
 {
-  s8_t i;
+  err_t result;
+  const u8_t *hwaddr;
   struct ieee_802154_addr src, dest;
 #if LWIP_6LOWPAN_INFER_SHORT_ADDRESS
   ip6_addr_t ip6_src;
@@ -663,35 +664,23 @@ lowpan6_output(struct netif *netif, struct pbuf *q, const 
ip6_addr_t *ip6addr)
   }
 #endif /* LWIP_6LOWPAN_INFER_SHORT_ADDRESS */
 
-
-  /* Get next hop record. */
-  i = nd6_get_next_hop_entry(ip6addr, netif);
-  if (i < 0) {
+  /* Ask ND6 what to do with the packet. */
+  result = nd6_get_next_hop_addr_or_queue(netif, q, ip6addr, &hwaddr);
+  if (result != ERR_OK) {
     MIB2_STATS_NETIF_INC(netif, ifoutdiscards);
-    /* failed to get a next hop neighbor record. */
-    return ERR_MEM;
+    return result;
   }
 
-  /* Now that we have a destination record, send or queue the packet. */
-  if (neighbor_cache[i].state == ND6_STALE) {
-    /* Switch to delay state. */
-    neighbor_cache[i].state = ND6_DELAY;
-    neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME;
-  }
-  /* @todo should we send or queue if PROBE? send for now, to let unicast NS 
pass. */
-  if ((neighbor_cache[i].state == ND6_REACHABLE) ||
-      (neighbor_cache[i].state == ND6_DELAY) ||
-      (neighbor_cache[i].state == ND6_PROBE)) {
-
-    /* Send out. */
-    dest.addr_len = netif->hwaddr_len;
-    SMEMCPY(dest.addr, neighbor_cache[i].lladdr, netif->hwaddr_len);
-    MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
-    return lowpan6_frag(netif, q, &src, &dest);
+  /* If no hardware address is returned, nd6 has queued the packet for later. 
*/
+  if (hwaddr == NULL) {
+    return ERR_OK;
   }
 
-  /* We should queue packet on this interface. */
-  return nd6_queue_packet(i, q);
+  /* Send out the packet using the returned hardware address. */
+  dest.addr_len = netif->hwaddr_len;
+  SMEMCPY(dest.addr, hwaddr, netif->hwaddr_len);
+  MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
+  return lowpan6_frag(netif, q, &src, &dest);
 }
 
 static struct pbuf *
@@ -768,7 +757,7 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr 
* src, struct ieee_8
       ip6hdr->src.addr[0] = PP_HTONL(0xfe800000UL);
       ip6hdr->src.addr[1] = 0;
       ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL);
-      ip6hdr->src.addr[3] = htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) |
+      ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) |
                                   lowpan6_buffer[lowpan6_offset+1]);
       lowpan6_offset += 2;
     } else if ((lowpan6_buffer[1] & 0x30) == 0x30) {
@@ -776,11 +765,11 @@ lowpan6_decompress(struct pbuf * p, struct 
ieee_802154_addr * src, struct ieee_8
       ip6hdr->src.addr[1] = 0;
       if (src->addr_len == 2) {
         ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL);
-        ip6hdr->src.addr[3] = htonl(0xfe000000UL | (src->addr[0] << 8) | 
src->addr[1]);
+        ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (src->addr[0] << 8) | 
src->addr[1]);
       } else {
-        ip6hdr->src.addr[2] = htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] 
<< 16) |
+        ip6hdr->src.addr[2] = lwip_htonl(((src->addr[0] ^ 2) << 24) | 
(src->addr[1] << 16) |
                                     (src->addr[2] << 8) | src->addr[3]);
-        ip6hdr->src.addr[3] = htonl((src->addr[4] << 24) | (src->addr[5] << 
16) |
+        ip6hdr->src.addr[3] = lwip_htonl((src->addr[4] << 24) | (src->addr[5] 
<< 16) |
                                     (src->addr[6] << 8) | src->addr[7]);
       }
     }
@@ -815,15 +804,15 @@ lowpan6_decompress(struct pbuf * p, struct 
ieee_802154_addr * src, struct ieee_8
       lowpan6_offset += 8;
     } else if ((lowpan6_buffer[1] & 0x30) == 0x20) {
       ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL);
-      ip6hdr->src.addr[3] = htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset+1]);
+      ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset+1]);
       lowpan6_offset += 2;
     } else if ((lowpan6_buffer[1] & 0x30) == 0x30) {
       if (src->addr_len == 2) {
         ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL);
-        ip6hdr->src.addr[3] = htonl(0xfe000000UL | (src->addr[0] << 8) | 
src->addr[1]);
+        ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (src->addr[0] << 8) | 
src->addr[1]);
       } else {
-        ip6hdr->src.addr[2] = htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] 
<< 16) | (src->addr[2] << 8) | src->addr[3]);
-        ip6hdr->src.addr[3] = htonl((src->addr[4] << 24) | (src->addr[5] << 
16) | (src->addr[6] << 8) | src->addr[7]);
+        ip6hdr->src.addr[2] = lwip_htonl(((src->addr[0] ^ 2) << 24) | 
(src->addr[1] << 16) | (src->addr[2] << 8) | src->addr[3]);
+        ip6hdr->src.addr[3] = lwip_htonl((src->addr[4] << 24) | (src->addr[5] 
<< 16) | (src->addr[6] << 8) | src->addr[7]);
       }
     }
   }
@@ -843,22 +832,22 @@ lowpan6_decompress(struct pbuf * p, struct 
ieee_802154_addr * src, struct ieee_8
       MEMCPY(&ip6hdr->dest.addr[0], lowpan6_buffer + lowpan6_offset, 16);
       lowpan6_offset += 16;
     } else if ((lowpan6_buffer[1] & 0x03) == 0x01) {
-      ip6hdr->dest.addr[0] = htonl(0xff000000UL | 
(lowpan6_buffer[lowpan6_offset++] << 16));
+      ip6hdr->dest.addr[0] = lwip_htonl(0xff000000UL | 
(lowpan6_buffer[lowpan6_offset++] << 16));
       ip6hdr->dest.addr[1] = 0;
-      ip6hdr->dest.addr[2] = htonl(lowpan6_buffer[lowpan6_offset++]);
-      ip6hdr->dest.addr[3] = htonl((lowpan6_buffer[lowpan6_offset] << 24) | 
(lowpan6_buffer[lowpan6_offset + 1] << 16) | (lowpan6_buffer[lowpan6_offset + 
2] << 8) | lowpan6_buffer[lowpan6_offset + 3]);
+      ip6hdr->dest.addr[2] = lwip_htonl(lowpan6_buffer[lowpan6_offset++]);
+      ip6hdr->dest.addr[3] = lwip_htonl((lowpan6_buffer[lowpan6_offset] << 24) 
| (lowpan6_buffer[lowpan6_offset + 1] << 16) | (lowpan6_buffer[lowpan6_offset + 
2] << 8) | lowpan6_buffer[lowpan6_offset + 3]);
       lowpan6_offset += 4;
     } else if ((lowpan6_buffer[1] & 0x03) == 0x02) {
-      ip6hdr->dest.addr[0] = htonl(0xff000000UL | 
lowpan6_buffer[lowpan6_offset++]);
+      ip6hdr->dest.addr[0] = lwip_htonl(0xff000000UL | 
lowpan6_buffer[lowpan6_offset++]);
       ip6hdr->dest.addr[1] = 0;
       ip6hdr->dest.addr[2] = 0;
-      ip6hdr->dest.addr[3] = htonl((lowpan6_buffer[lowpan6_offset] << 16) | 
(lowpan6_buffer[lowpan6_offset + 1] << 8) | lowpan6_buffer[lowpan6_offset + 2]);
+      ip6hdr->dest.addr[3] = lwip_htonl((lowpan6_buffer[lowpan6_offset] << 16) 
| (lowpan6_buffer[lowpan6_offset + 1] << 8) | lowpan6_buffer[lowpan6_offset + 
2]);
       lowpan6_offset += 3;
     } else if ((lowpan6_buffer[1] & 0x03) == 0x03) {
       ip6hdr->dest.addr[0] = PP_HTONL(0xff020000UL);
       ip6hdr->dest.addr[1] = 0;
       ip6hdr->dest.addr[2] = 0;
-      ip6hdr->dest.addr[3] = htonl(lowpan6_buffer[lowpan6_offset++]);
+      ip6hdr->dest.addr[3] = lwip_htonl(lowpan6_buffer[lowpan6_offset++]);
     }
 
   } else {
@@ -894,15 +883,15 @@ lowpan6_decompress(struct pbuf * p, struct 
ieee_802154_addr * src, struct ieee_8
       lowpan6_offset += 8;
     } else if ((lowpan6_buffer[1] & 0x03) == 0x02) {
       ip6hdr->dest.addr[2] = PP_HTONL(0x000000ffUL);
-      ip6hdr->dest.addr[3] = htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset + 1]);
+      ip6hdr->dest.addr[3] = lwip_htonl(0xfe000000UL | 
(lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset + 1]);
       lowpan6_offset += 2;
     } else if ((lowpan6_buffer[1] & 0x03) == 0x03) {
       if (dest->addr_len == 2) {
         ip6hdr->dest.addr[2] = PP_HTONL(0x000000ffUL);
-        ip6hdr->dest.addr[3] = htonl(0xfe000000UL | (dest->addr[0] << 8) | 
dest->addr[1]);
+        ip6hdr->dest.addr[3] = lwip_htonl(0xfe000000UL | (dest->addr[0] << 8) 
| dest->addr[1]);
       } else {
-        ip6hdr->dest.addr[2] = htonl(((dest->addr[0] ^ 2) << 24) | 
(dest->addr[1] << 16) | dest->addr[2] << 8 | dest->addr[3]);
-        ip6hdr->dest.addr[3] = htonl((dest->addr[4] << 24) | (dest->addr[5] << 
16) | dest->addr[6] << 8 | dest->addr[7]);
+        ip6hdr->dest.addr[2] = lwip_htonl(((dest->addr[0] ^ 2) << 24) | 
(dest->addr[1] << 16) | dest->addr[2] << 8 | dest->addr[3]);
+        ip6hdr->dest.addr[3] = lwip_htonl((dest->addr[4] << 24) | 
(dest->addr[5] << 16) | dest->addr[6] << 8 | dest->addr[7]);
       }
     }
   }
@@ -927,26 +916,26 @@ lowpan6_decompress(struct pbuf * p, struct 
ieee_802154_addr * src, struct ieee_8
       /* Decompress ports */
       i = lowpan6_buffer[lowpan6_offset++] & 0x03;
       if (i == 0) {
-        udphdr->src = htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
-        udphdr->dest = htons(lowpan6_buffer[lowpan6_offset + 2] << 8 | 
lowpan6_buffer[lowpan6_offset + 3]);
+        udphdr->src = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
+        udphdr->dest = lwip_htons(lowpan6_buffer[lowpan6_offset + 2] << 8 | 
lowpan6_buffer[lowpan6_offset + 3]);
         lowpan6_offset += 4;
       } else if (i == 0x01) {
-        udphdr->src = htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
-        udphdr->dest = htons(0xf000 | lowpan6_buffer[lowpan6_offset + 2]);
+        udphdr->src = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
+        udphdr->dest = lwip_htons(0xf000 | lowpan6_buffer[lowpan6_offset + 2]);
         lowpan6_offset += 3;
       } else if (i == 0x02) {
-        udphdr->src = htons(0xf000 | lowpan6_buffer[lowpan6_offset]);
-        udphdr->dest = htons(lowpan6_buffer[lowpan6_offset + 1] << 8 | 
lowpan6_buffer[lowpan6_offset + 2]);
+        udphdr->src = lwip_htons(0xf000 | lowpan6_buffer[lowpan6_offset]);
+        udphdr->dest = lwip_htons(lowpan6_buffer[lowpan6_offset + 1] << 8 | 
lowpan6_buffer[lowpan6_offset + 2]);
         lowpan6_offset += 3;
       } else if (i == 0x03) {
-        udphdr->src = htons(0xf0b0 | ((lowpan6_buffer[lowpan6_offset] >> 4) & 
0x0f));
-        udphdr->dest = htons(0xf0b0 | (lowpan6_buffer[lowpan6_offset] & 0x0f));
+        udphdr->src = lwip_htons(0xf0b0 | ((lowpan6_buffer[lowpan6_offset] >> 
4) & 0x0f));
+        udphdr->dest = lwip_htons(0xf0b0 | (lowpan6_buffer[lowpan6_offset] & 
0x0f));
         lowpan6_offset += 1;
       }
 
-      udphdr->chksum = htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
+      udphdr->chksum = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | 
lowpan6_buffer[lowpan6_offset + 1]);
       lowpan6_offset += 2;
-      udphdr->len = htons(p->tot_len - lowpan6_offset + UDP_HLEN);
+      udphdr->len = lwip_htons(p->tot_len - lowpan6_offset + UDP_HLEN);
 
       ip6_offset += UDP_HLEN;
     } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/auth.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/auth.c 
b/net/ip/lwip_base/src/netif/ppp/auth.c
index 109c146..c8673ad 100644
--- a/net/ip/lwip_base/src/netif/ppp/auth.c
+++ b/net/ip/lwip_base/src/netif/ppp/auth.c
@@ -2121,10 +2121,10 @@ set_allowed_addrs(unit, addrs, opts)
        } else {
            np = getnetbyname (ptr_word);
            if (np != NULL && np->n_addrtype == AF_INET) {
-               a = htonl ((u32_t)np->n_net);
+               a = lwip_htonl ((u32_t)np->n_net);
                if (ptr_mask == NULL) {
                    /* calculate appropriate mask for net */
-                   ah = ntohl(a);
+                   ah = lwip_ntohl(a);
                    if (IN_CLASSA(ah))
                        mask = IN_CLASSA_NET;
                    else if (IN_CLASSB(ah))
@@ -2150,10 +2150,10 @@ set_allowed_addrs(unit, addrs, opts)
                     ifunit, ptr_word);
                continue;
            }
-           a = htonl((ntohl(a) & mask) + offset);
+           a = lwip_htonl((lwip_ntohl(a) & mask) + offset);
            mask = ~(u32_t)0;
        }
-       ip[n].mask = htonl(mask);
+       ip[n].mask = lwip_htonl(mask);
        ip[n].base = a & ip[n].mask;
        ++n;
        if (~mask == 0 && suggested_ip == 0)
@@ -2234,7 +2234,7 @@ int
 bad_ip_adrs(addr)
     u32_t addr;
 {
-    addr = ntohl(addr);
+    addr = lwip_ntohl(addr);
     return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
        || IN_MULTICAST(addr) || IN_BADCLASS(addr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/ipcp.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/ipcp.c 
b/net/ip/lwip_base/src/netif/ppp/ipcp.c
index 2cdcba8..b7c766e 100644
--- a/net/ip/lwip_base/src/netif/ppp/ipcp.c
+++ b/net/ip/lwip_base/src/netif/ppp/ipcp.c
@@ -350,11 +350,8 @@ setvjslots(argv)
 {
     int value;
 
-/* FIXME: found what int_option() did */
-#if PPP_OPTIONS
     if (!int_option(*argv, &value))
        return 0;
-#endif /* PPP_OPTIONS */
 
     if (value < 2 || value > 16) {
        option_error("vj-max-slots value must be between 2 and 16");
@@ -542,7 +539,7 @@ setnetmask(argv)
     p = *argv;
     n = parse_dotted_ip(p, &mask);
 
-    mask = htonl(mask);
+    mask = lwip_htonl(mask);
 
     if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
        option_error("invalid netmask value '%s'", *argv);
@@ -728,13 +725,8 @@ static void ipcp_resetci(fsm *f) {
     wo->req_dns1 = wo->req_dns2 = pcb->settings.usepeerdns;    /* Request DNS 
addresses from the peer */
 #endif /* LWIP_DNS */
     *go = *wo;
-#if 0 /* UNUSED */
-    /* We don't need ask_for_local, this is only useful for setup which
-     * can determine the local IP address from the system hostname.
-     */
-    if (!ask_for_local)
+    if (!pcb->ask_for_local)
        go->ouraddr = 0;
-#endif /* UNUSED */
 #if 0 /* UNUSED */
     if (ip_choose_hook) {
        ip_choose_hook(&wo->hisaddr);
@@ -822,9 +814,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) {
            u32_t l; \
            PUTCHAR(opt, ucp); \
            PUTCHAR(CILEN_ADDRS, ucp); \
-           l = ntohl(val1); \
+           l = lwip_ntohl(val1); \
            PUTLONG(l, ucp); \
-           l = ntohl(val2); \
+           l = lwip_ntohl(val2); \
            PUTLONG(l, ucp); \
            len -= CILEN_ADDRS; \
        } else \
@@ -855,7 +847,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) {
            u32_t l; \
            PUTCHAR(opt, ucp); \
            PUTCHAR(CILEN_ADDR, ucp); \
-           l = ntohl(val); \
+           l = lwip_ntohl(val); \
            PUTLONG(l, ucp); \
            len -= CILEN_ADDR; \
        } else \
@@ -869,7 +861,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) {
            u32_t l; \
            PUTCHAR(opt, ucp); \
            PUTCHAR(CILEN_ADDR, ucp); \
-           l = ntohl(addr); \
+           l = lwip_ntohl(addr); \
            PUTLONG(l, ucp); \
            len -= CILEN_ADDR; \
        } else \
@@ -884,7 +876,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) {
            u32_t l; \
            PUTCHAR(opt, ucp); \
            PUTCHAR(CILEN_ADDR, ucp); \
-           l = ntohl(addr); \
+           l = lwip_ntohl(addr); \
            PUTLONG(l, ucp); \
            len -= CILEN_ADDR; \
        } else \
@@ -953,11 +945,11 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) {
            citype != opt) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        if (val1 != cilong) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        if (val2 != cilong) \
            goto bad; \
     }
@@ -998,7 +990,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) {
            citype != opt) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        if (val != cilong) \
            goto bad; \
     }
@@ -1014,7 +1006,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) {
        if (cilen != CILEN_ADDR || citype != opt) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        if (addr != cilong) \
            goto bad; \
     }
@@ -1031,7 +1023,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) {
        if (cilen != CILEN_ADDR || citype != opt) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        if (addr != cilong) \
            goto bad; \
     }
@@ -1112,9 +1104,9 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       ciaddr1 = htonl(l); \
+       ciaddr1 = lwip_htonl(l); \
        GETLONG(l, p); \
-       ciaddr2 = htonl(l); \
+       ciaddr2 = lwip_htonl(l); \
        no.old_addrs = 1; \
        code \
     }
@@ -1141,7 +1133,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       ciaddr1 = htonl(l); \
+       ciaddr1 = lwip_htonl(l); \
        no.neg = 1; \
        code \
     }
@@ -1155,7 +1147,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       cidnsaddr = htonl(l); \
+       cidnsaddr = lwip_htonl(l); \
        no.neg = 1; \
        code \
     }
@@ -1271,11 +1263,11 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
                goto bad;
            try_.neg_addr = 0;
            GETLONG(l, p);
-           ciaddr1 = htonl(l);
+           ciaddr1 = lwip_htonl(l);
            if (ciaddr1 && go->accept_local)
                try_.ouraddr = ciaddr1;
            GETLONG(l, p);
-           ciaddr2 = htonl(l);
+           ciaddr2 = lwip_htonl(l);
            if (ciaddr2 && go->accept_remote)
                try_.hisaddr = ciaddr2;
            no.old_addrs = 1;
@@ -1285,7 +1277,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
                goto bad;
            try_.old_addrs = 0;
            GETLONG(l, p);
-           ciaddr1 = htonl(l);
+           ciaddr1 = lwip_htonl(l);
            if (ciaddr1 && go->accept_local)
                try_.ouraddr = ciaddr1;
            if (try_.ouraddr != 0)
@@ -1297,7 +1289,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
            if (go->req_dns1 || no.req_dns1 || cilen != CILEN_ADDR)
                goto bad;
            GETLONG(l, p);
-           try_.dnsaddr[0] = htonl(l);
+           try_.dnsaddr[0] = lwip_htonl(l);
            try_.req_dns1 = 1;
            no.req_dns1 = 1;
            break;
@@ -1305,7 +1297,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
            if (go->req_dns2 || no.req_dns2 || cilen != CILEN_ADDR)
                goto bad;
            GETLONG(l, p);
-           try_.dnsaddr[1] = htonl(l);
+           try_.dnsaddr[1] = lwip_htonl(l);
            try_.req_dns2 = 1;
            no.req_dns2 = 1;
            break;
@@ -1316,7 +1308,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int 
treat_as_reject) {
            if (cilen != CILEN_ADDR)
                goto bad;
            GETLONG(l, p);
-           ciaddr1 = htonl(l);
+           ciaddr1 = lwip_htonl(l);
            if (ciaddr1)
                try_.winsaddr[citype == CI_MS_WINS2] = ciaddr1;
            break;
@@ -1372,12 +1364,12 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        /* Check rejected value. */ \
        if (cilong != val1) \
            goto bad; \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        /* Check rejected value. */ \
        if (cilong != val2) \
            goto bad; \
@@ -1417,7 +1409,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        /* Check rejected value. */ \
        if (cilong != val) \
            goto bad; \
@@ -1434,7 +1426,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        /* Check rejected value. */ \
        if (cilong != dnsaddr) \
            goto bad; \
@@ -1452,7 +1444,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) {
        len -= cilen; \
        INCPTR(2, p); \
        GETLONG(l, p); \
-       cilong = htonl(l); \
+       cilong = lwip_htonl(l); \
        /* Check rejected value. */ \
        if (cilong != addr) \
            goto bad; \
@@ -1575,13 +1567,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, 
int reject_if_disagree) {
             * then accept it.
             */
            GETLONG(tl, p);             /* Parse source address (his) */
-           ciaddr1 = htonl(tl);
+           ciaddr1 = lwip_htonl(tl);
            if (ciaddr1 != wo->hisaddr
                && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
                    DECPTR(sizeof(u32_t), p);
-                   tl = ntohl(wo->hisaddr);
+                   tl = lwip_ntohl(wo->hisaddr);
                    PUTLONG(tl, p);
                }
            } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
@@ -1598,13 +1590,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, 
int reject_if_disagree) {
             * but disagree about it, then NAK it with our idea.
             */
            GETLONG(tl, p);             /* Parse desination address (ours) */
-           ciaddr2 = htonl(tl);
+           ciaddr2 = lwip_htonl(tl);
            if (ciaddr2 != wo->ouraddr) {
                if (ciaddr2 == 0 || !wo->accept_local) {
                    orc = CONFNAK;
                    if (!reject_if_disagree) {
                        DECPTR(sizeof(u32_t), p);
-                       tl = ntohl(wo->ouraddr);
+                       tl = lwip_ntohl(wo->ouraddr);
                        PUTLONG(tl, p);
                    }
                } else {
@@ -1631,13 +1623,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, 
int reject_if_disagree) {
             * then accept it.
             */
            GETLONG(tl, p);     /* Parse source address (his) */
-           ciaddr1 = htonl(tl);
+           ciaddr1 = lwip_htonl(tl);
            if (ciaddr1 != wo->hisaddr
                && (ciaddr1 == 0 || !wo->accept_remote)) {
                orc = CONFNAK;
                if (!reject_if_disagree) {
                    DECPTR(sizeof(u32_t), p);
-                   tl = ntohl(wo->hisaddr);
+                   tl = lwip_ntohl(wo->hisaddr);
                    PUTLONG(tl, p);
                }
            } else if (ciaddr1 == 0 && wo->hisaddr == 0) {
@@ -1666,9 +1658,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int 
reject_if_disagree) {
                break;
            }
            GETLONG(tl, p);
-           if (htonl(tl) != ao->dnsaddr[d]) {
+           if (lwip_htonl(tl) != ao->dnsaddr[d]) {
                 DECPTR(sizeof(u32_t), p);
-               tl = ntohl(ao->dnsaddr[d]);
+               tl = lwip_ntohl(ao->dnsaddr[d]);
                PUTLONG(tl, p);
                orc = CONFNAK;
             }
@@ -1688,9 +1680,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int 
reject_if_disagree) {
                break;
            }
            GETLONG(tl, p);
-           if (htonl(tl) != ao->winsaddr[d]) {
+           if (lwip_htonl(tl) != ao->winsaddr[d]) {
                 DECPTR(sizeof(u32_t), p);
-               tl = ntohl(ao->winsaddr[d]);
+               tl = lwip_ntohl(ao->winsaddr[d]);
                PUTLONG(tl, p);
                orc = CONFNAK;
             }
@@ -1793,7 +1785,7 @@ endswitch:
        }
        PUTCHAR(CI_ADDR, ucp);
        PUTCHAR(CILEN_ADDR, ucp);
-       tl = ntohl(wo->hisaddr);
+       tl = lwip_ntohl(wo->hisaddr);
        PUTLONG(tl, ucp);
     }
 
@@ -1850,12 +1842,12 @@ ip_demand_conf(u)
 
     if (wo->hisaddr == 0 && !pcb->settings.noremoteip) {
        /* make up an arbitrary address for the peer */
-       wo->hisaddr = htonl(0x0a707070 + ifunit);
+       wo->hisaddr = lwip_htonl(0x0a707070 + ifunit);
        wo->accept_remote = 1;
     }
     if (wo->ouraddr == 0) {
        /* make up an arbitrary address for us */
-       wo->ouraddr = htonl(0x0a404040 + ifunit);
+       wo->ouraddr = lwip_htonl(0x0a404040 + ifunit);
        wo->accept_local = 1;
        ask_for_local = 0;      /* don't tell the peer this address */
     }
@@ -1917,7 +1909,7 @@ static void ipcp_up(fsm *f) {
        return;
     }
     if (ho->hisaddr == 0 && !pcb->settings.noremoteip) {
-       ho->hisaddr = htonl(0x0a404040);
+       ho->hisaddr = lwip_htonl(0x0a404040);
        ppp_warn("Could not determine remote IP address: defaulting to %I",
             ho->hisaddr);
     }
@@ -1947,11 +1939,29 @@ static void ipcp_up(fsm *f) {
     }
 #endif /* LWIP_DNS */
 
-/* FIXME: check why it fails, just to know */
-#if 0 /* Unused */
     /*
      * Check that the peer is allowed to use the IP address it wants.
      */
+    if (ho->hisaddr != 0) {
+       u32_t addr = lwip_ntohl(ho->hisaddr);
+       if ((addr >> IP_CLASSA_NSHIFT) == IP_LOOPBACKNET
+           || IP_MULTICAST(addr) || IP_BADCLASS(addr)
+           /*
+            * For now, consider that PPP in server mode with peer required
+            * to authenticate must provide the peer IP address, reject any
+            * IP address wanted by peer different than the one we wanted.
+            */
+#if PPP_SERVER && PPP_AUTH_SUPPORT
+           || (pcb->settings.auth_required && wo->hisaddr != ho->hisaddr)
+#endif /* PPP_SERVER && PPP_AUTH_SUPPORT */
+           ) {
+               ppp_error("Peer is not authorized to use remote address %I", 
ho->hisaddr);
+               ipcp_close(pcb, "Unauthorized remote IP address");
+               return;
+       }
+    }
+#if 0 /* Unused */
+    /* Upstream checking code */
     if (ho->hisaddr != 0 && !auth_ip_addr(f->unit, ho->hisaddr)) {
        ppp_error("Peer is not authorized to use remote address %I", 
ho->hisaddr);
        ipcp_close(f->unit, "Unauthorized remote IP address");
@@ -2271,9 +2281,9 @@ static int ipcp_printpkt(const u_char *p, int plen,
                if (olen == CILEN_ADDRS) {
                    p += 2;
                    GETLONG(cilong, p);
-                   printer(arg, "addrs %I", htonl(cilong));
+                   printer(arg, "addrs %I", lwip_htonl(cilong));
                    GETLONG(cilong, p);
-                   printer(arg, " %I", htonl(cilong));
+                   printer(arg, " %I", lwip_htonl(cilong));
                }
                break;
 #if VJ_SUPPORT
@@ -2299,7 +2309,7 @@ static int ipcp_printpkt(const u_char *p, int plen,
                if (olen == CILEN_ADDR) {
                    p += 2;
                    GETLONG(cilong, p);
-                   printer(arg, "addr %I", htonl(cilong));
+                   printer(arg, "addr %I", lwip_htonl(cilong));
                }
                break;
 #if LWIP_DNS
@@ -2316,7 +2326,7 @@ static int ipcp_printpkt(const u_char *p, int plen,
            case CI_MS_WINS2:
                p += 2;
                GETLONG(cilong, p);
-               printer(arg, "ms-wins %I", htonl(cilong));
+               printer(arg, "ms-wins %I", lwip_htonl(cilong));
                break;
 #endif /* UNUSED - WINS */
            default:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/ipv6cp.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/ipv6cp.c 
b/net/ip/lwip_base/src/netif/ppp/ipv6cp.c
index f0f4eee..11c18df 100644
--- a/net/ip/lwip_base/src/netif/ppp/ipv6cp.c
+++ b/net/ip/lwip_base/src/netif/ppp/ipv6cp.c
@@ -1093,7 +1093,7 @@ static void ipv6_check_options() {
 
     if (!wo->opt_local) {      /* init interface identifier */
        if (wo->use_ip && eui64_iszero(wo->ourid)) {
-           eui64_setlo32(wo->ourid, ntohl(ipcp_wantoptions[0].ouraddr));
+           eui64_setlo32(wo->ourid, lwip_ntohl(ipcp_wantoptions[0].ouraddr));
            if (!eui64_iszero(wo->ourid))
                wo->opt_local = 1;
        }
@@ -1104,7 +1104,7 @@ static void ipv6_check_options() {
 
     if (!wo->opt_remote) {
        if (wo->use_ip && eui64_iszero(wo->hisid)) {
-           eui64_setlo32(wo->hisid, ntohl(ipcp_wantoptions[0].hisaddr));
+           eui64_setlo32(wo->hisid, lwip_ntohl(ipcp_wantoptions[0].hisaddr));
            if (!eui64_iszero(wo->hisid))
                wo->opt_remote = 1;
        }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/multilink.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/multilink.c 
b/net/ip/lwip_base/src/netif/ppp/multilink.c
index 0d617a0..62014e8 100644
--- a/net/ip/lwip_base/src/netif/ppp/multilink.c
+++ b/net/ip/lwip_base/src/netif/ppp/multilink.c
@@ -469,7 +469,7 @@ get_default_epdisc(ep)
        if (hp != NULL) {
                addr = *(u32_t *)hp->h_addr;
                if (!bad_ip_adrs(addr)) {
-                       addr = ntohl(addr);
+                       addr = lwip_ntohl(addr);
                        if (!LOCAL_IP_ADDR(addr)) {
                                ep->class = EPD_IP;
                                set_ip_epdisc(ep, addr);
@@ -504,7 +504,7 @@ epdisc_to_str(ep)
                u32_t addr;
 
                GETLONG(addr, p);
-               slprintf(str, sizeof(str), "IP:%I", htonl(addr));
+               slprintf(str, sizeof(str), "IP:%I", lwip_htonl(addr));
                return str;
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/ppp.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/ppp.c 
b/net/ip/lwip_base/src/netif/ppp/ppp.c
index 2f6ae11..8b77765 100644
--- a/net/ip/lwip_base/src/netif/ppp/ppp.c
+++ b/net/ip/lwip_base/src/netif/ppp/ppp.c
@@ -275,8 +275,8 @@ err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) {
   PPPDEBUG(LOG_DEBUG, ("ppp_connect[%d]: holdoff=%d\n", pcb->netif->num, 
holdoff));
 
   if (holdoff == 0) {
-    new_phase(pcb, PPP_PHASE_INITIALIZE);
-    return pcb->link_cb->connect(pcb, pcb->link_ctx_cb);
+    ppp_do_connect(pcb);
+    return ERR_OK;
   }
 
   new_phase(pcb, PPP_PHASE_HOLDOFF);
@@ -302,7 +302,8 @@ err_t ppp_listen(ppp_pcb *pcb) {
 
   if (pcb->link_cb->listen) {
     new_phase(pcb, PPP_PHASE_INITIALIZE);
-    return pcb->link_cb->listen(pcb, pcb->link_ctx_cb);
+    pcb->link_cb->listen(pcb, pcb->link_ctx_cb);
+    return ERR_OK;
   }
   return ERR_IF;
 }
@@ -695,7 +696,7 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct 
link_callbacks *callbacks, vo
   MIB2_INIT_NETIF(pppif, snmp_ifType_ppp, 0);
   if (!netif_add(pcb->netif,
 #if LWIP_IPV4
-                 IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY,
+                 IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4,
 #endif /* LWIP_IPV4 */
                  (void *)pcb, ppp_netif_init_cb, NULL)) {
     LWIP_MEMPOOL_FREE(PPP_PCB, pcb);
@@ -1090,7 +1091,7 @@ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) {
   LWIP_UNUSED_ARG(our_adr);
   LWIP_UNUSED_ARG(his_adr);
 
-  netif_set_addr(pcb->netif, IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY);
+  netif_set_addr(pcb->netif, IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4);
   return 1;
 }
 
@@ -1219,7 +1220,7 @@ u32_t get_mask(u32_t addr) {
 #if 0
   u32_t mask, nmask;
 
-  addr = htonl(addr);
+  addr = lwip_htonl(addr);
   if (IP_CLASSA(addr)) { /* determine network mask for address class */
     nmask = IP_CLASSA_NET;
   } else if (IP_CLASSB(addr)) {
@@ -1229,7 +1230,7 @@ u32_t get_mask(u32_t addr) {
   }
 
   /* class D nets are disallowed by bad_ip_adrs */
-  mask = PP_HTONL(0xffffff00UL) | htonl(nmask);
+  mask = PP_HTONL(0xffffff00UL) | lwip_htonl(nmask);
 
   /* XXX
    * Scan through the system's network interfaces.
@@ -1447,7 +1448,7 @@ int get_loop_output(void) {
 struct protocol_list {
   u_short proto;
   const char *name;
-} protocol_list[] = {
+} const protocol_list[] = {
   { 0x21, "IP" },
   { 0x23, "OSI Network Layer" },
   { 0x25, "Xerox NS IDP" },
@@ -1582,7 +1583,7 @@ struct protocol_list {
  * protocol_name - find a name for a PPP protocol.
  */
 const char * protocol_name(int proto) {
-  struct protocol_list *lp;
+  const struct protocol_list *lp;
 
   for (lp = protocol_list; lp->proto != 0; ++lp) {
     if (proto == lp->proto) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/pppapi.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/pppapi.c 
b/net/ip/lwip_base/src/netif/ppp/pppapi.c
index e2bedc7..947f7ba 100644
--- a/net/ip/lwip_base/src/netif/ppp/pppapi.c
+++ b/net/ip/lwip_base/src/netif/ppp/pppapi.c
@@ -222,6 +222,7 @@ pppapi_do_pppol2tp_create(struct tcpip_api_call_data *m)
     msg->msg.msg.l2tpcreate.secret_len,
 #else /* PPPOL2TP_AUTH_SUPPORT */
     NULL,
+    0,
 #endif /* PPPOL2TP_AUTH_SUPPORT */
     msg->msg.msg.l2tpcreate.link_status_cb, msg->msg.msg.l2tpcreate.ctx_cb);
   return ERR_OK;
@@ -239,6 +240,10 @@ pppapi_pppol2tp_create(struct netif *pppif, struct netif 
*netif, ip_addr_t *ipad
   ppp_pcb* result;
   PPPAPI_VAR_DECLARE(msg);
   PPPAPI_VAR_ALLOC_RETURN_NULL(msg);
+#if !PPPOL2TP_AUTH_SUPPORT
+  LWIP_UNUSED_ARG(secret);
+  LWIP_UNUSED_ARG(secret_len);
+#endif /* !PPPOL2TP_AUTH_SUPPORT */
 
   PPPAPI_VAR_REF(msg).msg.ppp = NULL;
   PPPAPI_VAR_REF(msg).msg.msg.l2tpcreate.pppif = pppif;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/pppoe.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/pppoe.c 
b/net/ip/lwip_base/src/netif/ppp/pppoe.c
index 768d22b..eabfa4d 100644
--- a/net/ip/lwip_base/src/netif/ppp/pppoe.c
+++ b/net/ip/lwip_base/src/netif/ppp/pppoe.c
@@ -119,7 +119,7 @@ LWIP_MEMPOOL_DECLARE(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, 
sizeof(struct pppoe_so
 /* callbacks called from PPP core */
 static err_t pppoe_write(ppp_pcb *ppp, void *ctx, struct pbuf *p);
 static err_t pppoe_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, 
u_short protocol);
-static err_t pppoe_connect(ppp_pcb *ppp, void *ctx);
+static void pppoe_connect(ppp_pcb *ppp, void *ctx);
 static void pppoe_disconnect(ppp_pcb *ppp, void *ctx);
 static err_t pppoe_destroy(ppp_pcb *ppp, void *ctx);
 
@@ -419,8 +419,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb)
     PPPDEBUG(LOG_DEBUG, ("pppoe: unknown version/type packet: 0x%x\n", 
ph->vertype));
     goto done;
   }
-  session = ntohs(ph->session);
-  plen = ntohs(ph->plen);
+  session = lwip_ntohs(ph->session);
+  plen = lwip_ntohs(ph->plen);
   off += sizeof(*ph);
 
   if (plen + off > pb->len) {
@@ -436,8 +436,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb)
   sc = NULL;
   while (off + sizeof(pt) <= pb->len) {
     MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt));
-    tag = ntohs(pt.tag);
-    len = ntohs(pt.len);
+    tag = lwip_ntohs(pt.tag);
+    len = lwip_ntohs(pt.len);
     if (off + sizeof(pt) + len > pb->len) {
       PPPDEBUG(LOG_DEBUG, ("pppoe: tag 0x%x len 0x%x is too long\n", tag, 
len));
       goto done;
@@ -680,7 +680,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb)
     goto drop;
   }
 
-  session = ntohs(ph->session);
+  session = lwip_ntohs(ph->session);
   sc = pppoe_find_softc_by_session(session, netif);
   if (sc == NULL) {
 #ifdef PPPOE_TERM_UNKNOWN_SESSIONS
@@ -690,7 +690,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb)
     goto drop;
   }
 
-  plen = ntohs(ph->plen);
+  plen = lwip_ntohs(ph->plen);
 
   if (pbuf_header(pb, -(s16_t)(PPPOE_HEADERLEN)) != 0) {
     /* bail out */
@@ -732,7 +732,7 @@ pppoe_output(struct pppoe_softc *sc, struct pbuf *pb)
   }
   ethhdr = (struct eth_hdr *)pb->payload;
   etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : 
ETHTYPE_PPPOEDISC;
-  ethhdr->type = htons(etype);
+  ethhdr->type = lwip_htons(etype);
   MEMCPY(&ethhdr->dest.addr, &sc->sc_dest.addr, sizeof(ethhdr->dest.addr));
   MEMCPY(&ethhdr->src.addr, &sc->sc_ethif->hwaddr, sizeof(ethhdr->src.addr));
 
@@ -879,7 +879,7 @@ pppoe_timeout(void *arg)
 }
 
 /* Start a connection (i.e. initiate discovery phase) */
-static err_t
+static void
 pppoe_connect(ppp_pcb *ppp, void *ctx)
 {
   err_t err;
@@ -934,7 +934,6 @@ pppoe_connect(ppp_pcb *ppp, void *ctx)
     PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": failed to send PADI, 
error=%d\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, 
err));
   }
   sys_timeout(PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
-  return err;
 }
 
 /* disconnect */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/pppol2tp.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/pppol2tp.c 
b/net/ip/lwip_base/src/netif/ppp/pppol2tp.c
index 7ecbe9e..d44471e 100644
--- a/net/ip/lwip_base/src/netif/ppp/pppol2tp.c
+++ b/net/ip/lwip_base/src/netif/ppp/pppol2tp.c
@@ -73,7 +73,7 @@ LWIP_MEMPOOL_DECLARE(PPPOL2TP_PCB, 
MEMP_NUM_PPPOL2TP_INTERFACES, sizeof(pppol2tp
 static err_t pppol2tp_write(ppp_pcb *ppp, void *ctx, struct pbuf *p);
 static err_t pppol2tp_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *p, 
u_short protocol);
 static err_t pppol2tp_destroy(ppp_pcb *ppp, void *ctx);    /* Destroy a L2TP 
control block */
-static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx);    /* Be a LAC, 
connect to a LNS. */
+static void pppol2tp_connect(ppp_pcb *ppp, void *ctx);    /* Be a LAC, connect 
to a LNS. */
 static void pppol2tp_disconnect(ppp_pcb *ppp, void *ctx);  /* Disconnect */
 
  /* Prototypes for procedures local to this file. */
@@ -113,6 +113,10 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
   ppp_pcb *ppp;
   pppol2tp_pcb *l2tp;
   struct udp_pcb *udp;
+#if !PPPOL2TP_AUTH_SUPPORT
+  LWIP_UNUSED_ARG(secret);
+  LWIP_UNUSED_ARG(secret_len);
+#endif /* !PPPOL2TP_AUTH_SUPPORT */
 
   if (ipaddr == NULL) {
     goto ipaddr_check_failed;
@@ -251,7 +255,7 @@ static err_t pppol2tp_destroy(ppp_pcb *ppp, void *ctx) {
 }
 
 /* Be a LAC, connect to a LNS. */
-static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) {
+static void pppol2tp_connect(ppp_pcb *ppp, void *ctx) {
   err_t err;
   pppol2tp_pcb *l2tp = (pppol2tp_pcb *)ctx;
   lcp_options *lcp_wo;
@@ -322,7 +326,6 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) {
     PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCRQ, error=%d\n", err));
   }
   sys_timeout(PPPOL2TP_CONTROL_TIMEOUT, pppol2tp_timeout, l2tp);
-  return err;
 }
 
 /* Disconnect */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/pppos.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/pppos.c 
b/net/ip/lwip_base/src/netif/ppp/pppos.c
index b4d435e..fb48df4 100644
--- a/net/ip/lwip_base/src/netif/ppp/pppos.c
+++ b/net/ip/lwip_base/src/netif/ppp/pppos.c
@@ -35,8 +35,8 @@
 #if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in 
lwipopts.h */
 
 #include <string.h>
-#include <stddef.h>
 
+#include "lwip/arch.h"
 #include "lwip/err.h"
 #include "lwip/pbuf.h"
 #include "lwip/sys.h"
@@ -57,9 +57,9 @@ LWIP_MEMPOOL_DECLARE(PPPOS_PCB, MEMP_NUM_PPPOS_INTERFACES, 
sizeof(pppos_pcb), "P
 /* callbacks called from PPP core */
 static err_t pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p);
 static err_t pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, 
u16_t protocol);
-static err_t pppos_connect(ppp_pcb *ppp, void *ctx);
+static void pppos_connect(ppp_pcb *ppp, void *ctx);
 #if PPP_SERVER
-static err_t pppos_listen(ppp_pcb *ppp, void *ctx);
+static void pppos_listen(ppp_pcb *ppp, void *ctx);
 #endif /* PPP_SERVER */
 static void pppos_disconnect(ppp_pcb *ppp, void *ctx);
 static err_t pppos_destroy(ppp_pcb *ppp, void *ctx);
@@ -298,7 +298,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf 
*pb, u16_t protocol)
   return err;
 }
 
-static err_t
+static void
 pppos_connect(ppp_pcb *ppp, void *ctx)
 {
   pppos_pcb *pppos = (pppos_pcb *)ctx;
@@ -327,11 +327,10 @@ pppos_connect(ppp_pcb *ppp, void *ctx)
    */
   PPPDEBUG(LOG_INFO, ("pppos_connect: unit %d: connecting\n", 
ppp->netif->num));
   ppp_start(ppp); /* notify upper layers */
-  return ERR_OK;
 }
 
 #if PPP_SERVER
-static err_t
+static void
 pppos_listen(ppp_pcb *ppp, void *ctx)
 {
   pppos_pcb *pppos = (pppos_pcb *)ctx;
@@ -360,7 +359,6 @@ pppos_listen(ppp_pcb *ppp, void *ctx)
    */
   PPPDEBUG(LOG_INFO, ("pppos_listen: unit %d: listening\n", ppp->netif->num));
   ppp_start(ppp); /* notify upper layers */
-  return ERR_OK;
 }
 #endif /* PPP_SERVER */
 
@@ -404,9 +402,9 @@ pppos_destroy(ppp_pcb *ppp, void *ctx)
 #if !NO_SYS && !PPP_INPROC_IRQ_SAFE
 /** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP 
thread.
  *
- * @param pcb PPP descriptor index, returned by pppos_create()
- * @param data received data
- * @param len length of received data
+ * @param ppp PPP descriptor index, returned by pppos_create()
+ * @param s received data
+ * @param l length of received data
  */
 err_t
 pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l)
@@ -458,9 +456,9 @@ PACK_STRUCT_END
 
 /** Pass received raw characters to PPPoS to be decoded.
  *
- * @param pcb PPP descriptor index, returned by pppos_create()
- * @param data received data
- * @param len length of received data
+ * @param ppp PPP descriptor index, returned by pppos_create()
+ * @param s received data
+ * @param l length of received data
  */
 void
 pppos_input(ppp_pcb *ppp, u8_t *s, int l)
@@ -471,18 +469,20 @@ pppos_input(ppp_pcb *ppp, u8_t *s, int l)
   u8_t escaped;
   PPPOS_DECL_PROTECT(lev);
 
-  PPPOS_PROTECT(lev);
-  if (!pppos->open) {
-    PPPOS_UNPROTECT(lev);
-    return;
-  }
-  PPPOS_UNPROTECT(lev);
-
   PPPDEBUG(LOG_DEBUG, ("pppos_input[%d]: got %d bytes\n", ppp->netif->num, l));
   while (l-- > 0) {
     cur_char = *s++;
 
     PPPOS_PROTECT(lev);
+    /* ppp_input can disconnect the interface, we need to abort to prevent a 
memory
+     * leak if there are remaining bytes because pppos_connect and pppos_listen
+     * functions expect input buffer to be free. Furthermore there are no real
+     * reason to continue reading bytes if we are disconnected.
+     */
+    if (!pppos->open) {
+      PPPOS_UNPROTECT(lev);
+      return;
+    }
     escaped = ESCAPE_P(pppos->in_accm, cur_char);
     PPPOS_UNPROTECT(lev);
     /* Handle special characters. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/utils.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/utils.c 
b/net/ip/lwip_base/src/netif/ppp/utils.c
index 1d44e9c..008c633 100644
--- a/net/ip/lwip_base/src/netif/ppp/utils.c
+++ b/net/ip/lwip_base/src/netif/ppp/utils.c
@@ -247,11 +247,13 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, 
va_list args) {
            val = va_arg(args, unsigned int);
            base = 16;
            break;
+#if 0 /* unused (and wrong on LLP64 systems) */
        case 'p':
            val = (unsigned long) va_arg(args, void *);
            base = 16;
            neg = 2;
            break;
+#endif /* unused (and wrong on LLP64 systems) */
        case 's':
            str = va_arg(args, char *);
            break;
@@ -267,7 +269,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, 
va_list args) {
 #endif /* do we always have strerror() in embedded ? */
        case 'I':
            ip = va_arg(args, u32_t);
-           ip = ntohl(ip);
+           ip = lwip_ntohl(ip);
            ppp_slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff,
                     (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
            str = num;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/ppp/vj.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/ppp/vj.c 
b/net/ip/lwip_base/src/netif/ppp/vj.c
index dadb38d..168c340 100644
--- a/net/ip/lwip_base/src/netif/ppp/vj.c
+++ b/net/ip/lwip_base/src/netif/ppp/vj.c
@@ -95,32 +95,32 @@ vj_compress_init(struct vjcompress *comp)
 
 #define DECODEL(f) { \
   if (*cp == 0) {\
-    u32_t tmp_ = ntohl(f) + ((cp[1] << 8) | cp[2]); \
-    (f) = htonl(tmp_); \
+    u32_t tmp_ = lwip_ntohl(f) + ((cp[1] << 8) | cp[2]); \
+    (f) = lwip_htonl(tmp_); \
     cp += 3; \
   } else { \
-    u32_t tmp_ = ntohl(f) + (u32_t)*cp++; \
-    (f) = htonl(tmp_); \
+    u32_t tmp_ = lwip_ntohl(f) + (u32_t)*cp++; \
+    (f) = lwip_htonl(tmp_); \
   } \
 }
 
 #define DECODES(f) { \
   if (*cp == 0) {\
-    u16_t tmp_ = ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \
-    (f) = htons(tmp_); \
+    u16_t tmp_ = lwip_ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \
+    (f) = lwip_htons(tmp_); \
     cp += 3; \
   } else { \
-    u16_t tmp_ = ntohs(f) + (u16_t)*cp++; \
-    (f) = htons(tmp_); \
+    u16_t tmp_ = lwip_ntohs(f) + (u16_t)*cp++; \
+    (f) = lwip_htons(tmp_); \
   } \
 }
 
 #define DECODEU(f) { \
   if (*cp == 0) {\
-    (f) = htons(((u16_t)cp[1] << 8) | cp[2]); \
+    (f) = lwip_htons(((u16_t)cp[1] << 8) | cp[2]); \
     cp += 3; \
   } else { \
-    (f) = htons((u16_t)*cp++); \
+    (f) = lwip_htons((u16_t)*cp++); \
   } \
 }
 
@@ -306,7 +306,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
    * needed in this section of code).
    */
   if (TCPH_FLAGS(th) & TCP_URG) {
-    deltaS = ntohs(th->urgp);
+    deltaS = lwip_ntohs(th->urgp);
     ENCODEZ(deltaS);
     changes |= NEW_U;
   } else if (th->urgp != oth->urgp) {
@@ -317,12 +317,12 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
     goto uncompressed;
   }
 
-  if ((deltaS = (u16_t)(ntohs(th->wnd) - ntohs(oth->wnd))) != 0) {
+  if ((deltaS = (u16_t)(lwip_ntohs(th->wnd) - lwip_ntohs(oth->wnd))) != 0) {
     ENCODE(deltaS);
     changes |= NEW_W;
   }
 
-  if ((deltaL = ntohl(th->ackno) - ntohl(oth->ackno)) != 0) {
+  if ((deltaL = lwip_ntohl(th->ackno) - lwip_ntohl(oth->ackno)) != 0) {
     if (deltaL > 0xffff) {
       goto uncompressed;
     }
@@ -331,7 +331,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
     changes |= NEW_A;
   }
 
-  if ((deltaL = ntohl(th->seqno) - ntohl(oth->seqno)) != 0) {
+  if ((deltaL = lwip_ntohl(th->seqno) - lwip_ntohl(oth->seqno)) != 0) {
     if (deltaL > 0xffff) {
       goto uncompressed;
     }
@@ -351,7 +351,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
      * in case the other side missed the compressed version.
      */
     if (IPH_LEN(ip) != IPH_LEN(&cs->cs_ip) &&
-      ntohs(IPH_LEN(&cs->cs_ip)) == hlen) {
+      lwip_ntohs(IPH_LEN(&cs->cs_ip)) == hlen) {
       break;
     }
     /* no break */
@@ -366,7 +366,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
     goto uncompressed;
 
   case NEW_S|NEW_A:
-    if (deltaS == deltaA && deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
+    if (deltaS == deltaA && deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
       /* special case for echoed terminal traffic */
       changes = SPECIAL_I;
       cp = new_seq;
@@ -374,7 +374,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
     break;
 
   case NEW_S:
-    if (deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
+    if (deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
       /* special case for data xfer */
       changes = SPECIAL_D;
       cp = new_seq;
@@ -384,7 +384,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
      break;
   }
 
-  deltaS = (u16_t)(ntohs(IPH_ID(ip)) - ntohs(IPH_ID(&cs->cs_ip)));
+  deltaS = (u16_t)(lwip_ntohs(IPH_ID(ip)) - lwip_ntohs(IPH_ID(&cs->cs_ip)));
   if (deltaS != 1) {
     ENCODEZ(deltaS);
     changes |= NEW_I;
@@ -396,7 +396,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb)
    * Grab the cksum before we overwrite it below.  Then update our
    * state with this packet's header.
    */
-  deltaA = ntohs(th->chksum);
+  deltaA = lwip_ntohs(th->chksum);
   MEMCPY(&cs->cs_ip, ip, hlen);
 
   /*
@@ -538,7 +538,7 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
   cs = &comp->rstate[comp->last_recv];
   hlen = IPH_HL(&cs->cs_ip) << 2;
   th = (struct tcp_hdr *)&((u8_t*)&cs->cs_ip)[hlen];
-  th->chksum = htons((*cp << 8) | cp[1]);
+  th->chksum = lwip_htons((*cp << 8) | cp[1]);
   cp += 2;
   if (changes & TCP_PUSH_BIT) {
     TCPH_SET_FLAG(th, TCP_PSH);
@@ -549,19 +549,19 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress 
*comp)
   switch (changes & SPECIALS_MASK) {
   case SPECIAL_I:
     {
-      u32_t i = ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
+      u32_t i = lwip_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
       /* some compilers can't nest inline assembler.. */
-      tmp = ntohl(th->ackno) + i;
-      th->ackno = htonl(tmp);
-      tmp = ntohl(th->seqno) + i;
-      th->seqno = htonl(tmp);
+      tmp = lwip_ntohl(th->ackno) + i;
+      th->ackno = lwip_htonl(tmp);
+      tmp = lwip_ntohl(th->seqno) + i;
+      th->seqno = lwip_htonl(tmp);
     }
     break;
 
   case SPECIAL_D:
     /* some compilers can't nest inline assembler.. */
-    tmp = ntohl(th->seqno) + ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
-    th->seqno = htonl(tmp);
+    tmp = lwip_ntohl(th->seqno) + lwip_ntohs(IPH_LEN(&cs->cs_ip)) - 
cs->cs_hlen;
+    th->seqno = lwip_htonl(tmp);
     break;
 
   default:
@@ -585,8 +585,8 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
   if (changes & NEW_I) {
     DECODES(cs->cs_ip._id);
   } else {
-    IPH_ID_SET(&cs->cs_ip, ntohs(IPH_ID(&cs->cs_ip)) + 1);
-    IPH_ID_SET(&cs->cs_ip, htons(IPH_ID(&cs->cs_ip)));
+    IPH_ID_SET(&cs->cs_ip, lwip_ntohs(IPH_ID(&cs->cs_ip)) + 1);
+    IPH_ID_SET(&cs->cs_ip, lwip_htons(IPH_ID(&cs->cs_ip)));
   }
 
   /*
@@ -607,9 +607,9 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
 
 #if BYTE_ORDER == LITTLE_ENDIAN
   tmp = n0->tot_len - vjlen + cs->cs_hlen;
-  IPH_LEN_SET(&cs->cs_ip, htons((u16_t)tmp));
+  IPH_LEN_SET(&cs->cs_ip, lwip_htons((u16_t)tmp));
 #else
-  IPH_LEN_SET(&cs->cs_ip, htons(n0->tot_len - vjlen + cs->cs_hlen));
+  IPH_LEN_SET(&cs->cs_ip, lwip_htons(n0->tot_len - vjlen + cs->cs_hlen));
 #endif
 
   /* recompute the ip header checksum */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/src/netif/slipif.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/src/netif/slipif.c 
b/net/ip/lwip_base/src/netif/slipif.c
index 8849fbf..6eb83c3 100644
--- a/net/ip/lwip_base/src/netif/slipif.c
+++ b/net/ip/lwip_base/src/netif/slipif.c
@@ -304,7 +304,7 @@ slipif_rxbyte(struct netif *netif, u8_t c)
 /** Like slipif_rxbyte, but passes completed packets to netif->input
  *
  * @param netif The lwip network interface structure for this slipif
- * @param data received character
+ * @param c received character
  */
 static void
 slipif_rxbyte_input(struct netif *netif, u8_t c)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/Makefile
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/Makefile 
b/net/ip/lwip_base/test/fuzz/Makefile
new file mode 100644
index 0000000..67ffb19
--- /dev/null
+++ b/net/ip/lwip_base/test/fuzz/Makefile
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
+# All rights reserved. 
+# 
+# Redistribution and use in source and binary forms, with or without 
modification, 
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+#    this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+#    this list of conditions and the following disclaimer in the documentation
+#    and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission. 
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
EVENT 
+# SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT 
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING 
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY 
+# OF SUCH DAMAGE.
+#
+# This file is part of the lwIP TCP/IP stack.
+# 
+# Author: Adam Dunkels <[email protected]>
+#
+
+all compile: lwip_fuzz
+.PHONY: all clean
+
+CC=afl-gcc
+LDFLAGS=-lm
+CFLAGS=-O0
+
+CONTRIBDIR=../../../lwip-contrib
+include $(CONTRIBDIR)/ports/unix/Common.mk
+
+clean:
+       rm -f *.o $(LWIPLIBCOMMON) lwip_fuzz *.s .depend* *.core core
+
+depend dep: .depend
+
+include .depend
+
+.depend: fuzz.c $(LWIPFILES) $(APPFILES)
+       $(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend
+
+lwip_fuzz: .depend $(LWIPLIBCOMMON) fuzz.o
+       $(CC) $(CFLAGS) -o lwip_fuzz fuzz.o $(LWIPLIBCOMMON) $(LDFLAGS)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/README
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/README 
b/net/ip/lwip_base/test/fuzz/README
new file mode 100644
index 0000000..1d1e3d8
--- /dev/null
+++ b/net/ip/lwip_base/test/fuzz/README
@@ -0,0 +1,34 @@
+
+Fuzzing the lwIP stack (afl-fuzz requires linux/unix or similar)
+
+This directory contains a small app that reads Ethernet frames from stdin and
+processes them. It is used together with the 'american fuzzy lop' tool (found
+at http://lcamtuf.coredump.cx/afl/) and the sample inputs to test how
+unexpected inputs are handled. The afl tool will read the known inputs, and
+try to modify them to exercise as many code paths as possible, by instrumenting
+the code and keeping track of which code is executed.
+
+Just running make will produce the test program.
+
+Then run afl with:
+
+afl-fuzz -i inputs/<INPUT> -o output ./lwip_fuzz
+
+and it should start working. It will probably complain about CPU scheduler,
+set AFL_SKIP_CPUFREQ=1 to ignore it.
+If it complains about invalid "/proc/sys/kernel/core_pattern" setting, try
+executing "sudo bash -c 'echo core > /proc/sys/kernel/core_pattern'".
+
+The input is split into different subdirectories since they test different
+parts of the code, and since you want to run one instance of afl-fuzz on each
+core.
+
+When afl finds a crash or a hang, the input that caused it will be placed in
+the output directory. If you have hexdump and text2pcap tools installed,
+running output_to_pcap.sh <outputdir> will create pcap files for each input
+file to simplify viewing in wireshark.
+
+The lwipopts.h file needs to have checksum checking off, otherwise almost every
+packet will be discarded because of that. The other options can be tuned to
+expose different parts of the code.
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/config.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/config.h 
b/net/ip/lwip_base/test/fuzz/config.h
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/fuzz.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/fuzz.c 
b/net/ip/lwip_base/test/fuzz/fuzz.c
new file mode 100644
index 0000000..a9157f1
--- /dev/null
+++ b/net/ip/lwip_base/test/fuzz/fuzz.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
+ * All rights reserved. 
+ * 
+ * Redistribution and use in source and binary forms, with or without 
modification, 
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
IMPLIED 
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
EVENT 
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT 
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING 
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY 
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ * 
+ * Author: Erik Ekman <[email protected]>
+ *
+ */
+
+#include "lwip/init.h"
+#include "lwip/netif.h"
+#include "netif/etharp.h"
+#if LWIP_IPV6
+#include "lwip/ethip6.h"
+#include "lwip/nd6.h"
+#endif
+#include <string.h>
+#include <stdio.h>
+
+/* no-op send function */
+static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
+{
+  LWIP_UNUSED_ARG(netif);
+  LWIP_UNUSED_ARG(p);
+  return ERR_OK;
+}
+
+static err_t testif_init(struct netif *netif)
+{
+  netif->name[0] = 'f';
+  netif->name[1] = 'z';
+  netif->output = etharp_output;
+  netif->linkoutput = lwip_tx_func;
+  netif->mtu = 1500;
+  netif->hwaddr_len = 6;
+  netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
+
+  netif->hwaddr[0] = 0x00;
+  netif->hwaddr[1] = 0x23;
+  netif->hwaddr[2] = 0xC1;
+  netif->hwaddr[3] = 0xDE;
+  netif->hwaddr[4] = 0xD0;
+  netif->hwaddr[5] = 0x0D;
+
+#if LWIP_IPV6
+  netif->output_ip6 = ethip6_output;
+  netif->ip6_autoconfig_enabled = 1;
+  netif_create_ip6_linklocal_address(netif, 1);
+  netif->flags |= NETIF_FLAG_MLD6;
+#endif
+
+  return ERR_OK;
+}
+
+static void input_pkt(struct netif *netif, const u8_t *data, size_t len)
+{
+  struct pbuf *p, *q;
+  err_t err;
+
+  LWIP_ASSERT("pkt too big", len <= 0xFFFF);
+  p = pbuf_alloc(PBUF_RAW, (u16_t)len, PBUF_POOL);
+  LWIP_ASSERT("alloc failed", p);
+  for(q = p; q != NULL; q = q->next) {
+    MEMCPY(q->payload, data, q->len);
+    data += q->len;
+  }
+  err = netif->input(p, netif);
+  if (err != ERR_OK) {
+    pbuf_free(p);
+  }
+}
+
+int main(int argc, char** argv)
+{
+  struct netif net_test;
+  ip4_addr_t addr;
+  ip4_addr_t netmask;
+  ip4_addr_t gw;
+  u8_t pktbuf[2000];
+  size_t len;
+
+  lwip_init();
+
+  IP4_ADDR(&addr, 172, 30, 115, 84);
+  IP4_ADDR(&netmask, 255, 255, 255, 0);
+  IP4_ADDR(&gw, 172, 30, 115, 1);
+
+  netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, 
ethernet_input);
+  netif_set_up(&net_test);
+
+#if LWIP_IPV6
+  nd6_tmr(); /* tick nd to join multicast groups */
+#endif
+
+  if(argc > 1) {
+    FILE* f;
+    const char* filename;
+    printf("reading input from file... ");
+    fflush(stdout);
+    filename = argv[1];
+    LWIP_ASSERT("invalid filename", filename != NULL);
+    f = fopen(filename, "rb");
+    LWIP_ASSERT("open failed", f != NULL);
+    len = fread(pktbuf, 1, sizeof(pktbuf), f);
+    fclose(f);
+    printf("testing file: \"%s\"...\r\n", filename);
+  } else {
+    len = fread(pktbuf, 1, sizeof(pktbuf), stdin);
+  }
+  input_pkt(&net_test, pktbuf, len);
+
+  return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/arp/arp_req.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/arp/arp_req.bin 
b/net/ip/lwip_base/test/fuzz/inputs/arp/arp_req.bin
new file mode 100644
index 0000000..b317334
Binary files /dev/null and b/net/ip/lwip_base/test/fuzz/inputs/arp/arp_req.bin 
differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/icmp/icmp_ping.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/icmp/icmp_ping.bin 
b/net/ip/lwip_base/test/fuzz/inputs/icmp/icmp_ping.bin
new file mode 100644
index 0000000..87e1ea7
Binary files /dev/null and 
b/net/ip/lwip_base/test/fuzz/inputs/icmp/icmp_ping.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/ipv6/neighbor_solicitation.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/ipv6/neighbor_solicitation.bin 
b/net/ip/lwip_base/test/fuzz/inputs/ipv6/neighbor_solicitation.bin
new file mode 100644
index 0000000..d2f921c
Binary files /dev/null and 
b/net/ip/lwip_base/test/fuzz/inputs/ipv6/neighbor_solicitation.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/ipv6/router_adv.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/ipv6/router_adv.bin 
b/net/ip/lwip_base/test/fuzz/inputs/ipv6/router_adv.bin
new file mode 100644
index 0000000..3aa9615
Binary files /dev/null and 
b/net/ip/lwip_base/test/fuzz/inputs/ipv6/router_adv.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/tcp/tcp_syn.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/tcp/tcp_syn.bin 
b/net/ip/lwip_base/test/fuzz/inputs/tcp/tcp_syn.bin
new file mode 100644
index 0000000..d77f6d2
Binary files /dev/null and b/net/ip/lwip_base/test/fuzz/inputs/tcp/tcp_syn.bin 
differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/inputs/udp/udp_port_5000.bin
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/inputs/udp/udp_port_5000.bin 
b/net/ip/lwip_base/test/fuzz/inputs/udp/udp_port_5000.bin
new file mode 100644
index 0000000..d77e267
Binary files /dev/null and 
b/net/ip/lwip_base/test/fuzz/inputs/udp/udp_port_5000.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/lwipopts.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/lwipopts.h 
b/net/ip/lwip_base/test/fuzz/lwipopts.h
new file mode 100644
index 0000000..4aff09b
--- /dev/null
+++ b/net/ip/lwip_base/test/fuzz/lwipopts.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
+ * All rights reserved. 
+ * 
+ * Redistribution and use in source and binary forms, with or without 
modification, 
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
IMPLIED 
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 
EVENT 
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
PROCUREMENT 
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING 
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY 
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ * 
+ * Author: Simon Goldschmidt
+ *
+ */
+#ifndef LWIP_HDR_LWIPOPTS_H__
+#define LWIP_HDR_LWIPOPTS_H__
+
+/* Prevent having to link sys_arch.c (we don't test the API layers in unit 
tests) */
+#define NO_SYS                          1
+#define LWIP_NETCONN                    0
+#define LWIP_SOCKET                     0
+#define SYS_LIGHTWEIGHT_PROT            0
+
+#define LWIP_IPV6                       1
+#define IPV6_FRAG_COPYHEADER            1
+#define LWIP_IPV6_DUP_DETECT_ATTEMPTS   0
+
+/* Enable DHCP to test it */
+#define LWIP_DHCP                       1
+
+/* Turn off checksum verification of fuzzed data */
+#define CHECKSUM_CHECK_IP               0
+#define CHECKSUM_CHECK_UDP              0
+#define CHECKSUM_CHECK_TCP              0
+#define CHECKSUM_CHECK_ICMP             0
+#define CHECKSUM_CHECK_ICMP6            0
+
+/* Minimal changes to opt.h required for tcp unit tests: */
+#define MEM_SIZE                        16000
+#define TCP_SND_QUEUELEN                40
+#define MEMP_NUM_TCP_SEG                TCP_SND_QUEUELEN
+#define TCP_SND_BUF                     (12 * TCP_MSS)
+#define TCP_WND                         (10 * TCP_MSS)
+#define LWIP_WND_SCALE                  1
+#define TCP_RCV_SCALE                   0
+#define PBUF_POOL_SIZE                  400 /* pbuf tests need ~200KByte */
+
+/* Minimal changes to opt.h required for etharp unit tests: */
+#define ETHARP_SUPPORT_STATIC_ENTRIES   1
+
+#endif /* LWIP_HDR_LWIPOPTS_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/fuzz/output_to_pcap.sh
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/fuzz/output_to_pcap.sh 
b/net/ip/lwip_base/test/fuzz/output_to_pcap.sh
new file mode 100644
index 0000000..c999ff0
--- /dev/null
+++ b/net/ip/lwip_base/test/fuzz/output_to_pcap.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+if [ -z "$1" ]
+then
+       echo "This script will make pcap files from the afl-fuzz crash/hang 
files"
+       echo "It needs hexdump and text2pcap"
+       echo "Please give output directory as argument"
+       exit 2
+fi
+
+for i in `ls $1/crashes/id*`
+do
+       PCAPNAME=`echo $i | grep pcap`
+       if [ -z "$PCAPNAME" ]; then
+               hexdump -C $i > $1/$$.tmp
+               text2pcap $1/$$.tmp ${i}.pcap
+       fi
+done
+for i in `ls $1/hangs/id*`
+do
+       PCAPNAME=`echo $i | grep pcap`
+       if [ -z "$PCAPNAME" ]; then
+               hexdump -C $i > $1/$$.tmp
+               text2pcap $1/$$.tmp ${i}.pcap
+       fi
+done
+rm -f $1/$$.tmp
+
+echo
+echo "Created pcap files:"
+ls $1/*/*.pcap

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/core/test_mem.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/core/test_mem.h 
b/net/ip/lwip_base/test/unit/core/test_mem.h
index 450bbd7..325134c 100644
--- a/net/ip/lwip_base/test/unit/core/test_mem.h
+++ b/net/ip/lwip_base/test/unit/core/test_mem.h
@@ -3,14 +3,6 @@
 
 #include "../lwip_check.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 Suite *mem_suite(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/core/test_pbuf.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/core/test_pbuf.h 
b/net/ip/lwip_base/test/unit/core/test_pbuf.h
index bdb7799..da7730a 100644
--- a/net/ip/lwip_base/test/unit/core/test_pbuf.h
+++ b/net/ip/lwip_base/test/unit/core/test_pbuf.h
@@ -3,14 +3,6 @@
 
 #include "../lwip_check.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 Suite *pbuf_suite(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/dhcp/test_dhcp.c
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/dhcp/test_dhcp.c 
b/net/ip/lwip_base/test/unit/dhcp/test_dhcp.c
index 68f2881..47aaa08 100644
--- a/net/ip/lwip_base/test/unit/dhcp/test_dhcp.c
+++ b/net/ip/lwip_base/test/unit/dhcp/test_dhcp.c
@@ -120,14 +120,13 @@ static enum tcase {
   TEST_LWIP_DHCP,
   TEST_LWIP_DHCP_NAK,
   TEST_LWIP_DHCP_RELAY,
-  TEST_LWIP_DHCP_NAK_NO_ENDMARKER
+  TEST_LWIP_DHCP_NAK_NO_ENDMARKER,
+  TEST_LWIP_DHCP_INVALID_OVERLOAD
 } tcase;
 
 static int debug = 0;
 static void setdebug(int a) {debug = a;}
 
-#define netif_dhcp_data(netif) ((struct 
dhcp*)(netif)->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])
-
 static int tick = 0;
 static void tick_lwip(void)
 {
@@ -904,6 +903,111 @@ START_TEST(test_dhcp_nak_no_endmarker)
 }
 END_TEST
 
+START_TEST(test_dhcp_invalid_overload)
+{
+  u8_t dhcp_offer_invalid_overload[] = {
+      0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */
+      0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22, /* From Remote host */
+      0x08, 0x00, /* Protocol: IP */
+      0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 
0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */
+      0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */
+
+      0x02, /* Type == Boot reply */
+      0x01, 0x06, /* Hw Ethernet, 6 bytes addrlen */
+      0x00, /* 0 hops */
+      0xAA, 0xAA, 0xAA, 0xAA, /* Transaction id, will be overwritten */
+      0x00, 0x00, /* 0 seconds elapsed */
+      0x00, 0x00, /* Flags (unicast) */
+      0x00, 0x00, 0x00, 0x00, /* Client ip */
+      0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */
+      0xc3, 0xaa, 0xbd, 0xab, /* DHCP server ip */
+      0x00, 0x00, 0x00, 0x00, /* relay agent */
+      0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, /* MAC addr + padding */
+
+      /* Empty server name */
+      0x34, 0x01, 0x02, 0xff, /* Overload: SNAME + END */
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      /* Empty boot file name */
+      0x34, 0x01, 0x01, 0xff, /* Overload FILE + END */
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+
+      0x63, 0x82, 0x53, 0x63, /* Magic cookie */
+      0x35, 0x01, 0x02, /* Message type: Offer */
+      0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Server identifier (IP) */
+      0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */
+      0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */
+      0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Subnet mask */
+      0x34, 0x01, 0x03, /* Overload: FILE + SNAME */
+      0xff, /* End option */
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, /* Padding */
+  };
+  ip4_addr_t addr;
+  ip4_addr_t netmask;
+  ip4_addr_t gw;
+  u32_t xid;
+  LWIP_UNUSED_ARG(_i);
+
+  tcase = TEST_LWIP_DHCP_INVALID_OVERLOAD;
+  setdebug(0);
+
+  IP4_ADDR(&addr, 0, 0, 0, 0);
+  IP4_ADDR(&netmask, 0, 0, 0, 0);
+  IP4_ADDR(&gw, 0, 0, 0, 0);
+
+  netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, 
ethernet_input);
+  netif_set_up(&net_test);
+
+  dhcp_start(&net_test);
+
+  fail_unless(txpacket == 1); /* DHCP discover sent */
+  xid = htonl(netif_dhcp_data(&net_test)->xid);
+  memcpy(&dhcp_offer_invalid_overload[46], &xid, 4); /* insert correct 
transaction id */
+  dhcp_offer_invalid_overload[311] = 3;
+  send_pkt(&net_test, dhcp_offer_invalid_overload, 
sizeof(dhcp_offer_invalid_overload));
+  /* IP addresses should be zero */
+  fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
+  fail_unless(txpacket == 1); /* Nothing more sent */
+
+  dhcp_offer_invalid_overload[311] = 2;
+  send_pkt(&net_test, dhcp_offer_invalid_overload, 
sizeof(dhcp_offer_invalid_overload));
+  /* IP addresses should be zero */
+  fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
+  fail_unless(txpacket == 1); /* Nothing more sent */
+
+  dhcp_offer_invalid_overload[311] = 1;
+  send_pkt(&net_test, dhcp_offer_invalid_overload, 
sizeof(dhcp_offer_invalid_overload));
+  /* IP addresses should be zero */
+  fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&netmask, &net_test.netmask, sizeof(ip4_addr_t)));
+  fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t)));
+  fail_unless(txpacket == 1); /* Nothing more sent */
+
+  dhcp_offer_invalid_overload[311] = 0;
+  send_pkt(&net_test, dhcp_offer_invalid_overload, sizeof(dhcp_offer));
+
+  fail_unless(netif_dhcp_data(&net_test)->state == DHCP_STATE_REQUESTING);
+
+  fail_unless(txpacket == 2); /* No more sent */
+  xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */
+
+  netif_remove(&net_test);
+}
+END_TEST
 
 /** Create the suite including all tests for this module */
 Suite *
@@ -913,7 +1017,8 @@ dhcp_suite(void)
     TESTFUNC(test_dhcp),
     TESTFUNC(test_dhcp_nak),
     TESTFUNC(test_dhcp_relayed),
-    TESTFUNC(test_dhcp_nak_no_endmarker)
+    TESTFUNC(test_dhcp_nak_no_endmarker),
+    TESTFUNC(test_dhcp_invalid_overload)
   };
   return create_suite("DHCP", tests, sizeof(tests)/sizeof(testfunc), 
dhcp_setup, dhcp_teardown);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/dhcp/test_dhcp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/dhcp/test_dhcp.h 
b/net/ip/lwip_base/test/unit/dhcp/test_dhcp.h
index 00021f2..0d88fa1 100644
--- a/net/ip/lwip_base/test/unit/dhcp/test_dhcp.h
+++ b/net/ip/lwip_base/test/unit/dhcp/test_dhcp.h
@@ -3,14 +3,6 @@
 
 #include "../lwip_check.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 Suite* dhcp_suite(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/etharp/test_etharp.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/etharp/test_etharp.h 
b/net/ip/lwip_base/test/unit/etharp/test_etharp.h
index 61742ec..2dd772d 100644
--- a/net/ip/lwip_base/test/unit/etharp/test_etharp.h
+++ b/net/ip/lwip_base/test/unit/etharp/test_etharp.h
@@ -3,14 +3,6 @@
 
 #include "../lwip_check.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 Suite* etharp_suite(void);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/lwip_check.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/lwip_check.h 
b/net/ip/lwip_base/test/unit/lwip_check.h
index 6946915..0c218d1 100644
--- a/net/ip/lwip_base/test/unit/lwip_check.h
+++ b/net/ip/lwip_base/test/unit/lwip_check.h
@@ -1,10 +1,6 @@
 #ifndef LWIP_HDR_LWIP_CHECK_H
 #define LWIP_HDR_LWIP_CHECK_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Common header file for lwIP unit tests using the check framework */
 
 #include <config.h>
@@ -38,8 +34,4 @@ Suite* create_suite(const char* name, testfunc *tests, size_t 
num_tests, SFun se
 int lwip_unittests_run(void)
 #endif
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* LWIP_HDR_LWIP_CHECK_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f52033e9/net/ip/lwip_base/test/unit/lwipopts.h
----------------------------------------------------------------------
diff --git a/net/ip/lwip_base/test/unit/lwipopts.h 
b/net/ip/lwip_base/test/unit/lwipopts.h
index 47ade69..25252b4 100644
--- a/net/ip/lwip_base/test/unit/lwipopts.h
+++ b/net/ip/lwip_base/test/unit/lwipopts.h
@@ -32,10 +32,6 @@
 #ifndef LWIP_HDR_LWIPOPTS_H
 #define LWIP_HDR_LWIPOPTS_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Prevent having to link sys_arch.c (we don't test the API layers in unit 
tests) */
 #define NO_SYS                          1
 #define SYS_LIGHTWEIGHT_PROT            0
@@ -63,8 +59,4 @@ extern "C" {
 /* Minimal changes to opt.h required for etharp unit tests: */
 #define ETHARP_SUPPORT_STATIC_ENTRIES   1
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* LWIP_HDR_LWIPOPTS_H */

Reply via email to