1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-31 00:34:20 +00:00

inet_pton for winxp

This commit is contained in:
R4SAS 2019-02-05 14:13:23 +03:00
parent bd5122c6ea
commit 9c76368dbc

View File

@ -9,6 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sysinfoapi.h>
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <iphlpapi.h> #include <iphlpapi.h>
@ -21,8 +22,8 @@
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* // No more needed. Exists in MinGW. // inet_pton exists in Windows Vista, but XP haven't that function!
int inet_pton(int af, const char *src, void *dst) int inet_pton_xp(int af, const char *src, void *dst)
{ // This function was written by Petar Korponai?. See http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found { // This function was written by Petar Korponai?. See http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found
struct sockaddr_storage ss; struct sockaddr_storage ss;
int size = sizeof (ss); int size = sizeof (ss);
@ -45,7 +46,7 @@ int inet_pton(int af, const char *src, void *dst)
} }
} }
return 0; return 0;
}*/ }
#else /* !WIN32 => UNIX */ #else /* !WIN32 => UNIX */
#include <sys/types.h> #include <sys/types.h>
#include <ifaddrs.h> #include <ifaddrs.h>
@ -58,6 +59,20 @@ namespace util
namespace net namespace net
{ {
#ifdef WIN32 #ifdef WIN32
bool IsWindowsXPorLater() {
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if (osvi.dwMajorVersion <= 5)
return true;
else
return false;
}
int GetMTUWindowsIpv4(sockaddr_in inputAddress, int fallback) int GetMTUWindowsIpv4(sockaddr_in inputAddress, int fallback)
{ {
ULONG outBufLen = 0; ULONG outBufLen = 0;
@ -175,6 +190,9 @@ namespace net
std::string localAddressUniversal = localAddress.to_string(); std::string localAddressUniversal = localAddress.to_string();
#endif #endif
if (IsWindowsXPorLater())
#define inet_pton inet_pton_xp
if(localAddress.is_v4()) { if(localAddress.is_v4()) {
sockaddr_in inputAddress; sockaddr_in inputAddress;
inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr)); inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr));