return addr_buf[i];
}
-int bindport(int type, char *port) {
- struct addrinfo hints, *res0, *res;
- int s, one = 1;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_socktype = type;
- hints.ai_family = AF_UNSPEC;
- hints.ai_flags = AI_PASSIVE;
-
- if (getaddrinfo(NULL, port, &hints, &res0) != 0) {
- err("bindport: can't resolve port %s", port);
- return -1;
- }
- for (res = res0; res; res = res->ai_next) {
- s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- if (s >= 0) {
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
- if (bind(s, res->ai_addr, res->ai_addrlen) == 0)
- break;
- close(s);
- s = -1;
- }
- }
- freeaddrinfo(res0);
- return s;
-}
-
int connectport(int type, char *host, char *port) {
struct addrinfo hints, *res0, *res;
int s;