Commit 8b4f368d authored by Deon George's avatar Deon George

Merge branch 'upstream' - deuces inet_pton() work for minw32

parents c8e0ad84 afeb58c2
......@@ -523,3 +523,39 @@ DLLEXPORT char* socket_strerror(int error_number, char* buf, size_t buflen)
return safe_strerror(error_number, buf, buflen);
#endif
}
#if defined(_WIN32) && !defined(_MSC_VER)
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(src, 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 1;
}
#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);
#if defined(_WIN32) && !defined(_MSC_VER)
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