Commit d9a559b7 authored by Youness Alaoui's avatar Youness Alaoui

Fix inet_ntop_win32 to correctly fill in the in_addr and to return the correct...

Fix inet_ntop_win32 to correctly fill in the in_addr and to return the correct value upon success/failure
parent 5170c6d7
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
static const char * static const char *
inet_ntop_win32(int af, const void *src, char *dst, socklen_t cnt) inet_ntop_win32 (int af, const void *src, char *dst, socklen_t cnt)
{ {
if (af == AF_INET) { if (af == AF_INET) {
struct sockaddr_in in; struct sockaddr_in in;
...@@ -82,18 +82,25 @@ inet_pton_win32(int af, const char *src, void *dst) ...@@ -82,18 +82,25 @@ inet_pton_win32(int af, const char *src, void *dst)
hints.ai_family = af; hints.ai_family = af;
if (getaddrinfo(src, NULL, &hints, &res) != 0) { if (getaddrinfo(src, NULL, &hints, &res) != 0) {
return -1; return 0;
} }
ressave = res; ressave = res;
while (res) { while (res) {
memcpy(dst, res->ai_addr, res->ai_addrlen); if( res->ai_addr->sa_family == AF_INET) {
memcpy(dst, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
res->ai_addrlen);
res = res->ai_next;
} else if(res->ai_addr->sa_family == AF_INET6) {
memcpy(dst, &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr,
res->ai_addrlen);
res = res->ai_next; res = res->ai_next;
} }
}
freeaddrinfo(ressave); freeaddrinfo(ressave);
return 0; return 1;
} }
#endif #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