Selaa lähdekoodia

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.
Stéphane Raimbault 14 vuotta sitten
vanhempi
commit
05efa1f7dd
2 muutettua tiedostoa jossa 12 lisäystä ja 3 poistoa
  1. 7 0
      configure.ac
  2. 5 3
      src/modbus-tcp.c

+ 7 - 0
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

+ 5 - 3
src/modbus-tcp.c

@@ -25,7 +25,11 @@
 
 #if defined(_WIN32)
 # define OS_WIN32
-# include <winsock2.h>
+/* 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 <ws2tcpip.h>
 # 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;
     }