tcp_server (struct addrinfo *ai)
{
int fd;
+ int optval = 1;
fd = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (fd < 0)
return -1;
+ setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (int));
if (bind (fd, ai->ai_addr, ai->ai_addrlen) < 0)
{
close (fd);