|
|
|
@ -9,6 +9,7 @@
@@ -9,6 +9,7 @@
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <sysinfoapi.h> |
|
|
|
|
#include <winsock2.h> |
|
|
|
|
#include <ws2tcpip.h> |
|
|
|
|
#include <iphlpapi.h> |
|
|
|
@ -21,8 +22,8 @@
@@ -21,8 +22,8 @@
|
|
|
|
|
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) |
|
|
|
|
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) |
|
|
|
|
|
|
|
|
|
/* // No more needed. Exists in MinGW.
|
|
|
|
|
int inet_pton(int af, const char *src, void *dst) |
|
|
|
|
// inet_pton exists in Windows Vista, but XP haven't that function!
|
|
|
|
|
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
|
|
|
|
|
struct sockaddr_storage ss; |
|
|
|
|
int size = sizeof (ss); |
|
|
|
@ -45,7 +46,7 @@ int inet_pton(int af, const char *src, void *dst)
@@ -45,7 +46,7 @@ int inet_pton(int af, const char *src, void *dst)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
}*/ |
|
|
|
|
} |
|
|
|
|
#else /* !WIN32 => UNIX */ |
|
|
|
|
#include <sys/types.h> |
|
|
|
|
#include <ifaddrs.h> |
|
|
|
@ -58,6 +59,20 @@ namespace util
@@ -58,6 +59,20 @@ namespace util
|
|
|
|
|
namespace net |
|
|
|
|
{ |
|
|
|
|
#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) |
|
|
|
|
{ |
|
|
|
|
ULONG outBufLen = 0; |
|
|
|
@ -175,6 +190,9 @@ namespace net
@@ -175,6 +190,9 @@ namespace net
|
|
|
|
|
std::string localAddressUniversal = localAddress.to_string(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (IsWindowsXPorLater()) |
|
|
|
|
#define inet_pton inet_pton_xp |
|
|
|
|
|
|
|
|
|
if(localAddress.is_v4()) { |
|
|
|
|
sockaddr_in inputAddress; |
|
|
|
|
inet_pton(AF_INET, localAddressUniversal.c_str(), &(inputAddress.sin_addr)); |
|
|
|
|