Andrew Bartlet pointed out that the patch was incomplete, update and write doxygen.

This commit is contained in:
Love Hornquist Astrand
2010-09-30 00:44:35 -07:00
parent 6699b5e59a
commit 1072afd6bf

View File

@@ -370,35 +370,52 @@ KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host, krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host,
struct addrinfo **ai) struct addrinfo **ai)
{ {
struct addrinfo hints; int ret = 0;
char portstr[NI_MAXSERV];
int ret;
if (host->ai == NULL) { if (host->ai == NULL) {
struct addrinfo hints;
char portstr[NI_MAXSERV];
char *hostname = host->hostname; char *hostname = host->hostname;
snprintf (portstr, sizeof(portstr), "%d", host->port);
make_hints(&hints, host->proto);
/** /**
* If the hostname contains a dot, assumes it's a FQAN and * First try this as an IP address, this allows us to add a
* dot at the end to stop using the search domains.
*/
hints.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;
ret = getaddrinfo(host->hostname, portstr, &hints, &host->ai);
if (ret == 0)
goto out;
/**
* If the hostname contains a dot, assumes it's a FQDN and
* don't use search domains since that might be painfully slow * don't use search domains since that might be painfully slow
* when machine is disconnected from that network. * when machine is disconnected from that network.
*/ */
if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] == '.') { hints.ai_flags &= ~(AI_NUMERICHOST);
if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] != '.') {
ret = asprintf(&hostname, "%s.", host->hostname); ret = asprintf(&hostname, "%s.", host->hostname);
if (ret < 0 || hostname == NULL) if (ret < 0 || hostname == NULL)
return ENOMEM; return ENOMEM;
} }
make_hints(&hints, host->proto);
snprintf (portstr, sizeof(portstr), "%d", host->port);
ret = getaddrinfo(hostname, portstr, &hints, &host->ai); ret = getaddrinfo(hostname, portstr, &hints, &host->ai);
if (hostname != host->hostname) if (hostname != host->hostname)
free(hostname); free(hostname);
if (ret) if (ret) {
return krb5_eai_to_heim_errno(ret, errno); ret = krb5_eai_to_heim_errno(ret, errno);
goto out;
} }
}
out:
*ai = host->ai; *ai = host->ai;
return 0; return ret;
} }
static krb5_boolean static krb5_boolean