From 540d3795a91ae24b5fd7e29af4385a7d1681ed2e Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 6 Feb 2014 22:50:23 +0100 Subject: [PATCH] Switch from inet_pton() to getnameinfo() for portability Windows XP is supported again --- README-win32.txt | 2 +- src/common.c | 7 +++---- src/osflags | 3 +++ src/windows.h | 9 --------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/README-win32.txt b/README-win32.txt index 4a371f1..de9124b 100644 --- a/README-win32.txt +++ b/README-win32.txt @@ -9,7 +9,7 @@ Extra README file for Win32 related stuff == Running iodine on Windows: -0. After iodine 0.6, you need Windows Vista or newer to run. +0. After iodine 0.6, you need Windows XP or newer to run. 1. Install the TAP32 driver http://openvpn.net/index.php/open-source/downloads.html diff --git a/src/common.c b/src/common.c index 1edd087..1dcecbd 100644 --- a/src/common.c +++ b/src/common.c @@ -120,17 +120,16 @@ format_addr(struct sockaddr_storage *sockaddr, int sockaddr_len) memset(dst, 0, sizeof(dst)); if (sockaddr->ss_family == AF_INET && sockaddr_len >= sizeof(struct sockaddr_in)) { - struct sockaddr_in *addr = (struct sockaddr_in *) sockaddr; - inet_ntop(addr->sin_family, &addr->sin_addr, dst, sizeof(dst) - 1); + getnameinfo((struct sockaddr *)sockaddr, sockaddr_len, dst, sizeof(dst) - 1, NULL, 0, NI_NUMERICHOST); } else if (sockaddr->ss_family == AF_INET6 && sockaddr_len >= sizeof(struct sockaddr_in6)) { struct sockaddr_in6 *addr = (struct sockaddr_in6 *) sockaddr; if (IN6_IS_ADDR_V4MAPPED(&addr->sin6_addr)) { struct in_addr ia; /* Get mapped v4 addr from last 32bit field */ memcpy(&ia.s_addr, &addr->sin6_addr.s6_addr[12], sizeof(ia)); - inet_ntop(AF_INET, &ia, dst, sizeof(dst) - 1); + strcpy(dst, inet_ntoa(ia)); } else { - inet_ntop(addr->sin6_family, &addr->sin6_addr, dst, sizeof(dst) - 1); + getnameinfo((struct sockaddr *)sockaddr, sockaddr_len, dst, sizeof(dst) - 1, NULL, 0, NI_NUMERICHOST); } } else { dst[0] = '?'; diff --git a/src/osflags b/src/osflags index 4641b39..2d8a03b 100755 --- a/src/osflags +++ b/src/osflags @@ -26,6 +26,9 @@ link) ;; cflags) case $1 in + windows32) + echo '-DWINVER=0x0501'; + ;; BeOS) echo '-Dsocklen_t=int'; ;; diff --git a/src/windows.h b/src/windows.h index a002b55..db26995 100644 --- a/src/windows.h +++ b/src/windows.h @@ -17,15 +17,6 @@ #ifndef __FIX_WINDOWS_H__ #define __FIX_WINDOWS_H__ -#include -/* Need Vista or Later to get IPv6 support */ -#undef WINVER -#undef _WIN32_WINDOWS -#undef _WIN32_WINNT -#define WINVER WindowsVista -#define _WIN32_WINDOWS WindowsVista -#define _WIN32_WINNT WindowsVista - typedef unsigned int in_addr_t; #include