diff --git a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake index ed96dd8c7b..78a9f1f943 100644 --- a/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake @@ -14,7 +14,10 @@ set(unittest-sources ../features/netsocket/NetworkInterface.cpp ../features/netsocket/NetworkStack.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) # Test files diff --git a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake index 3d4297e530..f2f89e1136 100644 --- a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake @@ -8,7 +8,10 @@ set(unittest-sources ../features/netsocket/NetworkStack.cpp ../features/netsocket/InternetSocket.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) set(unittest-test-sources diff --git a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake index 37ea5dc0bf..336e9b106f 100644 --- a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake @@ -9,7 +9,10 @@ set(unittest-sources ../features/netsocket/NetworkStack.cpp ../features/netsocket/NetworkInterface.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) # Test files diff --git a/UNITTESTS/features/netsocket/NetworkStack/unittest.cmake b/UNITTESTS/features/netsocket/NetworkStack/unittest.cmake index f17d68852e..91ea42d5a2 100644 --- a/UNITTESTS/features/netsocket/NetworkStack/unittest.cmake +++ b/UNITTESTS/features/netsocket/NetworkStack/unittest.cmake @@ -12,7 +12,10 @@ set(unittest-sources ../features/netsocket/NetworkStack.cpp ../features/netsocket/NetworkInterface.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) # Test files diff --git a/UNITTESTS/features/netsocket/SocketAddress/unittest.cmake b/UNITTESTS/features/netsocket/SocketAddress/unittest.cmake index 04af1f03b4..6c4171c23f 100644 --- a/UNITTESTS/features/netsocket/SocketAddress/unittest.cmake +++ b/UNITTESTS/features/netsocket/SocketAddress/unittest.cmake @@ -6,19 +6,14 @@ # Unit test suite name set(TEST_SUITE_NAME "features_netsocket_SocketAddress") -# We want to get rid of ip6string.h fake include to use the real definitions. -list(REMOVE_ITEM unittest-includes "${PROJECT_SOURCE_DIR}/target_h") - # Source files set(unittest-sources ../features/netsocket/SocketAddress.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c - ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c -# Adding real ip6-related features, to test the relevant functions fully. ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c + ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c - ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c - + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) # Test files diff --git a/UNITTESTS/features/netsocket/TCPServer/unittest.cmake b/UNITTESTS/features/netsocket/TCPServer/unittest.cmake index d0b1e031b1..942d3aade0 100644 --- a/UNITTESTS/features/netsocket/TCPServer/unittest.cmake +++ b/UNITTESTS/features/netsocket/TCPServer/unittest.cmake @@ -13,7 +13,10 @@ set(unittest-sources ../features/netsocket/TCPSocket.cpp ../features/netsocket/TCPServer.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) set(unittest-test-sources diff --git a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake index 58367cfede..474a2b158e 100644 --- a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake @@ -9,7 +9,10 @@ set(unittest-sources ../features/netsocket/InternetSocket.cpp ../features/netsocket/TCPSocket.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) set(unittest-test-sources diff --git a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake index b57c38e6f4..82d149e086 100644 --- a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake @@ -9,7 +9,10 @@ set(unittest-sources ../features/netsocket/InternetSocket.cpp ../features/netsocket/UDPSocket.cpp ../features/frameworks/nanostack-libservice/source/libip4string/ip4tos.c + ../features/frameworks/nanostack-libservice/source/libip6string/ip6tos.c ../features/frameworks/nanostack-libservice/source/libip4string/stoip4.c + ../features/frameworks/nanostack-libservice/source/libip6string/stoip6.c + ../features/frameworks/nanostack-libservice/source/libBits/common_functions.c ) set(unittest-test-sources diff --git a/UNITTESTS/target_h/ip6string.h b/UNITTESTS/target_h/ip6string.h deleted file mode 100644 index d1d4ac28c5..0000000000 --- a/UNITTESTS/target_h/ip6string.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IP6STRING_H -#define IP6STRING_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -uint_fast8_t ip6tos(const void *ip6addr, char *p) -{ - return 0; -} - -void stoip6(const char *ip6addr, size_t len, void *dest) {} - -#ifdef __cplusplus -} -#endif -#endif diff --git a/features/netsocket/SocketAddress.cpp b/features/netsocket/SocketAddress.cpp index 3e42619a5e..2d0cb75bc8 100644 --- a/features/netsocket/SocketAddress.cpp +++ b/features/netsocket/SocketAddress.cpp @@ -24,26 +24,6 @@ -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; @@ -80,9 +60,8 @@ bool SocketAddress::set_ip_address(const char *addr) if (addr && stoip4(addr, strlen(addr), _addr.bytes)) { _addr.version = NSAPI_IPv4; return true; - } else if (addr && ipv6_is_valid(addr)) { + } 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();