A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Revision:
44:83ce5ace337b
Parent:
43:bc028d5a6424
Child:
47:73af5c0b0dc2
--- a/ip4/ip4.cpp	Thu Oct 19 20:56:58 2017 +0000
+++ b/ip4/ip4.cpp	Sun Oct 22 17:19:17 2017 +0000
@@ -137,7 +137,7 @@
     char text[30];
     if (NetTraceVerbose)
     {
-        Log ("IPv4 header\r\n");
+        Log ("IP4 header\r\n");
         LogF("  Version           %d\r\n", version);
         LogF("  Header length     %d\r\n", headerLength);
         LogF("  Type of service   %d\r\n", tos);
@@ -160,7 +160,7 @@
     }
     else
     {
-        Log ("IPv4 header ");
+        Log ("IP4   header ");
         IpProtocolToString(protocol, sizeof(text), text);
         Log(text);
         Log(" ");
@@ -210,17 +210,18 @@
     switch (protocol)
     {
         case ICMP:   action = Icmp4HandleReceivedPacket(trace, &srcIp, &dstIp, &dataLength, pData); break;
-        case IGMP:                                                                                 break;
+        case IGMP:                                                                                  break;
         case UDP:    action =  Udp4HandleReceivedPacket(trace, &srcIp, &dstIp, &dataLength, pData); break;
         case TCP:    action =  Tcp4HandleReceivedPacket(trace, &srcIp, &dstIp, &dataLength, pData); break;
-        case IP6IN4:                                                                               break;
+        case IP6IN4:                                                                                break;
         default:
             LogTimeF("IP4 received packet unknown protocol %d\r\n");
             return DO_NOTHING;
     }
     if (!action) return DO_NOTHING;
     
-    MacCopy(pDstMac, pSrcMac);
+    if (DhcpIpNeedsToBeRouted(dstIp)) ArIpToMac4(DhcpRouter, pDstMac);  //Send back to the router
+    else                              MacCopy(pDstMac, pSrcMac);        //Send back to the source
         
     writeHeader(pHeader);
     
@@ -254,7 +255,8 @@
         case UNICAST_DNS:
         case UNICAST_DHCP:
         case UNICAST_NTP:
-            ArIpToMac4(dstIp, pDstMac);             //Make the remote MAC from ARP
+            if (DhcpIpNeedsToBeRouted(dstIp)) ArIpToMac4(DhcpRouter, pDstMac); //send via router
+            else                              ArIpToMac4(dstIp,      pDstMac); //Send direct
             break;
         case MULTICAST_NODE:
         case MULTICAST_ROUTER: