[PATCH 21/42] util: Add address family set/get/reset helpers
Jussi Laakkonen <[email protected]> Fri, 21 Nov 2025 17:31:41 +0200
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Add address family (af) helper functions to be used for defining which
address families a provider has. Supports AF_INET and AF_INET6 as
set/get parameters.
---
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..0bfce5d5 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(struct supported_afs *afs, int family)
+{
+ if (!afs)
+ return;
+
+ switch (family) {
+ case AF_INET:
+ afs->af_inet = true;
+ break;
+ case AF_INET6:
+ afs->af_inet6 = true;
+ break;
+ default:
+ break;
+ }
+}
+
+bool util_get_afs(struct supported_afs *afs, int family)
+{
+ if (!afs)
+ return false;
+
+ switch (family) {
+ case AF_INET:
+ return afs->af_inet;
+ case AF_INET6:
+ return afs->af_inet6;
+ default:
+ return false;
+ }
+}
+
+void util_reset_afs(struct supported_afs *afs)
+{
+ if (!afs)
+ return;
+
+ afs->af_inet = afs->af_inet6 = false;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 430b821f..30630f93 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -24,6 +24,8 @@
#include <sys/time.h>
#include <glib.h>
+#include <stdbool.h>
+#include <arpa/inet.h>
typedef void (*util_debug_func_t)(const char *str, void *user_data);
@@ -53,3 +55,12 @@ 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);
+
+struct supported_afs {
+ bool af_inet;
+ bool af_inet6;
+};
+
+void util_set_afs(struct supported_afs *afs, int family);
+bool util_get_afs(struct supported_afs *afs, int family);
+void util_reset_afs(struct supported_afs *afs);
--
2.47.3