[PATCH 23/45] util: Add address family set/get/reset helpers
Jussi Laakkonen <[email protected]> Fri, 11 Jul 2025 17:27:14 +0300
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
[util] Add address family set/get/reset helpers. JB#62713
Add address family (af) helper functions to be used with a boolean array
defining which address families a provider has. Supports AF_INET and
AF_INET6 as set/get parameters. The array must be of AF_ARRAY_LENGTH
size.
---
src/shared/util.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/shared/util.h | 11 +++++++++++
2 files changed, 51 insertions(+)
diff --git a/src/shared/util.c b/src/shared/util.c
index bda2d2b3..22114029 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -128,3 +128,43 @@ char *util_timeval_to_iso8601(struct timeval *time)
return g_strdup(buf);
}
+
+void util_set_afs(bool *afs, int family)
+{
+ if (!afs)
+ return;
+
+ switch (family) {
+ case AF_INET:
+ afs[AF_INET_POS] = true;
+ break;
+ case AF_INET6:
+ afs[AF_INET6_POS] = true;
+ break;
+ default:
+ break;
+ }
+}
+
+bool util_get_afs(bool *afs, int family)
+{
+ if (!afs)
+ return false;
+
+ switch (family) {
+ case AF_INET:
+ return afs[AF_INET_POS];
+ case AF_INET6:
+ return afs[AF_INET6_POS];
+ default:
+ return false;
+ }
+}
+
+void util_reset_afs(bool *afs)
+{
+ if (!afs)
+ return;
+
+ afs[AF_INET_POS] = afs[AF_INET6_POS] = false;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 430b821f..c5a763c4 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -24,6 +24,13 @@
#include <sys/time.h>
#include <glib.h>
+#include <stdbool.h>
+#include <inet.h>
+#include <arpa/inet.h>
+
+#define AF_INET_POS 0
+#define AF_INET6_POS 1
+#define AF_ARRAY_LENGTH 2
typedef void (*util_debug_func_t)(const char *str, void *user_data);
@@ -53,3 +60,7 @@ static inline struct cb_data *cb_data_new(void *cb, void *user_data)
void util_iso8601_to_timeval(char *str, struct timeval *time);
char *util_timeval_to_iso8601(struct timeval *time);
+
+void util_set_afs(bool *afs, int family);
+bool util_get_afs(bool *afs, int family);
+void util_reset_afs(bool *afs);
--
2.39.5