Skip to content

Commit 6d95eaa

Browse files
Taiki-SanCruz Monrreal II
authored andcommitted
Switch the IPv4 parser to the one recently introduced in libservice. Return a bool value on wether parsing of the IPv4 address string was successful
1 parent d5c8baa commit 6d95eaa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

features/netsocket/SocketAddress.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424

2525

2626

27+
static bool ipv6_is_valid(const char *addr)
28+
{
29+
// Check each digit for [0-9a-fA-F:]
30+
// Must also have at least 2 colons
31+
int colons = 0;
32+
for (int i = 0; addr[i]; i++) {
33+
if (!(addr[i] >= '0' && addr[i] <= '9') &&
34+
!(addr[i] >= 'a' && addr[i] <= 'f') &&
35+
!(addr[i] >= 'A' && addr[i] <= 'F') &&
36+
addr[i] != ':') {
37+
return false;
38+
}
39+
if (addr[i] == ':') {
40+
colons++;
41+
}
42+
}
43+
44+
return colons >= 2;
45+
}
46+
2747
SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port)
2848
{
2949
_ip_address = NULL;
@@ -62,6 +82,7 @@ bool SocketAddress::set_ip_address(const char *addr)
6282
return true;
6383
} else if (addr && stoip6(addr, strlen(addr), _addr.bytes)) {
6484
_addr.version = NSAPI_IPv6;
85+
stoip6(addr, strlen(addr), _addr.bytes);
6586
return true;
6687
} else {
6788
_addr = nsapi_addr_t();

0 commit comments

Comments
 (0)