aboutsummaryrefslogtreecommitdiffstats
path: root/tests/socket
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-11-21 19:45:57 +0100
committerlaforge <laforge@osmocom.org>2023-11-22 12:18:26 +0000
commit641cc3c60da1ae4b1f442609ca381b052a5ecb44 (patch)
tree209c47a4f505d51718d2d5f58bd53c28f88e81d8 /tests/socket
parentafdfc6a034d0bec95993f29cc712b66288a54cbc (diff)
add new osmo_sockaddr_from_str_and_uint() function
The function is basically a shortcut for getaddrinfo with storing the output data into our 'struct osmo_sockaddr'. Change-Id: I6b5c0bf8ca97e6358d992fb2ff45ffd53ba15197 Related: SYS#6657
Diffstat (limited to 'tests/socket')
-rw-r--r--tests/socket/socket_test.c13
-rw-r--r--tests/socket/socket_test.ok3
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c
index ddb69268..34130b26 100644
--- a/tests/socket/socket_test.c
+++ b/tests/socket/socket_test.c
@@ -315,6 +315,7 @@ static void test_osa_str(void)
const char *result;
struct osmo_sockaddr localhost4 = {};
struct osmo_sockaddr localhost6 = {};
+ struct osmo_sockaddr osa = {};
localhost4.u.sin = (struct sockaddr_in){
.sin_family = AF_INET,
@@ -383,6 +384,18 @@ static void test_osa_str(void)
result = osmo_sockaddr_to_str(&localhost6);
printf("Checking osmo_sockaddr_to_str_buf long IPv6 port static buffer\n");
OSMO_ASSERT(!strncmp("[2003:1234:5678:90ab:cdef:1234:4321:4321]:23420", result, sizeof(buf)));
+
+ printf("Checking osmo_sockaddr_from_str_and_uint for 0.0.0.0\n");
+ OSMO_ASSERT(osmo_sockaddr_from_str_and_uint(&osa, "0.0.0.0", 1234) == 0);
+ OSMO_ASSERT(osmo_sockaddr_is_any(&osa));
+
+ printf("Checking osmo_sockaddr_from_str_and_uint for ::\n");
+ OSMO_ASSERT(osmo_sockaddr_from_str_and_uint(&osa, "::", 1234) == 0);
+ OSMO_ASSERT(osmo_sockaddr_is_any(&osa));
+
+ printf("Checking osmo_sockaddr_from_str_and_uint for 1.2.3.4\n");
+ OSMO_ASSERT(osmo_sockaddr_from_str_and_uint(&osa, "1.2.3.4", 1234) == 0);
+ OSMO_ASSERT(!osmo_sockaddr_is_any(&osa));
}
static void test_osa_netmask_prefixlen(void)
diff --git a/tests/socket/socket_test.ok b/tests/socket/socket_test.ok
index 236c0111..2b1c1006 100644
--- a/tests/socket/socket_test.ok
+++ b/tests/socket/socket_test.ok
@@ -31,3 +31,6 @@ Checking osmo_sockaddr_to_str_buf only 5 bytes IPv6
Checking osmo_sockaddr_to_str_buf long IPv6
Checking osmo_sockaddr_to_str_buf long IPv6 port
Checking osmo_sockaddr_to_str_buf long IPv6 port static buffer
+Checking osmo_sockaddr_from_str_and_uint for 0.0.0.0
+Checking osmo_sockaddr_from_str_and_uint for ::
+Checking osmo_sockaddr_from_str_and_uint for 1.2.3.4