summaryrefslogtreecommitdiffstats
path: root/src/test/test-local-addresses.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/test/test-local-addresses.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-local-addresses.c')
-rw-r--r--src/test/test-local-addresses.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/test-local-addresses.c b/src/test/test-local-addresses.c
new file mode 100644
index 0000000..5a02465
--- /dev/null
+++ b/src/test/test-local-addresses.c
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <stdio.h>
+
+#include "af-list.h"
+#include "alloc-util.h"
+#include "in-addr-util.h"
+#include "local-addresses.h"
+#include "tests.h"
+
+static void print_local_addresses(struct local_address *a, unsigned n) {
+ for (unsigned i = 0; i < n; i++) {
+ _cleanup_free_ char *b = NULL;
+
+ assert_se(in_addr_to_string(a[i].family, &a[i].address, &b) >= 0);
+ log_debug("%s if%i scope=%i metric=%u address=%s", af_to_name(a[i].family), a[i].ifindex, a[i].scope, a[i].metric, b);
+ }
+}
+
+TEST(local_addresses) {
+ struct local_address *a = NULL;
+ int n;
+
+ n = local_addresses(NULL, 0, AF_INET, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:0, AF_INET) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_addresses(NULL, 0, AF_INET6, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:0, AF_INET6) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_addresses(NULL, 0, AF_UNSPEC, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:0, AF_UNSPEC) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_addresses(NULL, 1, AF_INET, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:1, AF_INET) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_addresses(NULL, 1, AF_INET6, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:1, AF_INET6) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_addresses(NULL, 1, AF_UNSPEC, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Addresses(ifindex:1, AF_UNSPEC) */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_gateways(NULL, 0, AF_UNSPEC, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Gateways */");
+ print_local_addresses(a, (unsigned) n);
+ a = mfree(a);
+
+ n = local_outbounds(NULL, 0, AF_UNSPEC, &a);
+ assert_se(n >= 0);
+ log_debug("/* Local Outbounds */");
+ print_local_addresses(a, (unsigned) n);
+ free(a);
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);