aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/wpa_ctrl.c
diff options
context:
space:
mode:
authorJanusz Dziedzic <janusz.dziedzic@tieto.com>2012-08-05 17:50:17 (GMT)
committerJouni Malinen <j@w1.fi>2012-08-05 17:50:17 (GMT)
commit4307bb8c850bbec350f51978d4442ae320079b2e (patch)
tree1acbf1db8a5d7ef67dfa2af4c91e0210f875f992 /src/common/wpa_ctrl.c
parent15b97bc3b514dd942cfd303cb168656060b7132c (diff)
downloadhostap-4307bb8c850bbec350f51978d4442ae320079b2e.zip
hostap-4307bb8c850bbec350f51978d4442ae320079b2e.tar.gz
hostap-4307bb8c850bbec350f51978d4442ae320079b2e.tar.bz2
wpa_cli: Print nice prompt when using remote UDP
When CONFIG_CTRL_IFACE=udp-remote is used, print user frendly PS in wpa_cli. E.g., localhost/wlan0> 192.168.1.1/p2p-wlan-0-0> Signed-hostap: Janusz Dziedzic <janusz.dziedzic@tieto.com>
Diffstat (limited to 'src/common/wpa_ctrl.c')
-rw-r--r--src/common/wpa_ctrl.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index 9b67278..58cbe6a 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -49,6 +49,8 @@ struct wpa_ctrl {
struct sockaddr_in local;
struct sockaddr_in dest;
char *cookie;
+ char *remote_ifname;
+ char *remote_ip;
#endif /* CONFIG_CTRL_IFACE_UDP */
#ifdef CONFIG_CTRL_IFACE_UNIX
int s;
@@ -302,23 +304,27 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
port_id = WPA_CTRL_IFACE_PORT;
h = gethostbyname(name);
+ ctrl->remote_ip = os_strdup(name);
os_free(name);
if (h == NULL) {
perror("gethostbyname");
close(ctrl->s);
+ os_free(ctrl->remote_ip);
os_free(ctrl);
return NULL;
}
ctrl->dest.sin_port = htons(port_id);
os_memcpy(h->h_addr, (char *) &ctrl->dest.sin_addr.s_addr,
h->h_length);
- }
+ } else
+ ctrl->remote_ip = os_strdup("localhost");
#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
sizeof(ctrl->dest)) < 0) {
perror("connect");
close(ctrl->s);
+ os_free(ctrl->remote_ip);
os_free(ctrl);
return NULL;
}
@@ -329,14 +335,31 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
ctrl->cookie = os_strdup(buf);
}
+ if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) {
+ buf[len] = '\0';
+ ctrl->remote_ifname = os_strdup(buf);
+ }
+
return ctrl;
}
+char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl)
+{
+#define WPA_CTRL_MAX_PS_NAME 100
+ static char ps[WPA_CTRL_MAX_PS_NAME] = {};
+ os_snprintf(ps, WPA_CTRL_MAX_PS_NAME, "%s/%s",
+ ctrl->remote_ip, ctrl->remote_ifname);
+ return ps;
+}
+
+
void wpa_ctrl_close(struct wpa_ctrl *ctrl)
{
close(ctrl->s);
os_free(ctrl->cookie);
+ os_free(ctrl->remote_ifname);
+ os_free(ctrl->remote_ip);
os_free(ctrl);
}