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:
107:cc58b4c2090b
Parent:
61:aad055f1b0d1
Child:
112:f8694d0b8858
--- a/ip6/ip6addr.c	Fri Jan 11 16:06:08 2019 +0000
+++ b/ip6/ip6addr.c	Tue Jan 15 16:46:57 2019 +0000
@@ -12,9 +12,9 @@
 
 void Ip6AddressClear(char* ip)
 {
-    *ip = 0;
+    *ip = 0; //Just set the first byte to zero
 }
-bool Ip6AddressIsEmpty(char* ip)
+bool Ip6AddressIsEmpty(const char* ip)
 {
     return !*ip; //Just check for the first byte being non zero
 }
@@ -122,25 +122,26 @@
     }
     return count;
 }
-bool Ip6AddressIsSame(char* ipA, char* ipB)
+bool Ip6AddressIsSame(const char* ipA, const char* ipB)
 {
     return !memcmp(ipA, ipB, 16); //Though about optimising by doing a reverse loop but unlikely to be faster than an optimised assembly coded library function
 }
-void Ip6AddressCopy(char* ipTo, char* ipFrom)
+void Ip6AddressCopy(char* ipTo, const char* ipFrom)
 {
     memcpy(ipTo, ipFrom, 16);
 }
 
-char Ip6AddressAllNodes  [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
-char Ip6AddressAllRouters[] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
-char Ip6AddressMdns      [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb};
-char Ip6AddressLlmnr     [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03};
+const char Ip6AddressAllNodes  [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
+const char Ip6AddressAllRouters[] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
+const char Ip6AddressMdns      [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb};
+const char Ip6AddressLlmnr     [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03};
+const char Ip6AddressNtp       [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
 
 void Ip6AddressFromDest(int dest, char* pDstIp)
 {
     switch (dest)
     {
-        case   UNICAST:                                                      break;
+        case   UNICAST:        /*No change*/                                 break;
         case   UNICAST_DNS:    Ip6AddressCopy(pDstIp, NdpDnsServer        ); break;
         case   UNICAST_NTP:    Ip6AddressCopy(pDstIp, NtpServerIp6        ); break;
         case   UNICAST_TFTP:   Ip6AddressCopy(pDstIp, TftpServerIp6       ); break;
@@ -148,6 +149,7 @@
         case MULTICAST_ROUTER: Ip6AddressCopy(pDstIp, Ip6AddressAllRouters); break;
         case MULTICAST_MDNS:   Ip6AddressCopy(pDstIp, Ip6AddressMdns      ); break;
         case MULTICAST_LLMNR:  Ip6AddressCopy(pDstIp, Ip6AddressLlmnr     ); break;
+        case MULTICAST_NTP:    Ip6AddressCopy(pDstIp, Ip6AddressNtp       ); break;
         default:
             LogTimeF("Ip6AddressFromDest unknown destination %d\r\n", dest);
             break;