diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2020-08-01 22:02:03 +0200 |
---|---|---|
committer | Alexander Couzens <lynxis@fe80.eu> | 2020-09-02 17:23:43 +0200 |
commit | ea19839ade260256261353ccfa79455d086ea4e5 (patch) | |
tree | c71e4226bc278675b6100ab6dcc0b1aa7ffec439 /tests/socket | |
parent | d95f5d41faf57327f3fbe13671d409538de777eb (diff) |
tests/socket: add testcase test_get_ip_and_port
Check if osmo_sock_get_ip_and_port() works correct.
Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
Diffstat (limited to 'tests/socket')
-rw-r--r-- | tests/socket/socket_test.c | 33 | ||||
-rw-r--r-- | tests/socket/socket_test.ok | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c index ae771841..64e48bcb 100644 --- a/tests/socket/socket_test.c +++ b/tests/socket/socket_test.c @@ -154,6 +154,38 @@ static int test_sockinit2(void) return 0; } +static int test_get_ip_and_port() +{ + int fd, rc; + char ip[INET6_ADDRSTRLEN] = { }; + char port[6] = { }; + + printf("Checking test_get_ip_and_port() for combined BIND + CONNECT on IPv4\n"); + fd = osmo_sock_init2(AF_INET, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, "127.0.0.1", 55, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + + OSMO_ASSERT(fd >= 0); + + /* get the remote */ + rc = osmo_sock_get_ip_and_port(fd, ip, sizeof(ip), port, sizeof(port), false); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(strncmp(ip, "127.0.0.1", INET6_ADDRSTRLEN) == 0); + OSMO_ASSERT(strncmp(port, "55", 6) == 0); + + printf("Checking test_get_ip_and_port() for combined BIND + CONNECT on IPv6\n"); + fd = osmo_sock_init2(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, "::1", 0, "::1", 55, + OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); + OSMO_ASSERT(fd >= 0); + + /* get the remote */ + rc = osmo_sock_get_ip_and_port(fd, ip, sizeof(ip), port, sizeof(port), false); + OSMO_ASSERT(rc == 0); + OSMO_ASSERT(strncmp(ip, "::1", INET6_ADDRSTRLEN) == 0); + OSMO_ASSERT(strncmp(port, "55", 6) == 0); + + return 0; +} + const struct log_info_cat default_categories[] = { }; @@ -171,6 +203,7 @@ int main(int argc, char *argv[]) test_sockinit(); test_sockinit2(); + test_get_ip_and_port(); return EXIT_SUCCESS; } diff --git a/tests/socket/socket_test.ok b/tests/socket/socket_test.ok index 696e356b..589036f7 100644 --- a/tests/socket/socket_test.ok +++ b/tests/socket/socket_test.ok @@ -10,3 +10,5 @@ Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv6 & IPv4 Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv4 Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv6 Checking osmo_sock_init2(AF_UNSPEC) BIND on IPv4 +Checking test_get_ip_and_port() for combined BIND + CONNECT on IPv4 +Checking test_get_ip_and_port() for combined BIND + CONNECT on IPv6 |