diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2001-06-26 14:23:04 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2001-06-26 14:23:04 +0000 |
commit | e3623759aaa258965c3509f72db99780bae92241 (patch) | |
tree | 48b7fa0974db652954e04383ca51a63232c7e77c | |
parent | 7d5283c300c340ef878912edba68be2e334dfeab (diff) | |
download | krb5-e3623759aaa258965c3509f72db99780bae92241.zip krb5-e3623759aaa258965c3509f72db99780bae92241.tar.gz krb5-e3623759aaa258965c3509f72db99780bae92241.tar.bz2 |
localaddr.c: Added a special krb5_os_localaddr for Mac OS 9 which looks up the addresses without querying DNS synchronously
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-2@13504 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r-- | src/lib/krb5/os/ChangeLog | 5 | ||||
-rw-r--r-- | src/lib/krb5/os/localaddr.c | 79 |
2 files changed, 81 insertions, 3 deletions
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 555ae93..20e5ce4 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,8 @@ +2001-06-26 Alexandra Ellwood <lxs@mit.edu> + + * localaddr.c: Added a special krb5_os_localaddr for Mac OS 9 + which looks up the addresses without querying DNS synchronously + 2001-02-27 Alexandra Ellwood <lxs@mit.edu> * prompter.c, promptusr.c, read_pwd.c: We now export diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c index d275590..5852de5 100644 --- a/src/lib/krb5/os/localaddr.c +++ b/src/lib/krb5/os/localaddr.c @@ -504,14 +504,13 @@ krb5_os_localaddr(context, addr) return 0; } -#else /* Windows/Mac version */ +#elif defined(_MSDOS) || defined(_WIN32) /* Windows version */ /* * Hold on to your lunch! Backup kludge method of obtaining your * local IP address, courtesy of Windows Socket Network Programming, * by Robert Quinn */ -#if defined(_MSDOS) || defined(_WIN32) static struct hostent *local_addr_fallback_kludge() { static struct hostent host; @@ -550,7 +549,6 @@ static struct hostent *local_addr_fallback_kludge() return &host; } -#endif /* No ioctls in winsock so we just assume there is only one networking * card per machine, so gethostent is good enough. @@ -636,4 +634,79 @@ krb5_os_localaddr (krb5_context context, krb5_address ***addr) { return(err); } + +#else + +/* Mac OS 9 version */ +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_os_localaddr (krb5_context context, krb5_address ***addr) +{ + // First, build the new list + krb5_address ** addresses = NULL; + SInt32 interfaceCount; + SInt32 interfaceIndex; + InetInterfaceInfo info; + krb5_error_code err = 0; + + // Loop over the addressed once so we know how many there are + for (interfaceCount = 0; err == noErr; interfaceCount++) { + err = OTInetGetInterfaceInfo (&info, interfaceIndex); + } + + // Allocate storage for the address list + addresses = (krb5_address **) malloc( sizeof (krb5_address *) * (interfaceCount + 1)); + if (addresses == NULL) { + err = ENOMEM; + goto cleanup; + } + + // Set the pointers to NULL so we will have a termination pointer + memset (addresses, 0, sizeof (krb5_address *) * (interfaceCount + 1)); + + // Look up the addresses and store them in the list + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + err = OTInetGetInterfaceInfo (&info, interfaceIndex); + if (err != noErr) { + err = 0; + break; + } + + addresses[interfaceIndex] = (krb5_address *) malloc (sizeof (krb5_address)); + if (addresses[interfaceIndex] == NULL) { + err = ENOMEM; + goto cleanup; + } + + addresses[interfaceIndex]->magic = KV5M_ADDRESS; + addresses[interfaceIndex]->addrtype = AF_INET; + addresses[interfaceIndex]->length = INADDRSZ; + addresses[interfaceIndex]->contents = (unsigned char *) malloc (addresses[interfaceIndex]->length); + if (addresses[interfaceIndex]->contents == NULL) { + err = ENOMEM; + goto cleanup; + } + + memcpy(addresses[interfaceIndex]->contents, &info.fAddress, addresses[interfaceIndex]->length); + } + +cleanup: + if (err) { + if (addresses != NULL) { + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + if (addresses[interfaceIndex] != NULL) { + if (addresses[interfaceIndex]->contents != NULL) { + free (addresses[interfaceIndex]->contents); + } + free (addresses[interfaceIndex]); + } + } + free(addresses); + } + } else { + *addr = addresses; + } + + return(err); + +} #endif |