[PATCH v4 09/29] hostapd: ctrl udp allow to set port
Janusz Dziedzic
janusz.dziedzic at tieto.com
Fri Feb 26 01:38:24 PST 2016
Allow to setup port for ctrl and globa UDP iface.
The format is:
udp:<port_no>
eg.
wpa_supplicant -Dnl80211 -ddt -g udp:8888
or in conf file
ctrl_interface=udp:8877
Signed-off-by: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
hostapd/ctrl_iface.c | 28 ++++++++++++++++++++++++++--
hostapd/main.c | 5 +++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 89aad34..c419426 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -2446,6 +2446,7 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
{
int port = HOSTAPD_CTRL_IFACE_PORT;
char p[32]={0};
+ char *pos;
struct addrinfo hints = { 0 }, *res, *saveres;
int n;
@@ -2457,6 +2458,16 @@ int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
if (hapd->conf->ctrl_interface == NULL)
return 0;
+ pos = os_strstr(hapd->conf->ctrl_interface, "udp:");
+ if (pos) {
+ pos += 4;
+ port = atoi(pos);
+ if (!port) {
+ wpa_printf(MSG_ERROR, "invalid ctrl udp port");
+ goto fail;
+ }
+ }
+
dl_list_init(&hapd->ctrl_dst);
hapd->ctrl_sock = -1;
os_get_random(cookie, COOKIE_LEN);
@@ -2489,7 +2500,8 @@ try_again:
if (bind(hapd->ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
port--;
- if ((HOSTAPD_CTRL_IFACE_PORT - port) < HOSTAPD_CTRL_IFACE_PORT_LIMIT)
+ if ((HOSTAPD_CTRL_IFACE_PORT - port) < HOSTAPD_CTRL_IFACE_PORT_LIMIT &&
+ !pos)
goto try_again;
wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
goto fail;
@@ -3163,6 +3175,7 @@ int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
{
int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
char p[32]={0};
+ char *pos;
struct addrinfo hints = { 0 }, *res, *saveres;
int n;
@@ -3174,6 +3187,16 @@ int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
if (interface->global_iface_path == NULL)
return 0;
+ pos = os_strstr(interface->global_iface_path, "udp:");
+ if (pos) {
+ pos += 4;
+ port = atoi(pos);
+ if (!port) {
+ wpa_printf(MSG_ERROR, "invalid global ctrl udp port");
+ goto fail;
+ }
+ }
+
dl_list_init(&interface->global_ctrl_dst);
interface->global_ctrl_sock = -1;
os_get_random(gcookie, COOKIE_LEN);
@@ -3206,7 +3229,8 @@ try_again:
if (bind(interface->global_ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
port++;
- if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) < HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT)
+ if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) < HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT &&
+ !pos)
goto try_again;
wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
goto fail;
diff --git a/hostapd/main.c b/hostapd/main.c
index 6c4e195..47df24d 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -489,6 +489,11 @@ static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
interfaces->global_iface_path = os_strdup(path);
if (interfaces->global_iface_path == NULL)
return -1;
+
+#ifdef CONFIG_CTRL_IFACE_UDP
+ return 0;
+#endif
+
pos = os_strrchr(interfaces->global_iface_path, '/');
if (pos == NULL) {
wpa_printf(MSG_ERROR, "No '/' in the global control interface "
--
1.9.1
More information about the Hostap
mailing list