Hi,

On Thu, Nov 24, 2011 at 08:51:28PM +0100, Gert Doering wrote:
> So here's the patch - it compiles (MSVC on Win7), the resulting binary
> works on WinXP, and it's not too ugly - actually it removes more #ifdef's
> that it adds...
> 
> Let me know your comments.

So David found it confusing, and I agree to some extend :-) - it's
easier to see what is happening if we declare our replacement functions
as openvpn_inet_ntop() and openvpn_inet_pton() right away, instead of
having the preprocessor #define rename them on the fly.

new patch.

gert

-- 
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             g...@greenie.muc.de
fax: +49-89-35655025                        g...@net.informatik.tu-muenchen.de
From 0d49be3449e86365364378f48393e5e2b75a1045 Mon Sep 17 00:00:00 2001
From: Gert Doering <g...@greenie.muc.de>
List-Post: openvpn-devel@lists.sourceforge.net
Date: Thu, 24 Nov 2011 21:09:36 +0100
Subject: [PATCH] work around inet_ntop/inet_pton problems for MSVC builds on
 WinXP

always use our built-in replacement functions now, even if building
on Win7 (which has inet_ntop/inet_pton in the system libraries) because
the resulting binary will then fail on WinXP.

Signed-off-by: Gert Doering <g...@greenie.muc.de>
---
 socket.c |    9 ++++-----
 win32.h  |   10 ++++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/socket.c b/socket.c
index 5302eca..c8a86ea 100644
--- a/socket.c
+++ b/socket.c
@@ -3083,11 +3083,12 @@ link_socket_write_udp_posix_sendmsg (struct link_socket 
*sock,
 /*
  * inet_ntop() and inet_pton() wrap-implementations using
  * WSAAddressToString() and WSAStringToAddress() functions
+ *
+ * this is needed as long as we support running OpenVPN on WinXP
  */
 
-#ifndef _MSC_VER
 const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size)
+openvpn_inet_ntop(int af, const void *src, char *dst, socklen_t size)
 {
   struct sockaddr_storage ss;
   unsigned long s = size;
@@ -3111,7 +3112,7 @@ inet_ntop(int af, const void *src, char *dst, socklen_t 
size)
 }
 
 int
-inet_pton(int af, const char *src, void *dst)
+openvpn_inet_pton(int af, const char *src, void *dst)
 {
   struct sockaddr_storage ss;
   int size = sizeof(ss);
@@ -3134,8 +3135,6 @@ inet_pton(int af, const char *src, void *dst)
   return 0;
 }
 
-#endif
-
 int
 socket_recv_queue (struct link_socket *sock, int maxsize)
 {
diff --git a/win32.h b/win32.h
index 5b18e3c..0607cad 100644
--- a/win32.h
+++ b/win32.h
@@ -278,10 +278,12 @@ char *get_win_sys_path (void);
 
 /* call self in a subprocess */
 void fork_to_self (const char *cmdline);
-#ifndef _MSC_VER
-const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
-int inet_pton(int af, const char *src, void *st);
-#endif
+
+const char *openvpn_inet_ntop(int af, const void *src, 
+                              char *dst, socklen_t size);
+int openvpn_inet_pton(int af, const char *src, void *dst);
+#define inet_ntop(af,src,dst,size) openvpn_inet_ntop(af,src,dst,size)
+#define inet_pton(af,src,dst)      openvpn_inet_pton(af,src,dst)
 
 /* Find temporary directory */
 const char *win_get_tempdir();
-- 
1.7.4.4

Attachment: pgpzI8GWndwpH.pgp
Description: PGP signature

Reply via email to