From a355bfedd1471043e5068ec2db7f6efa876ab614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 21 Oct 2016 22:35:46 +0000 Subject: [PATCH] Minor fix on getaddrinfo() in listen_on_port() --- lib/network.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/network.cpp b/lib/network.cpp index 542098f83..ef62022bc 100644 --- a/lib/network.cpp +++ b/lib/network.cpp @@ -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)