From: Ken Raeburn Date: Tue, 8 May 2001 03:50:53 +0000 (+0000) Subject: * locate_kdc.c (add_sockaddr_to_list) [TEST]: If getnameinfo is available, use X-Git-Tag: krb5-1.3-alpha1~1519 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f31e7aec76cd20d55f39ec44551ad6f8c4199e25;p=krb5.git * locate_kdc.c (add_sockaddr_to_list) [TEST]: If getnameinfo is available, use it instead of inet_ntoa to get the printable address. (add_host_to_list): Share declaration sections as much as possible. Propagate errors back correctly from gethostbyname path. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13232 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 8b1627ce8..244267ba3 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,12 @@ +2001-05-07 Ken Raeburn + + * locate_kdc.c (add_sockaddr_to_list) [TEST]: If getnameinfo is + available, use it instead of inet_ntoa to get the printable + address. + (add_host_to_list): Share declaration sections as much as + possible. Propagate errors back correctly from gethostbyname + path. + 2001-04-26 Ken Raeburn * hst_realm.c (T_TXT): Define if not defined by header files. diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c index 96a914bac..7b6ec221b 100644 --- a/src/lib/krb5/os/locate_kdc.c +++ b/src/lib/krb5/os/locate_kdc.c @@ -184,9 +184,21 @@ add_sockaddr_to_list (struct addrlist *lp, const struct sockaddr *addr, #ifdef TEST fprintf (stderr, "\tadding sockaddr family %2d, len %d", addr->sa_family, len); +#ifdef HAVE_GETNAMEINFO + { + char name[NI_MAXHOST]; + int err; + + err = getnameinfo (addr, len, name, sizeof (name), NULL, 0, + NI_NUMERICHOST | NI_NUMERICSERV); + if (err == 0) + fprintf (stderr, "\t%s", name); + } +#else if (addr->sa_family == AF_INET) fprintf (stderr, "\t%s", inet_ntoa (((const struct sockaddr_in *)addr)->sin_addr)); +#endif fprintf (stderr, "\n"); #endif @@ -270,14 +282,18 @@ add_host_to_list (struct addrlist *lp, const char *hostname, int port, int secport) { #ifdef HAVE_GETADDRINFO - int err; struct addrinfo *addrs, *a; +#else + struct hostent *hp; +#endif + int err; #ifdef TEST fprintf (stderr, "adding hostname %s, ports %d,%d\n", hostname, ntohs (port), ntohs (secport)); #endif +#ifdef HAVE_GETADDRINFO err = getaddrinfo (hostname, NULL, NULL, &addrs); if (err) return translate_ai_error (err); @@ -296,20 +312,10 @@ add_host_to_list (struct addrlist *lp, const char *hostname, break; } freeaddrinfo (addrs); - return err; #else - /* If we don't have getaddrinfo, we're not bothering with IPv6 - support. */ - int err; - struct hostent *hp; - int i; - -#ifdef TEST - fprintf (stderr, "adding hostname %s, ports %d,%d\n", hostname, port, secport); -#endif - hp = gethostbyname (hostname); if (hp != NULL) { + int i; for (i = 0; hp->h_addr_list[i] != 0; i++) { struct sockaddr_in sin4; @@ -332,8 +338,8 @@ add_host_to_list (struct addrlist *lp, const char *hostname, break; } } - return 0; #endif + return err; } /*