(add_hostent): if there's no fqdn in `he' try reverse resolving to see
if there's a fuller name there git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8791 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * Copyright (c) 1999 Kungliga Tekniska H<>gskolan |  * Copyright (c) 1999 - 2000 Kungliga Tekniska H<>gskolan | ||||||
|  * (Royal Institute of Technology, Stockholm, Sweden). |  * (Royal Institute of Technology, Stockholm, Sweden). | ||||||
|  * All rights reserved. |  * All rights reserved. | ||||||
|  *  |  *  | ||||||
| @@ -215,26 +215,53 @@ get_null (const struct addrinfo *hints, | |||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Try to find a fqdn (with `.') in he if possible, else return h_name | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | static char * | ||||||
|  | find_fqdn (const struct hostent *he) | ||||||
|  | { | ||||||
|  |     char *ret = he->h_name; | ||||||
|  |     char **h; | ||||||
|  |  | ||||||
|  |     if (strchr (ret, '.') == NULL) | ||||||
|  | 	for (h = he->h_aliases; *h; ++h) { | ||||||
|  | 	    if (strchr (*h, '.') != NULL) { | ||||||
|  | 		ret = *h; | ||||||
|  | 		break; | ||||||
|  | 	    } | ||||||
|  | 	} | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
| static int | static int | ||||||
| add_hostent (int port, int protocol, int socktype, | add_hostent (int port, int protocol, int socktype, | ||||||
| 	     struct addrinfo ***current, | 	     struct addrinfo ***current, | ||||||
| 	     int (*func)(struct addrinfo *, void *data, int port), | 	     int (*func)(struct addrinfo *, void *data, int port), | ||||||
| 	     struct hostent *he, int *flags) | 	     struct hostent *he, int *flags) | ||||||
| { | { | ||||||
|     char **h; |  | ||||||
|     int ret; |     int ret; | ||||||
|     char *canonname = NULL; |     char *canonname = NULL; | ||||||
|  |  | ||||||
|     if (*flags & AI_CANONNAME) { |     if (*flags & AI_CANONNAME) { | ||||||
| 	canonname = he->h_name; | 	canonname = find_fqdn (he); | ||||||
|  |  | ||||||
| 	if (strchr (he->h_name, '.') == NULL) | 	if (strchr (canonname, '.') == NULL) { | ||||||
| 	    for (h = he->h_aliases; *h; ++h) { | 	    struct hostent *he2; | ||||||
| 		if (strchr (*h, '.') != NULL) { | 	    int error; | ||||||
| 		    canonname = *h; |  | ||||||
| 		    break; | 	    he2 = getipnodebyaddr (he->h_addr_list[0], he->h_length, | ||||||
| 		} | 				   he->h_addrtype, &error); | ||||||
|  | 	    if (he2 != NULL) { | ||||||
|  | 		char *tmp = find_fqdn (he2); | ||||||
|  |  | ||||||
|  | 		if (strchr (tmp, '.') != NULL) | ||||||
|  | 		    canonname = tmp; | ||||||
|  | 		freehostent (he2); | ||||||
| 	    } | 	    } | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	canonname = strdup (canonname); | 	canonname = strdup (canonname); | ||||||
| 	if (canonname == NULL) | 	if (canonname == NULL) | ||||||
| 	    return EAI_MEMORY; | 	    return EAI_MEMORY; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Assar Westerlund
					Assar Westerlund