Commit 05efa1f7dd327a1895d8585e9bed9f7aa9cdf68a

Authored by Stéphane Raimbault
1 parent 0c36a6e7

Fix compilation of TCP PI on Windows

- removed ENOTCONN errno not supported
- set WINVER to Windows XP (and above) and add ws2_32.dll. So older
  Windows versions aren't supported.
configure.ac
@@ -114,6 +114,13 @@ if test "x$GCC" = "xyes"; then @@ -114,6 +114,13 @@ if test "x$GCC" = "xyes"; then
114 esac 114 esac
115 fi 115 fi
116 116
  117 +# Required for getaddrinfo (TCP PI - IPv6)
  118 +AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes)
  119 +if test "x$HAVE_WINSOCK2_H" = "xyes"; then
  120 + LIBS="$LIBS -lws2_32"
  121 + AC_SUBST(LIBS)
  122 +fi
  123 +
117 AC_CONFIG_FILES([ 124 AC_CONFIG_FILES([
118 Makefile 125 Makefile
119 src/Makefile 126 src/Makefile
src/modbus-tcp.c
@@ -25,7 +25,11 @@ @@ -25,7 +25,11 @@
25 25
26 #if defined(_WIN32) 26 #if defined(_WIN32)
27 # define OS_WIN32 27 # define OS_WIN32
28 -# include <winsock2.h> 28 +/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
  29 + * minwg32 headers check WINVER before allowing the use of these */
  30 +# ifndef WINVER
  31 +# define WINVER 0x0501
  32 +# endif
29 # include <ws2tcpip.h> 33 # include <ws2tcpip.h>
30 # define SHUT_RDWR 2 34 # define SHUT_RDWR 2
31 # define close closesocket 35 # define close closesocket
@@ -304,7 +308,6 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx) @@ -304,7 +308,6 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx)
304 freeaddrinfo(ai_list); 308 freeaddrinfo(ai_list);
305 309
306 if (ctx->s < 0) { 310 if (ctx->s < 0) {
307 - errno = ENOTCONN;  
308 return -1; 311 return -1;
309 } 312 }
310 313
@@ -480,7 +483,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) @@ -480,7 +483,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
480 freeaddrinfo(ai_list); 483 freeaddrinfo(ai_list);
481 484
482 if (new_socket < 0) { 485 if (new_socket < 0) {
483 - errno = ENOTCONN;  
484 return -1; 486 return -1;
485 } 487 }
486 488