Skip to content

Commit 512a43b

Browse files
committed
Copypaste resolving functions from unix.c to win32.c
1 parent dce98b9 commit 512a43b

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

win32.c

+45-13
Original file line numberDiff line numberDiff line change
@@ -61,49 +61,81 @@ enet_time_set (enet_uint32 newTimeBase)
6161
int
6262
enet_address_set_host (ENetAddress * address, const char * name)
6363
{
64-
struct hostent * hostEntry;
65-
64+
struct hostent * hostEntry = NULL;
65+
#ifdef HAS_GETHOSTBYNAME_R
66+
struct hostent hostData;
67+
char buffer [2048];
68+
int errnum;
69+
70+
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
71+
gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
72+
#else
73+
hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
74+
#endif
75+
#else
6676
hostEntry = gethostbyname (name);
77+
#endif
78+
6779
if (hostEntry == NULL ||
6880
hostEntry -> h_addrtype != AF_INET)
6981
{
70-
unsigned long host = inet_addr (name);
71-
if (host == INADDR_NONE)
82+
#ifdef HAS_INET_PTON
83+
if (! inet_pton (AF_INET6, name, & address -> host))
84+
#else
85+
if (! inet_aton (name, (struct in6_addr *) & address -> host))
86+
#endif
7287
return -1;
73-
address -> host = host;
7488
return 0;
7589
}
7690

77-
address -> host = * hostEntry -> h_addr_list [0];
91+
// address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
7892

7993
return 0;
8094
}
8195

8296
int
8397
enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
8498
{
99+
#ifdef HAS_INET_NTOP
100+
if (inet_ntop (AF_INET6, & address -> host, name, nameLength) == NULL)
101+
#else
85102
char * addr = inet_ntoa (* (struct in6_addr *) & address -> host);
86-
if (addr == NULL)
87-
return -1;
88-
else
103+
if (addr != NULL)
89104
{
90105
size_t addrLen = strlen(addr);
91106
if (addrLen >= nameLength)
92107
return -1;
93108
memcpy (name, addr, addrLen + 1);
94-
}
109+
}
110+
else
111+
#endif
112+
return -1;
95113
return 0;
96114
}
97115

98116
int
99117
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
100118
{
101119
struct in6_addr in;
102-
struct hostent * hostEntry;
103-
120+
struct hostent * hostEntry = NULL;
121+
#ifdef HAS_GETHOSTBYADDR_R
122+
struct hostent hostData;
123+
char buffer [2048];
124+
int errnum;
125+
126+
in = address -> host;
127+
128+
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
129+
gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
130+
#else
131+
hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in6_addr), AF_INET6, & hostData, buffer, sizeof (buffer), & errnum);
132+
#endif
133+
#else
104134
in.s_addr = address -> host;
105-
135+
106136
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in6_addr), AF_INET6);
137+
#endif
138+
107139
if (hostEntry == NULL)
108140
return enet_address_get_host_ip (address, name, nameLength);
109141
else

0 commit comments

Comments
 (0)