どっちでも動くTCP server (2) 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; 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");