mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
d5c8baa364
commit
6d95eaa03d
|
@ -24,6 +24,26 @@
|
|||
|
||||
|
||||
|
||||
static bool ipv6_is_valid(const char *addr)
|
||||
{
|
||||
// Check each digit for [0-9a-fA-F:]
|
||||
// Must also have at least 2 colons
|
||||
int colons = 0;
|
||||
for (int i = 0; addr[i]; i++) {
|
||||
if (!(addr[i] >= '0' && addr[i] <= '9') &&
|
||||
!(addr[i] >= 'a' && addr[i] <= 'f') &&
|
||||
!(addr[i] >= 'A' && addr[i] <= 'F') &&
|
||||
addr[i] != ':') {
|
||||
return false;
|
||||
}
|
||||
if (addr[i] == ':') {
|
||||
colons++;
|
||||
}
|
||||
}
|
||||
|
||||
return colons >= 2;
|
||||
}
|
||||
|
||||
SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port)
|
||||
{
|
||||
_ip_address = NULL;
|
||||
|
@ -62,6 +82,7 @@ bool SocketAddress::set_ip_address(const char *addr)
|
|||
return true;
|
||||
} else if (addr && stoip6(addr, strlen(addr), _addr.bytes)) {
|
||||
_addr.version = NSAPI_IPv6;
|
||||
stoip6(addr, strlen(addr), _addr.bytes);
|
||||
return true;
|
||||
} else {
|
||||
_addr = nsapi_addr_t();
|
||||
|
|
Loading…
Reference in New Issue