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:
@@ -696,18 +696,20 @@ extern char *BX_host_to_ip (const char *host)
|
|||||||
extern char *BX_ip_to_host (const char *ip)
|
extern char *BX_ip_to_host (const char *ip)
|
||||||
{
|
{
|
||||||
static char host[128];
|
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;
|
hints.ai_family = AF_UNSPEC;
|
||||||
else
|
hints.ai_flags = AI_NUMERICHOST;
|
||||||
|
|
||||||
|
if (getaddrinfo(ip, NULL, &hints, &res) == 0)
|
||||||
{
|
{
|
||||||
inet_pton(AF_INET, ip, &sf.sf_addr);
|
if (!res || getnameinfo(res->ai_addr, res->ai_addrlen, host, 128, NULL, 0, 0))
|
||||||
sf.sf_family = AF_INET;
|
strlcpy(host, ip, sizeof host);
|
||||||
|
freeaddrinfo(res);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (getnameinfo((struct sockaddr*)&sf, sizeof(struct sockaddr_foobar), host, 128, NULL, 0, 0))
|
strlcpy(host, ip, sizeof host);
|
||||||
strncpy(host, ip, 128);
|
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user