diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2019-02-25 02:45:06 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2019-04-08 13:47:17 +0000 |
commit | 0c7826e9bd8026b239d320dba49416fd603f17fd (patch) | |
tree | 2d7553c002f684e8f2b76a4682093e29378271ac /tests | |
parent | e8461e486ebac6361b0869962aa86c5b8d46e59e (diff) |
add osmo_sockaddr_str API
For handling RTP IP addresses and ports, osmo-mgw, osmo-bsc and osmo-msc
so far have their own separate shims and code duplication around
inet_ntoa(), htons(), sockaddr conversions etc. Unify and standardize
with this common API.
In the MGW endpoint FSM that was introduced in osmo-bsc and which I
would like to re-use for osmo-msc (upcoming patch moving that to
osmo-mgw), it has turned out that using char* IP address and uint16_t
port number types are a convenient common denominator for logging,
MGCP message composition and GSM48. Ongoing osmo-msc work also uses this
for MNCC.
This is of course potentially useful for any other IP+port combinations
besides RTP stream handling.
Needless to say that most current implementations will probably stay
with their current own conversion code for a long time; for current
osmo-{bsc,msc,mgw} work (MGW endpoint FSM) though, I would like to move
to this API here.
Change-Id: Id617265337f09dfb6ddfe111ef5e578cd3dc9f63
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/sockaddr_str/sockaddr_str_test.c | 239 | ||||
-rw-r--r-- | tests/sockaddr_str/sockaddr_str_test.ok | 288 | ||||
-rw-r--r-- | tests/testsuite.at | 6 |
4 files changed, 538 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index ab3728f0..88bcd7e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,6 +30,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \ tdef/tdef_test tdef/tdef_vty_test_config_root \ tdef/tdef_vty_test_config_subnode \ tdef/tdef_vty_test_dynamic \ + sockaddr_str/sockaddr_str_test \ $(NULL) if ENABLE_MSGFILE @@ -236,6 +237,9 @@ tdef_tdef_vty_test_config_subnode_LDADD = $(LDADD) $(top_builddir)/src/vty/libos tdef_tdef_vty_test_dynamic_SOURCES = tdef/tdef_vty_test_dynamic.c tdef_tdef_vty_test_dynamic_LDADD = $(LDADD) $(top_builddir)/src/vty/libosmovty.la +sockaddr_str_sockaddr_str_test_SOURCES = sockaddr_str/sockaddr_str_test.c +sockaddr_str_sockaddr_str_test_LDADD = $(LDADD) + # The `:;' works around a Bash 3.2 bug when the output is not writeable. $(srcdir)/package.m4: $(top_srcdir)/configure.ac :;{ \ @@ -304,6 +308,7 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ tdef/tdef_vty_test_config_root.vty \ tdef/tdef_vty_test_config_subnode.vty \ tdef/tdef_vty_test_dynamic.vty \ + sockaddr_str/sockaddr_str_test.ok \ $(NULL) DISTCLEANFILES = atconfig atlocal conv/gsm0503_test_vectors.c diff --git a/tests/sockaddr_str/sockaddr_str_test.c b/tests/sockaddr_str/sockaddr_str_test.c new file mode 100644 index 00000000..d2e7944d --- /dev/null +++ b/tests/sockaddr_str/sockaddr_str_test.c @@ -0,0 +1,239 @@ +/* tests for osmo_sockaddr_str API of libmsomcore */ +/* + * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> + * + * Author: neels@hofmeyr.de + * + * All Rights Reserved + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <osmocom/core/sockaddr_str.h> +#include <osmocom/core/utils.h> +#include <netinet/in.h> + +struct osmo_sockaddr_str oip_data[] = { + { .af = AF_INET, .ip = "1.2.3.4", .port = 5 }, + { .af = AF_INET, .ip = "0.0.0.0", .port = 0 }, + { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 }, + { .af = AF_INET, .ip = "0.0.0.256", .port = 1 }, + { .af = AF_INET, .ip = "not an ip address", .port = 1 }, + { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 }, + { .af = AF_INET6, .ip = "::", .port = 0 }, + { .af = AF_INET6, .ip = "::1", .port = 0 }, + { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 }, + { .af = AF_INET6, .ip = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", .port = 65535 }, + { .af = AF_INET6, .ip = "::fffff", .port = 1 }, + { .af = AF_INET6, .ip = "not an ip address", .port = 1 }, + + { .af = AF_INET6, .ip = "1.2.3.4", .port = 5 }, + { .af = AF_INET, .ip = "1:2:3::4", .port = 5 }, + { .af = AF_UNSPEC, .ip = "1.2.3.4", .port = 5 }, + { .af = AF_INET, .ip = "", .port = 5 }, + { .af = AF_INET6, .ip = "", .port = 5 }, + { .af = AF_INET, .ip = "1.2.3.4", .port = 0 }, + { .af = AF_INET, .ip = "1.2.3:4:5", .port = 0 }, + { .af = AF_INET6, .ip = "::1:10.9.8.7", .port = 1 }, +}; + +const char *af_name(int af) +{ + switch (af) { + case AF_INET: + return "AF_INET"; + case AF_INET6: + return "AF_INET6"; + case AF_UNSPEC: + return "AF_UNSPEC"; + default: + return "?"; + } +} + +static const struct value_string err_names[] = { + { -EINVAL, "-EINVAL" }, + {} +}; + +static inline const char *err_name(int err) +{ return get_value_string(err_names, err); } + +static inline const char *rc_name(int rc) +{ + if (!rc) + return "rc == 0"; + if (rc < 0) + return "rc < 0"; + return "rc > 0"; +} + +void dump_oip(const struct osmo_sockaddr_str *oip) +{ + printf("{ .af = %s, .ip = %s, .port = %u }\n", af_name(oip->af), osmo_quote_str(oip->ip, -1), oip->port); +} + +void sockaddr_str_test_conversions() +{ + int i; + char buf[1024]; + +#define hexdump(what) \ + osmo_hexdump_buf(buf, sizeof(buf), (void*)(&what), sizeof(what), "", false) + + for (i = 0; i < ARRAY_SIZE(oip_data); i++) { + struct osmo_sockaddr_str *x = &oip_data[i]; + int rc; + printf("\n\n"); + dump_oip(x); + + printf(" osmo_sockaddr_str_is_set() = %s\n", osmo_sockaddr_str_is_set(x) ? "true" : "false"); + + { + struct in_addr a = {}; + + rc = osmo_sockaddr_str_to_in_addr(x, &a); + printf(" osmo_sockaddr_str_to_in_addr() %s in_addr=%s\n", rc_name(rc), hexdump(a)); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_in_addr(&back, &a, x->port); + printf(" -> osmo_sockaddr_str_from_in_addr() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + struct in6_addr a = {}; + + rc = osmo_sockaddr_str_to_in6_addr(x, &a); + printf(" osmo_sockaddr_str_to_in6_addr() %s in6_addr=%s\n", rc_name(rc), hexdump(a)); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_in6_addr(&back, &a, x->port); + printf(" -> osmo_sockaddr_str_from_in6_addr() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + uint32_t a = 0; + + rc = osmo_sockaddr_str_to_32(x, &a); + printf(" osmo_sockaddr_str_to_32() %s uint32_t=0x%x\n", rc_name(rc), a); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_32(&back, a, x->port); + printf(" -> osmo_sockaddr_str_from_32() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + uint32_t a = 0; + + rc = osmo_sockaddr_str_to_32n(x, &a); + printf(" osmo_sockaddr_str_to_32n() %s uint32_t=0x%x\n", rc_name(rc), a); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_32n(&back, a, x->port); + printf(" -> osmo_sockaddr_str_from_32n() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + struct sockaddr_in a = {}; + + rc = osmo_sockaddr_str_to_sockaddr_in(x, &a); + printf(" osmo_sockaddr_str_to_sockaddr_in() %s sockaddr_in=%s\n", rc_name(rc), hexdump(a)); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_sockaddr_in(&back, &a); + printf(" -> osmo_sockaddr_str_from_sockaddr_in() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + struct sockaddr_in6 a = {}; + + rc = osmo_sockaddr_str_to_sockaddr_in6(x, &a); + printf(" osmo_sockaddr_str_to_sockaddr_in6() %s sockaddr_in6=%s\n", rc_name(rc), hexdump(a)); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_sockaddr_in6(&back, &a); + printf(" -> osmo_sockaddr_str_from_sockaddr_in6() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + struct sockaddr_storage a = {}; + + rc = osmo_sockaddr_str_to_sockaddr(x, &a); + printf(" osmo_sockaddr_str_to_sockaddr() %s sockaddr_storage=%s\n", rc_name(rc), hexdump(a)); + + if (rc == 0) { + struct osmo_sockaddr_str back; + rc = osmo_sockaddr_str_from_sockaddr(&back, &a); + printf(" -> osmo_sockaddr_str_from_sockaddr() %s ", rc_name(rc)); + dump_oip(&back); + if (memcmp(x, &back, sizeof(back))) + printf(" DIFFERS!\n"); + } + } + + { + struct osmo_sockaddr_str from_str; + rc = osmo_sockaddr_str_from_str(&from_str, x->ip, x->port); + printf(" osmo_sockaddr_str_from_str() %s ", rc_name(rc)); + dump_oip(&from_str); + if (rc == 0 && memcmp(x, &from_str, sizeof(from_str))) + printf(" DIFFERS!\n"); + } + } + +} + +int main(int argc, char **argv) +{ + sockaddr_str_test_conversions(); + return 0; +} + diff --git a/tests/sockaddr_str/sockaddr_str_test.ok b/tests/sockaddr_str/sockaddr_str_test.ok new file mode 100644 index 00000000..d69314d4 --- /dev/null +++ b/tests/sockaddr_str/sockaddr_str_test.ok @@ -0,0 +1,288 @@ + + +{ .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc == 0 in_addr=01020304 + -> osmo_sockaddr_str_from_in_addr() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc == 0 uint32_t=0x4030201 + -> osmo_sockaddr_str_from_32() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_to_32n() rc == 0 uint32_t=0x1020304 + -> osmo_sockaddr_str_from_32n() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_to_sockaddr_in() rc == 0 sockaddr_in=02000005010203040000000000000000 + -> osmo_sockaddr_str_from_sockaddr_in() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0200000501020304000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + + +{ .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc == 0 in_addr=00000000 + -> osmo_sockaddr_str_from_in_addr() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc == 0 uint32_t=0x0 + -> osmo_sockaddr_str_from_32() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_to_32n() rc == 0 uint32_t=0x0 + -> osmo_sockaddr_str_from_32n() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_to_sockaddr_in() rc == 0 sockaddr_in=02000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr_in() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "0.0.0.0", .port = 0 } + + +{ .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc == 0 in_addr=ffffffff + -> osmo_sockaddr_str_from_in_addr() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc == 0 uint32_t=0xffffffff + -> osmo_sockaddr_str_from_32() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_to_32n() rc == 0 uint32_t=0xffffffff + -> osmo_sockaddr_str_from_32n() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_to_sockaddr_in() rc == 0 sockaddr_in=0200ffffffffffff0000000000000000 + -> osmo_sockaddr_str_from_sockaddr_in() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0200ffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "255.255.255.255", .port = 65535 } + + +{ .af = AF_INET, .ip = "0.0.0.256", .port = 1 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=02000001000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0200000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "0.0.0.256", .port = 1 } + + +{ .af = AF_INET, .ip = "not an ip address", .port = 1 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=02000001000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0200000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc < 0 { .af = AF_UNSPEC, .ip = "not an ip address", .port = 1 } + + +{ .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=00010002000300000000000000000004 + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a000005000000000001000200030000000000000000000400000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a00000500000000000100020003000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + + +{ .af = AF_INET6, .ip = "::", .port = 0 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=00000000000000000000000000000000 + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "::", .port = 0 } + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "::", .port = 0 } + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "::", .port = 0 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "::", .port = 0 } + + +{ .af = AF_INET6, .ip = "::1", .port = 0 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=00000000000000000000000000000001 + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "::1", .port = 0 } + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a000000000000000000000000000000000000000000000100000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "::1", .port = 0 } + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "::1", .port = 0 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "::1", .port = 0 } + + +{ .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=ffffffffffffffffffffffffffffffff + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a00ffff00000000ffffffffffffffffffffffffffffffff00000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a00ffff00000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + + +{ .af = AF_INET6, .ip = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", .port = 65535 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=ffffffffffffffffffffffffffffffff + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + DIFFERS! + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a00ffff00000000ffffffffffffffffffffffffffffffff00000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + DIFFERS! + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a00ffff00000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", .port = 65535 } + DIFFERS! + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", .port = 65535 } + + +{ .af = AF_INET6, .ip = "::fffff", .port = 1 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=0a000001000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0a00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "::fffff", .port = 1 } + + +{ .af = AF_INET6, .ip = "not an ip address", .port = 1 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=0a000001000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0a00000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc < 0 { .af = AF_UNSPEC, .ip = "not an ip address", .port = 1 } + + +{ .af = AF_INET6, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=0a000005000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0a00000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + DIFFERS! + + +{ .af = AF_INET, .ip = "1:2:3::4", .port = 5 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=02000005000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0200000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "1:2:3::4", .port = 5 } + DIFFERS! + + +{ .af = AF_UNSPEC, .ip = "1.2.3.4", .port = 5 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 5 } + DIFFERS! + + +{ .af = AF_INET, .ip = "", .port = 5 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=02000005000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0200000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc < 0 { .af = AF_UNSPEC, .ip = "", .port = 5 } + + +{ .af = AF_INET6, .ip = "", .port = 5 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=0a000005000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0a00000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc < 0 { .af = AF_UNSPEC, .ip = "", .port = 5 } + + +{ .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc == 0 in_addr=01020304 + -> osmo_sockaddr_str_from_in_addr() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc == 0 uint32_t=0x4030201 + -> osmo_sockaddr_str_from_32() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_to_32n() rc == 0 uint32_t=0x1020304 + -> osmo_sockaddr_str_from_32n() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_to_sockaddr_in() rc == 0 sockaddr_in=02000000010203040000000000000000 + -> osmo_sockaddr_str_from_sockaddr_in() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0200000001020304000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET, .ip = "1.2.3.4", .port = 0 } + + +{ .af = AF_INET, .ip = "1.2.3:4:5", .port = 0 } + osmo_sockaddr_str_is_set() = false + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc < 0 in6_addr=00000000000000000000000000000000 + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=02000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc < 0 sockaddr_in6=00000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr() rc < 0 sockaddr_storage=0200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "1.2.3:4:5", .port = 0 } + DIFFERS! + + +{ .af = AF_INET6, .ip = "::1:10.9.8.7", .port = 1 } + osmo_sockaddr_str_is_set() = true + osmo_sockaddr_str_to_in_addr() rc < 0 in_addr=00000000 + osmo_sockaddr_str_to_in6_addr() rc == 0 in6_addr=0000000000000000000000010a090807 + -> osmo_sockaddr_str_from_in6_addr() rc == 0 { .af = AF_INET6, .ip = "::1:a09:807", .port = 1 } + DIFFERS! + osmo_sockaddr_str_to_32() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_32n() rc < 0 uint32_t=0x0 + osmo_sockaddr_str_to_sockaddr_in() rc < 0 sockaddr_in=00000000000000000000000000000000 + osmo_sockaddr_str_to_sockaddr_in6() rc == 0 sockaddr_in6=0a000001000000000000000000000000000000010a09080700000000 + -> osmo_sockaddr_str_from_sockaddr_in6() rc == 0 { .af = AF_INET6, .ip = "::1:a09:807", .port = 1 } + DIFFERS! + osmo_sockaddr_str_to_sockaddr() rc == 0 sockaddr_storage=0a000001000000000000000000000000000000010a0908070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + -> osmo_sockaddr_str_from_sockaddr() rc == 0 { .af = AF_INET6, .ip = "::1:a09:807", .port = 1 } + DIFFERS! + osmo_sockaddr_str_from_str() rc == 0 { .af = AF_INET6, .ip = "::1:10.9.8.7", .port = 1 } diff --git a/tests/testsuite.at b/tests/testsuite.at index 0093403a..db2003f4 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -331,3 +331,9 @@ AT_KEYWORDS([tdef]) cat $abs_srcdir/tdef/tdef_test.ok > expout AT_CHECK([$abs_top_builddir/tests/tdef/tdef_test], [0], [expout], [ignore]) AT_CLEANUP + +AT_SETUP([sockaddr_str]) +AT_KEYWORDS([sockaddr_str]) +cat $abs_srcdir/sockaddr_str/sockaddr_str_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/sockaddr_str/sockaddr_str_test], [0], [expout], [ignore]) +AT_CLEANUP |