diff mbox

[v2] IAPP: Set SO_REUSEADDR on listening socket

Message ID 20160808154628.29274-1-bordjukov@gmail.com
State Accepted
Headers show

Commit Message

Petko Bordjukov Aug. 8, 2016, 3:46 p.m. UTC
Make it possible for several instances of hostapd to listen on the same
network interface.

Signed-off-by: Petko Bordjukov <bordjukov@gmail.com>
---

Changes since v1:

 * Fixed a mistake in the error message.
 * Made the inability to set SO_REUSEADDR not fatal

 src/ap/iapp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Jouni Malinen Aug. 18, 2016, 7:47 p.m. UTC | #1
On Mon, Aug 08, 2016 at 06:46:28PM +0300, Petko Bordjukov wrote:
> Make it possible for several instances of hostapd to listen on the same
> network interface.

Thanks, applied.
diff mbox

Patch

diff --git a/src/ap/iapp.c b/src/ap/iapp.c
index 07672ce..3fd0951 100644
--- a/src/ap/iapp.c
+++ b/src/ap/iapp.c
@@ -381,6 +381,7 @@  struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface)
 	struct sockaddr_in *paddr, uaddr;
 	struct iapp_data *iapp;
 	struct ip_mreqn mreq;
+	int reuseaddr = 1;
 
 	iapp = os_zalloc(sizeof(*iapp));
 	if (iapp == NULL)
@@ -443,6 +444,13 @@  struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface)
 	os_memset(&uaddr, 0, sizeof(uaddr));
 	uaddr.sin_family = AF_INET;
 	uaddr.sin_port = htons(IAPP_UDP_PORT);
+
+	if (setsockopt(iapp->udp_sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
+		       sizeof(reuseaddr)) < 0) {
+		wpa_printf(MSG_INFO, "iapp_init - setsockopt[UDP,SO_REUSEADDR]: %s",
+			   strerror(errno));
+	}
+
 	if (bind(iapp->udp_sock, (struct sockaddr *) &uaddr,
 		 sizeof(uaddr)) < 0) {
 		wpa_printf(MSG_INFO, "iapp_init - bind[UDP]: %s",