[PATCH 1/3] Add ipv4 support function for "get" control interface command

Mikael Kanstrup mikael.kanstrup at gmail.com
Sat Mar 14 19:37:06 EDT 2015


From: Mikael Kanstrup <mikael.kanstrup at sonymobile.com>

Add support to retrieve ipv4 config variables with the "get" control
interface command.

Signed-off-by: Mikael Kanstrup <mikael.kanstrup at sonymobile.com>
---
 wpa_supplicant/config.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index 8e6cd20..d69a5b6 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -4051,6 +4051,29 @@ static int wpa_config_get_str(const char *name, struct wpa_config *config,
 	return res;
 }
 
+#ifdef CONFIG_P2P
+static int wpa_config_get_ipv4(const char *name, struct wpa_config *config,
+			       long offset, char *buf, size_t buflen,
+			       int pretty_print)
+{
+	void *val = ((u8 *) config) + (long) offset;
+	int res;
+	char addr[INET_ADDRSTRLEN];
+
+	if (!val || !inet_ntop(AF_INET, val, addr, sizeof(addr)))
+		return -1;
+
+	if (pretty_print)
+		res = os_snprintf(buf, buflen, "%s=%s\n", name, addr);
+	else
+		res = os_snprintf(buf, buflen, "%s", addr);
+
+	if (os_snprintf_error(buflen, res))
+		res = -1;
+
+	return res;
+}
+#endif /* CONFIG_P2P */
 
 #ifdef OFFSET
 #undef OFFSET
@@ -4067,7 +4090,8 @@ static int wpa_config_get_str(const char *name, struct wpa_config *config,
 #define STR(f) _STR(f), NULL, NULL
 #define STR_RANGE(f, min, max) _STR(f), (void *) min, (void *) max
 #define BIN(f) #f, wpa_global_config_parse_bin, NULL, OFFSET(f), NULL, NULL
-#define IPV4(f) #f, wpa_global_config_parse_ipv4, NULL, OFFSET(f), NULL, NULL
+#define IPV4(f) #f, wpa_global_config_parse_ipv4, wpa_config_get_ipv4,  \
+	OFFSET(f), NULL, NULL
 
 static const struct global_parse_data global_fields[] = {
 #ifdef CONFIG_CTRL_IFACE
-- 
1.8.2.2



More information about the HostAP mailing list