|
@ -156,13 +156,20 @@ create_and_bind(const char *addr, const char *port) |
|
|
memset(&hints, 0, sizeof(struct addrinfo)); |
|
|
memset(&hints, 0, sizeof(struct addrinfo)); |
|
|
hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ |
|
|
hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ |
|
|
hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ |
|
|
hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ |
|
|
|
|
|
result = NULL; |
|
|
|
|
|
|
|
|
s = getaddrinfo(addr, port, &hints, &result); |
|
|
s = getaddrinfo(addr, port, &hints, &result); |
|
|
|
|
|
|
|
|
if (s != 0) { |
|
|
if (s != 0) { |
|
|
LOGI("getaddrinfo: %s", gai_strerror(s)); |
|
|
LOGI("getaddrinfo: %s", gai_strerror(s)); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (result == NULL) { |
|
|
|
|
|
LOGE("Could not bind"); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (rp = result; rp != NULL; rp = rp->ai_next) { |
|
|
for (rp = result; rp != NULL; rp = rp->ai_next) { |
|
|
listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
|
|
listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
|
|
if (listen_sock == -1) { |
|
|
if (listen_sock == -1) { |
|
@ -190,11 +197,7 @@ create_and_bind(const char *addr, const char *port) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
close(listen_sock); |
|
|
close(listen_sock); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (rp == NULL) { |
|
|
|
|
|
LOGE("Could not bind"); |
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
listen_sock = -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
freeaddrinfo(result); |
|
|
freeaddrinfo(result); |
|
|