summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-09 12:32:28 +0100
committerThomas Haller <thaller@redhat.com>2020-01-28 11:17:41 +0100
commitb9c5c07c4d756c4d0f4c0fda38cf4862b1b5c09e (patch)
tree22af508171fc23dc416b58774458eed9058a584b
parent8f3b43f009795ecaa640635a7c786291539425c7 (diff)
downloadNetworkManager-b9c5c07c4d756c4d0f4c0fda38cf4862b1b5c09e.tar.gz
shared: add NM_IP_ADDR_ZERO macro for initializing NMIPAddr to zero
-rw-r--r--libnm-core/tests/test-general.c5
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h4
2 files changed, 9 insertions, 0 deletions
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index 9968f3613f..e42ac737e0 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -8334,6 +8334,9 @@ test_nm_ip_addr_zero (void)
in_addr_t a4 = nmtst_inet4_from_string ("0.0.0.0");
struct in6_addr a6 = *nmtst_inet6_from_string ("::");
char buf[NM_UTILS_INET_ADDRSTRLEN];
+ NMIPAddr a = NM_IP_ADDR_INIT;
+
+ g_assert (memcmp (&a, &nm_ip_addr_zero, sizeof (a)) == 0);
g_assert (IN6_IS_ADDR_UNSPECIFIED (&nm_ip_addr_zero.addr6));
g_assert (memcmp (&nm_ip_addr_zero.addr6, &in6addr_any, sizeof (in6addr_any)) == 0);
@@ -8346,6 +8349,8 @@ test_nm_ip_addr_zero (void)
g_assert_cmpstr (nm_utils_inet_ntop (AF_INET, &nm_ip_addr_zero, buf), ==, "0.0.0.0");
g_assert_cmpstr (nm_utils_inet_ntop (AF_INET6, &nm_ip_addr_zero, buf), ==, "::");
+
+ G_STATIC_ASSERT_EXPR (sizeof (a) == sizeof (a.array));
}
/*****************************************************************************/
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 0a32a257a8..e835a1efa3 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -115,9 +115,13 @@ typedef struct {
* However, as ethernet addresses fit in here nicely, use
* it also for an ethernet MAC address. */
guint8 addr_eth[6 /*ETH_ALEN*/];
+
+ guint8 array[sizeof (struct in6_addr)];
};
} NMIPAddr;
+#define NM_IP_ADDR_INIT { .array = { 0 } }
+
extern const NMIPAddr nm_ip_addr_zero;
static inline gboolean