From e5e8af9c71ce47cd2342135ad941b144bfb864ec Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Wed, 25 Feb 2015 20:40:55 -0500 Subject: Restore synchronous name resolution (revert SVN rev52115). These gethostbyaddr() calls should be changed to getaddrinfo() but only in master. Change-Id: I7e2d31ceb0e072beb7f324336d7b145c3adbe3a0 Reviewed-on: https://code.wireshark.org/review/7402 Reviewed-by: Jeff Morriss --- epan/addr_resolv.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'epan/addr_resolv.c') diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 5795fb06c9..6776001e31 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -857,6 +857,7 @@ static hashipv4_t * host_lookup(const guint addr, gboolean *found) { hashipv4_t * volatile tp; + struct hostent *hostp; *found = TRUE; @@ -891,6 +892,25 @@ try_resolv: } #endif /* ASYNC_DNS */ + /* + * The Windows "gethostbyaddr()" insists on translating 0.0.0.0 to + * the name of the host on which it's running; to work around that + * botch, we don't try to translate an all-zero IP address to a host + * name. + */ + if (addr != 0) { + /* Use async DNS if possible, else fall back to timeouts, + * else call gethostbyaddr and hope for the best + */ + + hostp = gethostbyaddr((const char *)&addr, 4, AF_INET); + + if (hostp != NULL && hostp->h_name[0] != '\0') { + g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN); + return tp; + } + } + /* unknown host or DNS timeout */ } @@ -922,6 +942,7 @@ host_lookup6(const struct e_in6_addr *addr, gboolean *found) #ifdef HAVE_C_ARES async_dns_queue_msg_t *caqm; #endif /* HAVE_C_ARES */ + struct hostent *hostp; #endif /* INET6 */ *found = TRUE; @@ -971,6 +992,13 @@ try_resolv: } #endif /* HAVE_C_ARES */ + /* Quick hack to avoid DNS/YP timeout */ + hostp = gethostbyaddr((const char *)addr, sizeof(*addr), AF_INET6); + + if (hostp != NULL && hostp->h_name[0] != '\0') { + g_strlcpy(tp->name, hostp->h_name, MAXNAMELEN); + return tp; + } #endif /* INET6 */ } -- cgit v1.2.3