Merge pull request #8003 from Taiki-San/patch-2

Leverage the simplification of the IPv6 parsing primitive
pull/8531/head
Martin Kojtal 2018-10-24 14:13:16 +01:00 committed by GitHub
commit 7cd1478147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 65 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <stdint.h>
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

View File

@ -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();