Minor fix on getaddrinfo() in listen_on_port()

pull/762/head
René Cannaò 10 years ago
parent f28bd5a96d
commit a355bfedd1

@ -5,20 +5,22 @@
* returns the socket
*/
int listen_on_port(char *ip, uint16_t port, int backlog, bool reuseport) {
int arg_on = 1;
int rc, arg_on = 1;
struct addrinfo hints;
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
struct addrinfo *next, *ai;
char port_string[NI_MAXSERV];
int sd = -1;
snprintf(port_string, sizeof(port_string), "%d", port);
if (getaddrinfo(ip, port_string, &hints, &ai) != 0) {
proxy_error("getaddrinfo(): %s\n", gai_strerror(errno));
return -1;
}
rc = getaddrinfo(ip, port_string, &hints, &ai);
if (rc) {
proxy_error("getaddrinfo(): %s\n", gai_strerror(rc));
return -1;
}
for (next = ai; next != NULL; next = next->ai_next) {
if ((sd = socket(next->ai_family, next->ai_socktype, next->ai_protocol)) == -1)

Loading…
Cancel
Save