Commit f97d9649 authored by Deuce's avatar Deuce 👌🏾

Add inet_pton() for Win32.

Needed by MinGW32... we'll see if MSVC needs it as well soon.
parent 1cbe4b35
Pipeline #726 failed with stage
in 5 minutes and 41 seconds
......@@ -523,3 +523,39 @@ DLLEXPORT char* socket_strerror(int error_number, char* buf, size_t buflen)
return safe_strerror(error_number, buf, buflen);
#endif
}
#ifdef _WIN32
DLLEXPORT int inet_pton(int af, const char *src, void *dst)
{
struct addrinfo hints = {0};
struct addrinfo *res, *cur;
if (af != AF_INET && af != AF_INET6) {
// TODO: Should set socket_errno to EAFNOSUPPORT
return -1;
}
hints.ai_flags = AI_NUMERICHOST|AI_PASSIVE;
if(getaddrinfo(addr_str, NULL, &hints, &res))
return -1;
for(cur = res; cur; cur++) {
if(cur->ai_addr->sa_family == af)
break;
}
if(!cur) {
freeaddrinfo(res);
return 0;
}
switch(af) {
case AF_INET:
memcpy(dst, ((struct sockaddr_in *)(cur->sin_addr)), sizeof((struct sockaddr_in *)cur->sin_addr));
break;
case AF_INET6:
memcpy(dst, ((struct sockaddr_in6 *)(cur->sin6_addr)), sizeof((struct sockaddr_in6 *)cur->sin6_addr));
break;
}
freeaddrinfo(res);
return addr;
}
#endif
......@@ -241,6 +241,10 @@ DLLEXPORT void inet_setaddrport(union xp_sockaddr *addr, uint16_t port);
DLLEXPORT BOOL inet_addrmatch(union xp_sockaddr* addr1, union xp_sockaddr* addr2);
DLLEXPORT char* socket_strerror(int, char*, size_t);
#ifdef _WIN32
DLLEXPORT int inet_pton(int af, const char *src, void *dst);
#endif
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment