Commit 7e170c34b02269faa8a083cb57a2f567af634828
1 parent
46281355
Return -1 on getaddrinfo error and print error in debug mode
Showing
1 changed file
with
6 additions
and
2 deletions
src/modbus-tcp.c
| @@ -342,8 +342,12 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx) | @@ -342,8 +342,12 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx) | ||
| 342 | ai_list = NULL; | 342 | ai_list = NULL; |
| 343 | rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service, | 343 | rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service, |
| 344 | &ai_hints, &ai_list); | 344 | &ai_hints, &ai_list); |
| 345 | - if (rc != 0) | ||
| 346 | - return rc; | 345 | + if (rc != 0) { |
| 346 | + if (ctx->debug) { | ||
| 347 | + printf("Error returned by getaddrinfo: %d\n", rc); | ||
| 348 | + } | ||
| 349 | + return -1; | ||
| 350 | + } | ||
| 347 | 351 | ||
| 348 | for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { | 352 | for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { |
| 349 | int flags = ai_ptr->ai_socktype; | 353 | int flags = ai_ptr->ai_socktype; |