From: Danilo Almeida Date: Sat, 21 Aug 1999 15:12:50 +0000 (+0000) Subject: Use multiple addresses, if present, on Mac and Windows X-Git-Tag: krb5-1.2-beta1~275 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4cc72a8d5dd822692829bfe8c1a06145d9b9a7da;p=krb5.git Use multiple addresses, if present, on Mac and Windows git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11701 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 16363aed3..fdb179830 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,8 @@ +1999-08-21 Danilo Almeida + + * localaddr.c (krb5_os_localaddr): Use multiple addresses, if + present, on Mac and Windows. + 1999-08-10 Alexandra Ellwood * changepw.c (krb5_change_password): diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index f55c35c78..9b64ad19b 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -294,12 +294,11 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_os_localaddr (krb5_context context, krb5_address ***addr) { char host[64]; /* Name of local machine */ struct hostent *hostrec; - int err; - - *addr = calloc (2, sizeof (krb5_address *)); - if (*addr == NULL) - return ENOMEM; + int err, count, i; + krb5_address ** paddr; + *addr = 0; + paddr = 0; err = 0; if (gethostname (host, sizeof(host))) { @@ -319,27 +318,55 @@ krb5_os_localaddr (krb5_context context, krb5_address ***addr) { return err; } - (*addr)[0] = calloc (1, sizeof(krb5_address)); - if ((*addr)[0] == NULL) { - free (*addr); - return ENOMEM; + for (count = 0; hostrec->h_addr_list[count]; count++); + + + paddr = (krb5_address **)malloc(sizeof(krb5_address *) * (count+1)); + if (!paddr) { + err = ENOMEM; + goto cleanup; + } + + memset(addr, 0, sizeof(krb5_address *) * (count+1)); + + for (i = 0; i < count; i++) + { + paddr[i] = (krb5_address *)malloc(sizeof(krb5_address)); + if (paddr[i] == NULL) { + err = ENOMEM; + goto cleanup; + } + + paddr[i]->magic = KV5M_ADDRESS; + paddr[i]->addrtype = hostrec->h_addrtype; + paddr[i]->length = hostrec->h_length; + paddr[i]->contents = (unsigned char *)malloc(paddr[i]->length); + if (!paddr[i]->contents) { + err = ENOMEM; + goto cleanup; + } + memcpy(paddr[i]->contents, + hostrec->h_addr_list[i], + paddr[i]->length); } - (*addr)[0]->magic = KV5M_ADDRESS; - (*addr)[0]->addrtype = hostrec->h_addrtype; - (*addr)[0]->length = hostrec->h_length; - (*addr)[0]->contents = (unsigned char *)malloc((*addr)[0]->length); - if (!(*addr)[0]->contents) { - free((*addr)[0]); - free(*addr); - return ENOMEM; - } else { - memcpy ((*addr)[0]->contents, - hostrec->h_addr, - (*addr)[0]->length); + + cleanup: + if (err) { + if (paddr) { + for (i = 0; i < count; i++) + { + if (paddr[i]) { + if (paddr[i]->contents) + free(paddr[i]->contents); + free(paddr[i]); + } + } + free(paddr); + } } - /* FIXME, deal with the case where gethostent returns multiple addrs */ + else + *addr = paddr; - return(0); + return(err); } #endif -