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>
This commit is contained in:
parent
15b97bc3b5
commit
4307bb8c85
3 changed files with 28 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -286,6 +286,8 @@ int wpa_ctrl_pending(struct wpa_ctrl *ctrl);
|
|||
*/
|
||||
int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl);
|
||||
|
||||
char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl);
|
||||
|
||||
#ifdef ANDROID
|
||||
/**
|
||||
* wpa_ctrl_cleanup() - Delete any local UNIX domain socket files that
|
||||
|
|
|
@ -3806,6 +3806,7 @@ static void wpa_cli_edit_eof_cb(void *ctx)
|
|||
static void wpa_cli_interactive(void)
|
||||
{
|
||||
char *home, *hfile = NULL;
|
||||
const char *ps = wpa_ctrl_get_remote_ifname(ctrl_conn);
|
||||
|
||||
printf("\nInteractive mode\n\n");
|
||||
|
||||
|
@ -3820,7 +3821,7 @@ static void wpa_cli_interactive(void)
|
|||
|
||||
eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL);
|
||||
edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
|
||||
wpa_cli_edit_completion_cb, NULL, hfile, NULL);
|
||||
wpa_cli_edit_completion_cb, NULL, hfile, ps);
|
||||
eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
|
||||
|
||||
eloop_run();
|
||||
|
|
Loading…
Reference in a new issue