Skip to content

Commit f2a619d

Browse files
committed
Make gai_strerror optional via configuration
Check via usual autoconf and when not present print just the error code instead of the readable string. Useful for compact embedded stacks where this is not present.
1 parent fe12169 commit f2a619d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ AC_CHECK_DECLS([__CYGWIN__])
105105
AC_SEARCH_LIBS(accept, network socket)
106106

107107
# Checks for library functions.
108-
AC_CHECK_FUNCS([accept4 getaddrinfo gettimeofday inet_pton inet_ntop select socket strerror strlcpy])
108+
AC_CHECK_FUNCS([accept4 gai_strerror getaddrinfo gettimeofday inet_pton inet_ntop select socket strerror strlcpy])
109109

110110
# Required for MinGW with GCC v4.8.1 on Win7
111111
AC_DEFINE(WINVER, 0x0501, _)

src/modbus-tcp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx)
403403
rc = getaddrinfo(ctx_tcp_pi->node, ctx_tcp_pi->service, &ai_hints, &ai_list);
404404
if (rc != 0) {
405405
if (ctx->debug) {
406+
#ifdef HAVE_GAI_STRERROR
406407
fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
408+
#else
409+
fprintf(stderr, "Error returned by getaddrinfo: %d\n", rc);
410+
#endif
407411
}
408412
freeaddrinfo(ai_list);
409413
errno = ECONNREFUSED;
@@ -629,7 +633,11 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
629633
rc = getaddrinfo(node, service, &ai_hints, &ai_list);
630634
if (rc != 0) {
631635
if (ctx->debug) {
636+
#ifdef HAVE_GAI_STRERROR
632637
fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
638+
#else
639+
fprintf(stderr, "Error returned by getaddrinfo: %d\n", rc);
640+
#endif
633641
}
634642
freeaddrinfo(ai_list);
635643
errno = ECONNREFUSED;

0 commit comments

Comments
 (0)