Skip to content

Commit

Permalink
Handle IPv4/v6 addresses returend from getaddrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
K-os committed Aug 24, 2015
1 parent a91524f commit 2b52599
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,36 @@ enet_address_set_host (ENetAddress * address, const char * name)
memset (& hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC;

if (getaddrinfo (name, NULL, NULL, & resultList) != 0)
if (getaddrinfo (name, NULL, & hints, & resultList) != 0)
return -1;

for (result = resultList; result != NULL; result = result -> ai_next)
{
//todo: split 4 with ::ffff: and v6
if (/*result -> ai_family == AF_INET && */ result -> ai_addr != NULL && result -> ai_addrlen >= sizeof (struct sockaddr_in))
if (result -> ai_addr != NULL && result -> ai_addrlen >= sizeof (struct sockaddr_in))
{
struct sockaddr_in6 * sin = (struct sockaddr_in6 *) result -> ai_addr;
if (result -> ai_family == AF_INET)
{
struct sockaddr_in * sin = (struct sockaddr_in *) result -> ai_addr;

address -> host = sin -> sin6_addr;
((uint32_t *) & address -> host.s6_addr)[0] = 0;
((uint32_t *) & address -> host.s6_addr)[1] = 0;
((uint32_t *) & address -> host.s6_addr)[2] = htonl(0xffff);
((uint32_t *) & address -> host.s6_addr)[3] = sin->sin_addr.s_addr;

freeaddrinfo (resultList);
freeaddrinfo (resultList);

return 0;
return 0;
}
else if(result -> ai_family == AF_INET6)
{
struct sockaddr_in6 * sin = (struct sockaddr_in6 *) result -> ai_addr;

address -> host = sin -> sin6_addr;

freeaddrinfo (resultList);

return 0;
}
}
}

Expand Down

0 comments on commit 2b52599

Please sign in to comment.