Server rewrite, lazy - After the rewrite s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) exit(1); #ifdef IPV6_V6ONLY if (res->ai_family == AF_INET6 && setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) { close(s); continue; } #endif if (bind(s, res->ai_addr, res->ai_addrlen) < 0) exit(1); listen(s, 5); freeaddrinfo(res);