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:
- 171:f708d6776752
- Parent:
- 143:8cec8f08dc54
- Child:
- 172:9bc3c7b2cca1
diff -r 96c637dc3f52 -r f708d6776752 ip6/ip6addr.c
--- a/ip6/ip6addr.c Wed Dec 09 18:11:05 2020 +0000
+++ b/ip6/ip6addr.c Sat Dec 12 20:10:02 2020 +0000
@@ -12,11 +12,32 @@
void Ip6AddressClear(char* ip)
{
- *ip = 0; //Just set the first byte to zero
+ 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)
{
- return !*ip; //Just check for the first byte being non zero
+ return !ip[0] && !ip[12]; //Check for the first and 12th byte being non zero
+}
+void Ip6AddressFromIp4(char* ip6, uint32_t ip4)
+{
+ memset(ip6, 0, 16);
+ *ip6++ = 0; *ip6++ = 0; *ip6++ = 0; *ip6++ = 0;
+ *ip6++ = 0; *ip6++ = 0; *ip6++ = 0; *ip6++ = 0;
+ *ip6++ = 0; *ip6++ = 0; *ip6++ = 0; *ip6++ = 0;
+ *ip6++ = (ip4 >> 0) & 0xFF;
+ *ip6++ = (ip4 >> 8) & 0xFF;
+ *ip6++ = (ip4 >> 16) & 0xFF;
+ *ip6++ = (ip4 >> 24) & 0xFF;
+}
+uint32_t Ip6AddressToIp4(char* ip6)
+{
+ uint32_t ip4;
+ ip4 = ip6[12] << 0;
+ ip4 |= ip6[13] << 8;
+ ip4 |= ip6[14] << 16;
+ ip4 |= ip6[15] << 24;
+ return ip4;
}
static void addHexNibble(bool* pAdded, int number, int index, char** pp)
{
@@ -159,6 +180,10 @@
{
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;
@@ -178,15 +203,15 @@
{
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: /*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;
default:
LogTimeF("Ip6AddressFromDest unknown destination %d\r\n", dest);
break;