mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 17:42:49 +02:00
OK, looks like I was doing stupid things with IPv6 hostname lookups :) Back
when I originally wrote that code, there wasn't any man pages for them and I couldn't really find any good docs either, so I just copy&pasted some code from somewhere and it seemed to work. Anyway, it was doing reverse name lookup for uninitialized host name which really wasn't a good idea :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2358 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
f2a4a97668
commit
13eb6379e7
1 changed files with 15 additions and 23 deletions
|
|
@ -378,9 +378,8 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
union sockaddr_union *so;
|
union sockaddr_union *so;
|
||||||
struct addrinfo hints, *ai, *origai;
|
struct addrinfo hints, *ai, *ailist;
|
||||||
char hbuf[NI_MAXHOST];
|
int ret, count;
|
||||||
int host_error, count;
|
|
||||||
#else
|
#else
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -395,19 +394,14 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
/* save error to host_error for later use */
|
/* save error to host_error for later use */
|
||||||
host_error = getaddrinfo(addr, NULL, &hints, &ai);
|
ret = getaddrinfo(addr, NULL, &hints, &ailist);
|
||||||
if (host_error != 0)
|
if (ret != 0)
|
||||||
return host_error;
|
return ret;
|
||||||
|
|
||||||
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf,
|
count = 0;
|
||||||
sizeof(hbuf), NULL, 0, NI_NUMERICHOST))
|
for (ai = ailist; ai != NULL && count < 2; ai = ai->ai_next) {
|
||||||
return 1;
|
|
||||||
|
|
||||||
origai = ai; count = 0;
|
|
||||||
while (ai != NULL && count < 2) {
|
|
||||||
so = (union sockaddr_union *) ai->ai_addr;
|
so = (union sockaddr_union *) ai->ai_addr;
|
||||||
|
|
||||||
if (so != NULL) {
|
|
||||||
if (ai->ai_family == AF_INET6 && ip6->family == 0) {
|
if (ai->ai_family == AF_INET6 && ip6->family == 0) {
|
||||||
sin_get_ip(so, ip6);
|
sin_get_ip(so, ip6);
|
||||||
count++;
|
count++;
|
||||||
|
|
@ -416,9 +410,7 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ai = ai->ai_next;
|
freeaddrinfo(ailist);
|
||||||
}
|
|
||||||
freeaddrinfo(origai);
|
|
||||||
#else
|
#else
|
||||||
hp = gethostbyname(addr);
|
hp = gethostbyname(addr);
|
||||||
if (hp == NULL) return h_errno;
|
if (hp == NULL) return h_errno;
|
||||||
|
|
@ -427,7 +419,7 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
|
||||||
memcpy(&ip4->ip, hp->h_addr, 4);
|
memcpy(&ip4->ip, hp->h_addr, 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return count > 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get name for host, *name should be g_free()'d unless it's NULL.
|
/* Get name for host, *name should be g_free()'d unless it's NULL.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue