Remove gethostbyaddr and gethostbyaddr2.

They've been deprecated for a very long time. Replace them with
getaddrinfo. Note that we might not want to do synchronous name
resolution at all.

Add HAVE_GETADDRINFO to the KfW win-mac.h collision list.

Change-Id: If59ce8a038776eadd6cd1794ed0e2dad8bf8a22c
Reviewed-on: https://code.wireshark.org/review/6958
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Gerald Combs 2015-02-04 12:18:37 -08:00 committed by Anders Broman
parent d6ebb82ed2
commit 881ff5df92
10 changed files with 75 additions and 44 deletions

View File

@ -76,7 +76,7 @@ cmake_pop_check_state()
# and there's not actually a function named floorl()
#
check_symbol_exists("floorl" "math.h" HAVE_FLOORL)
check_function_exists("gethostbyname2" HAVE_GETHOSTBYNAME2)
check_function_exists("getaddrinfo" HAVE_GETADDRINFO)
check_function_exists("getopt_long" HAVE_GETOPT_LONG)
if(HAVE_GETOPT_LONG)
if(HAVE_GETOPT_H)

View File

@ -268,25 +268,27 @@ yes
])
#
# AC_WIRESHARK_GETHOSTBY_LIB_CHECK
# AC_WIRESHARK_GETADDRINFO_LIB_CHECK
#
# Checks whether we need "-lnsl" to get "gethostby*()", which we use
# in "resolv.c".
# Checks whether we need "-lnsl" to get "getaddrinfo()", which we use
# in "addr_resolv.c".
#
# Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
# GNU Autoconf 2.13; the comment came from there.
# Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
#
AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
AC_DEFUN([AC_WIRESHARK_GETADDRINFO_LIB_CHECK],
[
# Comments below apply to gethostbyname(), from which this was
# migrated:
# msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
# to get the SysV transport functions.
# chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
# needs -lnsl.
# The nsl library prevents programs from opening the X display
# on Irix 5.2, according to dickey@clark.net.
AC_CHECK_FUNC(gethostbyname, ,
AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
AC_CHECK_FUNC(getaddrinfo, ,
AC_CHECK_LIB(nsl, getaddrinfo, NSL_LIBS="-lnsl"))
AC_SUBST(NSL_LIBS)
])
@ -294,7 +296,7 @@ AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
# AC_WIRESHARK_SOCKET_LIB_CHECK
#
# Checks whether we need "-lsocket" to get "socket()", which is used
# by libpcap on some platforms - and, in effect, "gethostby*()" on
# by libpcap on some platforms - and, in effect, "getaddrinfo()" on
# most if not all platforms (so that it can use NIS or DNS or...
# to look up host names).
#

View File

@ -261,6 +261,7 @@ read_keytab_file_from_preferences(void)
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#ifdef _WIN32
/* prevent redefinition warnings in kfw-2.5\inc\win_mac.h */
#undef HAVE_GETADDRINFO
#undef HAVE_STDARG_H
#undef HAVE_STDLIB_H
#undef HAVE_STRING_H

View File

@ -60,7 +60,7 @@ int dissect_krb5_cname(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *
int dissect_krb5_realm(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
guint32 kerberos_output_keytype(void);
guint get_krb_pdu_len(packet_info *, tvbuff_t *tvb, int offset);
guint get_krb_pdu_len(packet_info *, tvbuff_t *tvb, int offset, void *data _U_);
gint kerberos_rm_to_reclen(guint krb_rm);

View File

@ -71,8 +71,8 @@
/* Define if you have the 'floorl' function. */
#cmakedefine HAVE_FLOORL 1
/* Define to 1 if you have the `gethostbyname2' function. */
#cmakedefine HAVE_GETHOSTBYNAME2 1
/* Define to 1 if you have the `getaddrinfo' function. */
#cmakedefine HAVE_GETADDRINFO 1
/* Define to 1 if you have the getopt_long function. */
#cmakedefine HAVE_GETOPT_LONG 1

View File

@ -89,8 +89,8 @@
/* Define if you have the floorl function. */
#define HAVE_FLOORL 1
/* Define if you have the gethostbyname2 function. */
/* #undef HAVE_GETHOSTBYNAME2 */
/* Define if you have the getaddrinfo function. */
#define HAVE_GETADDRINFO 1
/* Define if you have the getprotobynumber function. */
/* #undef HAVE_GETPROTOBYNUMBER */

View File

@ -2128,9 +2128,9 @@ AC_SUBST(randpkt_man)
AC_SUBST(wiresharkfilter_man)
dnl Checks for "gethostbyname()" - and "-lnsl", if we need it to get
dnl "gethostbyname()".
AC_WIRESHARK_GETHOSTBY_LIB_CHECK
dnl Checks for "getaddrinfo()" - and "-lnsl", if we need it to get
dnl "getaddrinfo()".
AC_WIRESHARK_GETADDRINFO_LIB_CHECK
dnl Checks for "connect()", used as a proxy for "socket()" - and
dnl "-lsocket", if we need it to get "connect()".

View File

@ -3185,7 +3185,7 @@ get_host_ipaddr(const char *host, guint32 *addrp)
fd_set rfds, wfds;
async_hostent_t ahe;
#else /* HAVE_C_ARES */
struct hostent *hp;
struct addrinfo hint, *result = NULL;
#endif /* HAVE_C_ARES */
/*
@ -3234,16 +3234,23 @@ get_host_ipaddr(const char *host, guint32 *addrp)
}
return FALSE;
#else /* ! HAVE_C_ARES */
hp = gethostbyname(host);
if (hp == NULL) {
/* No. */
return FALSE;
/* Apparently, some versions of gethostbyaddr can
* return IPv6 addresses. */
} else if (hp->h_length <= (int) sizeof (struct in_addr)) {
memcpy(&ipaddr, hp->h_addr, hp->h_length);
} else {
return FALSE;
/*
* This can be slow, particularly for capture files with lots of
* addresses. Should we just return FALSE instead?
*/
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_INET;
if (getaddrinfo(host, NULL, &hint, &result) == 0) {
/* Probably more checks than necessary */
if (result != NULL) {
gboolean ret_val = FALSE;
if (result->ai_family == AF_INET && result->ai_addrlen == 4) {
memcpy(&ipaddr, result->ai_addr->sa_data, result->ai_addrlen);
ret_val = TRUE;
}
freeaddrinfo(result);
return ret_val;
}
}
#endif /* HAVE_C_ARES */
} else {
@ -3274,8 +3281,8 @@ get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
int nfds;
fd_set rfds, wfds;
async_hostent_t ahe;
#elif defined(HAVE_GETHOSTBYNAME2)
struct hostent *hp;
#elif defined(HAVE_GETADDRINFO)
struct addrinfo hint, *result = NULL;
#endif /* HAVE_C_ARES */
if (str_to_ip6(host, addrp))
@ -3319,11 +3326,24 @@ get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
if (ahe.addr_size == ahe.copied) {
return TRUE;
}
#elif defined(HAVE_GETHOSTBYNAME2)
hp = gethostbyname2(host, AF_INET6);
if (hp != NULL && hp->h_length == sizeof(struct e_in6_addr)) {
memcpy(addrp, hp->h_addr, hp->h_length);
return TRUE;
#elif defined(HAVE_GETADDRINFO)
/*
* This can be slow, particularly for capture files with lots of
* addresses. Should we just return FALSE instead?
*/
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_INET6;
if (getaddrinfo(host, NULL, &hint, &result) == 0) {
/* Probably more checks than necessary */
if (result != NULL) {
gboolean ret_val = FALSE;
if (result->ai_family == AF_INET6 && result->ai_addrlen == sizeof(struct e_in6_addr)) {
memcpy(addrp, result->ai_addr->sa_data, result->ai_addrlen);
ret_val = TRUE;
}
freeaddrinfo(result);
return ret_val;
}
}
#endif
@ -3336,17 +3356,24 @@ get_host_ipaddr6(const char *host, struct e_in6_addr *addrp)
* that we don't know)
*/
const char* host_ip_af(const char *host
#ifndef HAVE_GETHOSTBYNAME2
#ifndef HAVE_GETADDRINFO
_U_
#endif
)
{
#ifdef HAVE_GETHOSTBYNAME2
struct hostent *h;
return (h = gethostbyname2(host, AF_INET6)) && h->h_addrtype == AF_INET6 ? "ip6" : "ip";
#else
return "ip";
const char *af = "ip";
#ifdef HAVE_GETADDRINFO
struct addrinfo hint, *result = NULL;
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
if (getaddrinfo(host, NULL, &hint, &result) == 0) {
if (result->ai_family == AF_INET6) {
af = "ip6";
}
freeaddrinfo(result);
}
#endif
return af;
}
GHashTable *

View File

@ -512,6 +512,7 @@ read_keytab_file_from_preferences(void)
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
#ifdef _WIN32
/* prevent redefinition warnings in kfw-2.5\inc\win_mac.h */
#undef HAVE_GETADDRINFO
#undef HAVE_STDARG_H
#undef HAVE_STDLIB_H
#undef HAVE_STRING_H
@ -4244,7 +4245,7 @@ dissect_kerberos_ChangePasswdData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
/*--- End of included file: packet-kerberos-fn.c ---*/
#line 1984 "../../asn1/kerberos/packet-kerberos-template.c"
#line 1985 "../../asn1/kerberos/packet-kerberos-template.c"
/* Make wrappers around exported functions for now */
int
@ -5282,7 +5283,7 @@ void proto_register_kerberos(void) {
NULL, HFILL }},
/*--- End of included file: packet-kerberos-hfarr.c ---*/
#line 2365 "../../asn1/kerberos/packet-kerberos-template.c"
#line 2366 "../../asn1/kerberos/packet-kerberos-template.c"
};
/* List of subtrees */
@ -5356,7 +5357,7 @@ void proto_register_kerberos(void) {
&ett_kerberos_ChangePasswdData,
/*--- End of included file: packet-kerberos-ettarr.c ---*/
#line 2381 "../../asn1/kerberos/packet-kerberos-template.c"
#line 2382 "../../asn1/kerberos/packet-kerberos-template.c"
};
static ei_register_info ei[] = {

View File

@ -68,7 +68,7 @@ int dissect_krb5_cname(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *
int dissect_krb5_realm(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
guint32 kerberos_output_keytype(void);
guint get_krb_pdu_len(packet_info *, tvbuff_t *tvb, int offset, void *data);
guint get_krb_pdu_len(packet_info *, tvbuff_t *tvb, int offset, void *data _U_);
gint kerberos_rm_to_reclen(guint krb_rm);