Change in libosmocore[master]: tests/socket: add testcase test_get_ip_and_port

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Wed Sep 2 16:38:36 UTC 2020


lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19147 )

Change subject: tests/socket: add testcase test_get_ip_and_port
......................................................................

tests/socket: add testcase test_get_ip_and_port

Check if osmo_sock_get_ip_and_port() works correct.

Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
---
M tests/socket/socket_test.c
M tests/socket/socket_test.ok
2 files changed, 35 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved



diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c
index ae77184..64e48bc 100644
--- a/tests/socket/socket_test.c
+++ b/tests/socket/socket_test.c
@@ -154,6 +154,38 @@
 	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 @@
 
 	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 696e356..589036f 100644
--- a/tests/socket/socket_test.ok
+++ b/tests/socket/socket_test.ok
@@ -10,3 +10,5 @@
 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

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19147
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
Gerrit-Change-Number: 19147
Gerrit-PatchSet: 13
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200902/35daed01/attachment.htm>


More information about the gerrit-log mailing list