From: Jouni Malinen Date: Fri, 14 Jun 2013 18:42:23 +0000 (-0700) Subject: HTTP server: Allow TCP socket to be reused X-Git-Tag: hostap_2_1~842 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e88060e1a791afe84f273c2fb15fa7d813a13b61;p=thirdparty%2Fhostap.git HTTP server: Allow TCP socket to be reused This makes it easier to handle cases where the application is restarted and the previously used local TCP port may not have been fully cleared in the network stack. Signed-hostap: Jouni Malinen --- diff --git a/src/wps/http_server.c b/src/wps/http_server.c index 6ca32140a..06c8bee24 100644 --- a/src/wps/http_server.c +++ b/src/wps/http_server.c @@ -232,6 +232,7 @@ struct http_server * http_server_init(struct in_addr *addr, int port, { struct sockaddr_in sin; struct http_server *srv; + int on = 1; srv = os_zalloc(sizeof(*srv)); if (srv == NULL) @@ -242,6 +243,9 @@ struct http_server * http_server_init(struct in_addr *addr, int port, srv->fd = socket(AF_INET, SOCK_STREAM, 0); if (srv->fd < 0) goto fail; + + setsockopt(srv->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + if (fcntl(srv->fd, F_SETFL, O_NONBLOCK) < 0) goto fail; if (port < 0)