Add forgotten SO_REUSEADDR option

This commit is contained in:
Manuel Pégourié-Gonnard 2013-12-17 13:59:01 +01:00
parent 767f02cf6e
commit fd6b4cc1db

View file

@ -229,7 +229,7 @@ int net_connect( int *fd, const char *host, int port )
int net_bind( int *fd, const char *bind_ip, int port ) int net_bind( int *fd, const char *bind_ip, int port )
{ {
#if defined(POLARSSL_HAVE_IPV6) #if defined(POLARSSL_HAVE_IPV6)
int ret = POLARSSL_ERR_NET_UNKNOWN_HOST; int n, ret = POLARSSL_ERR_NET_UNKNOWN_HOST;
struct addrinfo hints, *addr_list, *cur; struct addrinfo hints, *addr_list, *cur;
char port_str[6]; char port_str[6];
@ -260,6 +260,10 @@ int net_bind( int *fd, const char *bind_ip, int port )
continue; continue;
} }
n = 1;
setsockopt( *fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &n, sizeof( n ) );
if( bind( *fd, cur->ai_addr, cur->ai_addrlen ) != 0 ) if( bind( *fd, cur->ai_addr, cur->ai_addrlen ) != 0 )
{ {
close( *fd ); close( *fd );