From 7e170c34b02269faa8a083cb57a2f567af634828 Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Sun, 15 Jan 2012 23:12:29 +0100 Subject: [PATCH] Return -1 on getaddrinfo error and print error in debug mode --- src/modbus-tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 59e8cd2..c92f08f 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -342,8 +342,12 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx) ai_list = NULL; rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service, &ai_hints, &ai_list); - if (rc != 0) - return rc; + if (rc != 0) { + if (ctx->debug) { + printf("Error returned by getaddrinfo: %d\n", rc); + } + return -1; + } for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { int flags = ai_ptr->ai_socktype; -- libgit2 0.21.4