[RFC 2/4] wpa_cli: add support for remote access

Janusz.Dziedzic at tieto.com Janusz.Dziedzic
Thu Aug 2 04:01:31 PDT 2012


wpa_cli can be used now as a client for
remote access to ctrl_interface of wpa_supplicant
when UDP and remote options are used.

You can simply run:
wpa_cli -i <hostname>:[port]
wpa_cli -i <IP>:[port]

Signed-hostap: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
 src/common/wpa_ctrl.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index b2b0683..fe07c02 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -26,6 +26,9 @@
 
 #if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
 #define CTRL_IFACE_SOCKET
+#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
+#include <netdb.h>
+#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
 #endif /* CONFIG_CTRL_IFACE_UNIX || CONFIG_CTRL_IFACE_UDP */
 
 
@@ -230,6 +233,9 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
 	struct wpa_ctrl *ctrl;
 	char buf[128];
 	size_t len;
+#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
+	struct hostent *h;
+#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
 
 	ctrl = os_malloc(sizeof(*ctrl));
 	if (ctrl == NULL)
@@ -244,7 +250,11 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
 	}
 
 	ctrl->local.sin_family = AF_INET;
+#ifndef CONFIG_CTRL_IFACE_UDP_REMOTE
 	ctrl->local.sin_addr.s_addr = htonl((127 << 24) | 1);
+#else
+	ctrl->local.sin_addr.s_addr = INADDR_ANY;
+#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
 	if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
 		 sizeof(ctrl->local)) < 0) {
 		close(ctrl->s);
@@ -253,8 +263,37 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
 	}
 
 	ctrl->dest.sin_family = AF_INET;
+#ifndef CONFIG_CTRL_IFACE_UDP_REMOTE
 	ctrl->dest.sin_addr.s_addr = htonl((127 << 24) | 1);
 	ctrl->dest.sin_port = htons(WPA_CTRL_IFACE_PORT);
+#else
+	if (ctrl_path) {
+		char *port, *name;
+		int port_id;
+
+		name = strdup(ctrl_path);
+		port = strchr(name, ':');
+
+		if (port) {
+			port_id = atoi(&port[1]);
+			port[0] = '\0';
+		} else
+			port_id = WPA_CTRL_IFACE_PORT;
+
+		printf("UDP remote host: %s, port: %d\n", name, port_id);
+		h = gethostbyname(name);
+		free(name);
+		if (h == NULL) {
+			perror("gethostbyname");
+			close(ctrl->s);
+			os_free(ctrl);
+			return NULL;
+		}
+		ctrl->dest.sin_port = htons(port_id);
+		bcopy(h->h_addr, (char *) &ctrl->dest.sin_addr.s_addr,
+		      h->h_length);
+	}
+#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
 	if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
 		    sizeof(ctrl->dest)) < 0) {
 		perror("connect");
-- 
1.7.0.4




More information about the Hostap mailing list