summaryrefslogtreecommitdiffstats
path: root/tests/sockaddr_str/sockaddr_str_test.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-10-05 05:12:33 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2019-11-01 14:33:58 +0100
commit2ceb758ba4a845898fbff11bd4942751078b8ee7 (patch)
tree3ae464646ef28312ddbd6f2ced625622a43ab7da /tests/sockaddr_str/sockaddr_str_test.c
parentab6d6cf3aa5ca75f4b110ac4282a07adcc981e59 (diff)
add osmo_sockaddr_str_is_nonzero()
Often, an IP address of 0.0.0.0 is considered an unset value (for clients requiring a server address; not for listening on "any"). osmo_sockaddr_str_is_set() does return false when the port is 0, but there is no simple way to tell whether the IP address is actually set to a server address. Add osmo_sockaddr_str_is_nonzero() to return false if: - the port is zero, or - the IP address is zero (0.0.0.0 or ::0), or - the IP address cannot be parsed. A practical use example: osmo-msc so far accepts an RTP IP address of 0.0.0.0 as valid. I noticed when trying to trigger error handling from a ttcn3 test. osmo-msc can use this function to reject invalid addresses from MGCP messages. Related: I53ddb19a70fda3deb906464e1b89c12d9b4c7cbd (osmo-msc) Change-Id: I73cbcab90cffcdc9a5f8d5281c57c1f87b2c3550
Diffstat (limited to 'tests/sockaddr_str/sockaddr_str_test.c')
-rw-r--r--tests/sockaddr_str/sockaddr_str_test.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/sockaddr_str/sockaddr_str_test.c b/tests/sockaddr_str/sockaddr_str_test.c
index d2e7944d..4284387b 100644
--- a/tests/sockaddr_str/sockaddr_str_test.c
+++ b/tests/sockaddr_str/sockaddr_str_test.c
@@ -53,6 +53,8 @@ struct osmo_sockaddr_str oip_data[] = {
{ .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 },
+ { .af = AF_INET, .ip = "0.0.0.0", .port = 5 },
+ { .af = AF_INET6, .ip = "::", .port = 5 },
};
const char *af_name(int af)
@@ -106,6 +108,7 @@ void sockaddr_str_test_conversions()
dump_oip(x);
printf(" osmo_sockaddr_str_is_set() = %s\n", osmo_sockaddr_str_is_set(x) ? "true" : "false");
+ printf(" osmo_sockaddr_str_is_nonzero() = %s\n", osmo_sockaddr_str_is_nonzero(x) ? "true" : "false");
{
struct in_addr a = {};