Rework the IPV6 verison of BX_ip_to_host() so that it works on BSD (used

by $iptoname() scripting function).


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@182 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2012-05-14 13:56:52 +00:00
parent f035eceb72
commit 26a62fe7fa

View File

@@ -696,18 +696,20 @@ extern char *BX_host_to_ip (const char *host)
extern char *BX_ip_to_host (const char *ip)
{
static char host[128];
struct sockaddr_foobar sf;
struct addrinfo hints = { 0 };
struct addrinfo *res;
if (inet_pton(AF_INET6, ip, &sf.sf_addr6))
sf.sf_family = AF_INET6;
else
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(ip, NULL, &hints, &res) == 0)
{
inet_pton(AF_INET, ip, &sf.sf_addr);
sf.sf_family = AF_INET;
if (!res || getnameinfo(res->ai_addr, res->ai_addrlen, host, 128, NULL, 0, 0))
strlcpy(host, ip, sizeof host);
freeaddrinfo(res);
}
if (getnameinfo((struct sockaddr*)&sf, sizeof(struct sockaddr_foobar), host, 128, NULL, 0, 0))
strncpy(host, ip, 128);
else
strlcpy(host, ip, sizeof host);
return host;
}