Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: ip6/ip6addr.c
- Revision:
- 172:9bc3c7b2cca1
- Parent:
- 171:f708d6776752
- Child:
- 176:7eb916c22084
--- a/ip6/ip6addr.c Sat Dec 12 20:10:02 2020 +0000
+++ b/ip6/ip6addr.c Wed Dec 16 17:33:22 2020 +0000
@@ -10,16 +10,16 @@
#include "slaac.h"
#include "tftp.h"
-void Ip6AddressClear(char* ip)
+void Ip6AddrClear(char* ip)
{
ip[ 0] = 0; //Just set the first byte to zero
ip[12] = 0; //and the 12 (the first byte of a IP4 address)
}
-bool Ip6AddressIsEmpty(const char* ip)
+bool Ip6AddrIsEmpty(const char* ip)
{
return !ip[0] && !ip[12]; //Check for the first and 12th byte being non zero
}
-void Ip6AddressFromIp4(char* ip6, uint32_t ip4)
+void Ip6AddrFromIp4(char* ip6, uint32_t ip4)
{
memset(ip6, 0, 16);
*ip6++ = 0; *ip6++ = 0; *ip6++ = 0; *ip6++ = 0;
@@ -30,7 +30,7 @@
*ip6++ = (ip4 >> 16) & 0xFF;
*ip6++ = (ip4 >> 24) & 0xFF;
}
-uint32_t Ip6AddressToIp4(char* ip6)
+uint32_t Ip6AddrToIp4(char* ip6)
{
uint32_t ip4;
ip4 = ip6[12] << 0;
@@ -52,7 +52,7 @@
*pAdded = true;
}
}
-int Ip6AddressToString(const char* pIp, int size, char* pText)
+int Ip6AddrToString(const char* pIp, int size, char* pText)
{
const char* pIpE = pIp + 16;
char* p = pText;
@@ -87,7 +87,7 @@
*pAdded = true;
}
}
-int Ip6AddressLog(const char* pIp)
+int Ip6AddrLog(const char* pIp)
{
int count = 0;
const char* pIpE = pIp + 16;
@@ -121,7 +121,7 @@
*pAdded = true;
}
}
-int Ip6AddressHttp(const char* pIp)
+int Ip6AddrHttp(const char* pIp)
{
int count = 0;
const char* pIpE = pIp + 16;
@@ -143,15 +143,40 @@
}
return count;
}
-bool Ip6AddressIsSame(const char* ipA, const char* ipB)
+bool Ip6AddrIsSame(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, const char* ipFrom)
+void Ip6AddrCopy(char* ipTo, const char* ipFrom)
{
memcpy(ipTo, ipFrom, 16);
}
+bool Ip6AddrIsIp4(const char *p)
+{
+ if (p[ 0] != 0) return false;
+ if (p[12] != 0) return false;
+ return true;
+}
+bool Ip6AddrIsLinkLocal(const char* p)
+{
+ if (p[0] != 0xFE) return false;
+ if (p[1] != 0x80) return false;
+ return true;
+}
+bool Ip6AddrIsUniqueLocal(const char* p)
+{
+ if (p[0] != 0xFD) return false;
+ if (p[1] != 0x00) return false;
+ return true;
+}
+bool Ip6AddrIsGlobal(const char* p)
+{
+ //[RFC 4291] designates 2000::/3 to be global unicast address space that the Internet Assigned Numbers Authority (IANA) may allocate to the RIRs.
+ //The top byte AND 0b11100000 (0xE0)must be 0x20
+ return (p[0] & 0xE0) == 0x20;
+}
+
bool Ip6AddrIsSolicited(const char* p)
{
if (*p++ != 0xff) return false;
@@ -180,10 +205,6 @@
{
return *p == 0xFF;
}
-bool Ip6AddrIsIp4(const char *p)
-{
- return p[0] == 0 && p[12] != 0;
-}
bool Ip6AddrIsSameGroup(const char* pA, const char* pB)
{
pA += 13;
@@ -193,25 +214,25 @@
return *pA == *pB;
}
-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};
+const char Ip6AddrAllNodes [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
+const char Ip6AddrAllRouters[] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
+const char Ip6AddrMdns [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb};
+const char Ip6AddrLlmnr [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03};
+const char Ip6AddrNtp [] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01};
-void Ip6AddressFromDest(int dest, char* pDstIp)
+void Ip6AddrFromDest(int dest, char* pDstIp)
{
switch (dest)
{
case UNICAST: /*No change*/ break;
- case UNICAST_DNS: Ip6AddressCopy(pDstIp, NdpDnsServer ); break;
- case UNICAST_NTP: Ip6AddressCopy(pDstIp, NtpClientQueryServerIp6); break;
- case UNICAST_TFTP: Ip6AddressCopy(pDstIp, TftpServerIp6 ); break;
- case MULTICAST_NODE: Ip6AddressCopy(pDstIp, Ip6AddressAllNodes ); break;
- 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;
+ case UNICAST_DNS: Ip6AddrCopy(pDstIp, NdpDnsServer ); break;
+ case UNICAST_NTP: Ip6AddrCopy(pDstIp, NtpClientQueryServerIp6); break;
+ case UNICAST_TFTP: Ip6AddrCopy(pDstIp, TftpServerIp6 ); break;
+ case MULTICAST_NODE: Ip6AddrCopy(pDstIp, Ip6AddrAllNodes ); break;
+ case MULTICAST_ROUTER: Ip6AddrCopy(pDstIp, Ip6AddrAllRouters ); break;
+ case MULTICAST_MDNS: Ip6AddrCopy(pDstIp, Ip6AddrMdns ); break;
+ case MULTICAST_LLMNR: Ip6AddrCopy(pDstIp, Ip6AddrLlmnr ); break;
+ case MULTICAST_NTP: Ip6AddrCopy(pDstIp, Ip6AddrNtp ); break;
default:
LogTimeF("Ip6AddressFromDest unknown destination %d\r\n", dest);
break;