summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-01-29 22:16:40 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-01-29 22:16:40 +0000
commit13eb6379e791574a0d729a63c064218656f96150 (patch)
treed9d0e3210012898b66d36b38b5bb2198b92118a3 /src
parentf2a4a9766869fbaae52c1da7d7721ebe93588f6a (diff)
downloadirssi-13eb6379e791574a0d729a63c064218656f96150.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/core/network.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/core/network.c b/src/core/network.c
index 8792b9e8..2ce7910d 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -378,9 +378,8 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
{
#ifdef HAVE_IPV6
union sockaddr_union *so;
- struct addrinfo hints, *ai, *origai;
- char hbuf[NI_MAXHOST];
- int host_error, count;
+ struct addrinfo hints, *ai, *ailist;
+ int ret, count;
#else
struct hostent *hp;
#endif
@@ -395,30 +394,23 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
hints.ai_socktype = SOCK_STREAM;
/* save error to host_error for later use */
- host_error = getaddrinfo(addr, NULL, &hints, &ai);
- if (host_error != 0)
- return host_error;
+ ret = getaddrinfo(addr, NULL, &hints, &ailist);
+ if (ret != 0)
+ return ret;
- if (getnameinfo(ai->ai_addr, ai->ai_addrlen, hbuf,
- sizeof(hbuf), NULL, 0, NI_NUMERICHOST))
- return 1;
-
- origai = ai; count = 0;
- while (ai != NULL && count < 2) {
+ count = 0;
+ for (ai = ailist; ai != NULL && count < 2; ai = ai->ai_next) {
so = (union sockaddr_union *) ai->ai_addr;
- if (so != NULL) {
- if (ai->ai_family == AF_INET6 && ip6->family == 0) {
- sin_get_ip(so, ip6);
- count++;
- } else if (ai->ai_family == AF_INET && ip4->family == 0) {
- sin_get_ip(so, ip4);
- count++;
- }
+ if (ai->ai_family == AF_INET6 && ip6->family == 0) {
+ sin_get_ip(so, ip6);
+ count++;
+ } else if (ai->ai_family == AF_INET && ip4->family == 0) {
+ sin_get_ip(so, ip4);
+ count++;
}
- ai = ai->ai_next;
}
- freeaddrinfo(origai);
+ freeaddrinfo(ailist);
#else
hp = gethostbyname(addr);
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);
#endif
- return 0;
+ return count > 0 ? 0 : 1;
}
/* Get name for host, *name should be g_free()'d unless it's NULL.