Server rewrite - After the rewrite i = 0; for (res = res0; res; res = res->ai_next) { s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) continue; #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) { close(s); continue; } listen(s, 5); socktable[i] = s; sockfamily[i++] = res->ai_family; } freeaddrinfo(res0); if (i == 0) errx(1, "no bind() successful");