1
0
Fork 0

IPv6: Windows XP doesn't have the inet_pton() function, resorting to custom-formatting the address

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1257 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-03-05 20:46:40 +00:00
parent fcdc68fd8e
commit 469d08ec42
2 changed files with 20 additions and 3 deletions

View File

@ -92,6 +92,9 @@ typedef unsigned short UInt16;
// OS-dependent stuff:
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x501 // We want to target WinXP and higher
#include <Windows.h>
#include <winsock2.h>
#include <Ws2tcpip.h> // IPv6 stuff

View File

@ -293,9 +293,23 @@ cSocket cSocket::AcceptIPv6(void)
// Get IP in string form:
if (SClient.IsValid())
{
char buffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(from.sin6_addr), buffer, sizeof(buffer));
SClient.m_IPString.assign(buffer);
#if defined(_WIN32)
// Windows XP doesn't have inet_ntop, so we need to improvise:
Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x",
from.sin6_addr.u.Word[0],
from.sin6_addr.u.Word[1],
from.sin6_addr.u.Word[2],
from.sin6_addr.u.Word[3],
from.sin6_addr.u.Word[4],
from.sin6_addr.u.Word[5],
from.sin6_addr.u.Word[6],
from.sin6_addr.u.Word[7]
);
#else
char buffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(from.sin6_addr), buffer, sizeof(buffer));
SClient.m_IPString.assign(buffer);
#endif // _WIN32
}
return SClient;
}