From 1d507eaf013fdffb6c17f0f02f6ee9a91d44aa62 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 28 Jul 2013 06:32:40 +0200 Subject: [PATCH] Fix error handling for getaddrinfo(). --- src/connection.c | 7 ++++++- tests/client.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/connection.c b/src/connection.c index 36e0304..f608339 100644 --- a/src/connection.c +++ b/src/connection.c @@ -770,7 +770,12 @@ static int connect_to_host(const char *hostname, const char *port) { | AI_V4MAPPED; /* support IPv4 through IPv6 */ gai_return = getaddrinfo(hostname, port, &gai_hints, &gai_result); if (gai_return != 0) { - LOG_PERROR(LOG_WARNING, "connect_to_host(): getaddrinfo()"); + if (gai_return == EAI_SYSTEM) { + LOG_PERROR(LOG_WARNING, "connect_to_host(): getaddrinfo()"); + } else { + LOG(LOG_WARNING, "connect_to_host(): getaddrinfo(): %s", + gai_strerror(gai_return)); + } return -1; } diff --git a/tests/client.c b/tests/client.c index f98711f..d4edf7f 100644 --- a/tests/client.c +++ b/tests/client.c @@ -185,7 +185,12 @@ static int connect_to_host(const char *hostname, const char *port) { | AI_V4MAPPED; /* support IPv4 through IPv6 */ gai_return = getaddrinfo(hostname, port, &gai_hints, &gai_result); if (gai_return != 0) { - perror("connect_to_host(): getaddrinfo()"); + if (gai_return == EAI_SYSTEM) { + perror("connect_to_host(): getaddrinfo()"); + } else { + fprintf(stderr, "connect_to_host(): getaddrinfo(): %s", + gai_strerror(gai_return)); + } return -1; } -- 2.45.2