2018-11-19 07:55:19 +00:00
|
|
|
#if defined(__MINGW32__) && !defined(_WIN64)
|
|
|
|
/*
|
|
|
|
* Contains routines missing from WS2_32.DLL until 2006, if yer using
|
|
|
|
* Microsoft C/C++, then this code is irrelevant, as the official
|
|
|
|
* Platform SDK already links against these routines in the correct
|
|
|
|
* libraries.
|
|
|
|
*
|
|
|
|
* -despair86 30/07/18
|
|
|
|
*/
|
|
|
|
|
|
|
|
// these need to be in a specific order
|
|
|
|
#include <assert.h>
|
2019-08-14 22:45:49 +00:00
|
|
|
#include <stdbool.h>
|
2019-01-14 16:34:22 +00:00
|
|
|
#include <net/net.h>
|
2018-11-19 07:55:19 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <iphlpapi.h>
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
const char*
|
|
|
|
inet_ntop(int af, const void* src, char* dst, size_t size)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
int address_length;
|
|
|
|
DWORD string_length = size;
|
|
|
|
struct sockaddr_storage sa;
|
2020-04-07 18:38:56 +00:00
|
|
|
struct sockaddr_in* sin = (struct sockaddr_in*)&sa;
|
|
|
|
struct sockaddr_in6* sin6 = (struct sockaddr_in6*)&sa;
|
2018-11-19 07:55:19 +00:00
|
|
|
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
2020-04-07 18:38:56 +00:00
|
|
|
switch (af)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
case AF_INET:
|
2020-04-07 18:38:56 +00:00
|
|
|
address_length = sizeof(struct sockaddr_in);
|
2018-11-19 07:55:19 +00:00
|
|
|
sin->sin_family = af;
|
|
|
|
memcpy(&sin->sin_addr, src, sizeof(struct in_addr));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_INET6:
|
2020-04-07 18:38:56 +00:00
|
|
|
address_length = sizeof(struct sockaddr_in6);
|
2018-11-19 07:55:19 +00:00
|
|
|
sin6->sin6_family = af;
|
|
|
|
memcpy(&sin6->sin6_addr, src, sizeof(struct in6_addr));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (WSAAddressToString((LPSOCKADDR)&sa, address_length, NULL, dst, &string_length) == 0)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-07 18:38:56 +00:00
|
|
|
inet_pton(int af, const char* src, void* dst)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
int address_length;
|
|
|
|
struct sockaddr_storage sa;
|
2020-04-07 18:38:56 +00:00
|
|
|
struct sockaddr_in* sin = (struct sockaddr_in*)&sa;
|
|
|
|
struct sockaddr_in6* sin6 = (struct sockaddr_in6*)&sa;
|
2018-11-19 07:55:19 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
switch (af)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
case AF_INET:
|
|
|
|
address_length = sizeof(struct sockaddr_in);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_INET6:
|
|
|
|
address_length = sizeof(struct sockaddr_in6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (WSAStringToAddress((LPTSTR)src, af, NULL, (LPSOCKADDR)&sa, &address_length) == 0)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
switch (af)
|
2018-11-19 07:55:19 +00:00
|
|
|
{
|
|
|
|
case AF_INET:
|
|
|
|
memcpy(dst, &sin->sin_addr, sizeof(struct in_addr));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_INET6:
|
|
|
|
memcpy(dst, &sin6->sin6_addr, sizeof(struct in6_addr));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|