From 05efa1f7dd327a1895d8585e9bed9f7aa9cdf68a Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Sun, 27 Feb 2011 17:55:09 +0100 Subject: [PATCH] Fix compilation of TCP PI on Windows --- configure.ac | 7 +++++++ src/modbus-tcp.c | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index a5a4855..ffc2472 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,13 @@ if test "x$GCC" = "xyes"; then esac fi +# Required for getaddrinfo (TCP PI - IPv6) +AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes) +if test "x$HAVE_WINSOCK2_H" = "xyes"; then + LIBS="$LIBS -lws2_32" + AC_SUBST(LIBS) +fi + AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index df68738..746a866 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -25,7 +25,11 @@ #if defined(_WIN32) # define OS_WIN32 -# include +/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later. + * minwg32 headers check WINVER before allowing the use of these */ +# ifndef WINVER +# define WINVER 0x0501 +# endif # include # define SHUT_RDWR 2 # define close closesocket @@ -304,7 +308,6 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx) freeaddrinfo(ai_list); if (ctx->s < 0) { - errno = ENOTCONN; return -1; } @@ -480,7 +483,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) freeaddrinfo(ai_list); if (new_socket < 0) { - errno = ENOTCONN; return -1; } -- libgit2 0.21.4