use new addr_families functions

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3517 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1997-09-21 13:24:31 +00:00
parent ebe1fa6374
commit 2ca944d2bc
5 changed files with 168 additions and 234 deletions

View File

@@ -48,34 +48,31 @@ krb5_sock_to_principal (krb5_context context,
krb5_principal *ret_princ)
{
krb5_error_code ret;
#if defined(AF_INET6) && defined(HAVE_SOCKADDR_IN6)
struct sockaddr_in6 addr;
#else
struct sockaddr_in addr;
#endif
int len = sizeof(addr);
krb5_address address;
int len = krb5_max_sockaddr_size ();
char *buf = malloc(len);
struct sockaddr *sa;
struct hostent *hostent;
int family;
if (getsockname (sock, (struct sockaddr *)&addr, &len) < 0)
if (buf == NULL)
return ENOMEM;
sa = (struct sockaddr *)buf;
if (getsockname (sock, sa, &len) < 0) {
free (buf);
return errno;
#if defined(AF_INET6) && defined(HAVE_SOCKADDR_IN6)
if(len == sizeof(struct sockaddr_in6))
hostent = gethostbyaddr ((const char *)&addr.sin6_addr,
sizeof(addr.sin6_addr),
addr.sin6_family);
else {
struct sockaddr_in *foo = (struct sockaddr_in *)&addr;
hostent = gethostbyaddr ((const char *)&foo->sin_addr,
sizeof(foo->sin_addr),
foo->sin_family);
}
#else
hostent = gethostbyaddr ((const char *)&addr.sin_addr,
sizeof(addr.sin_addr),
addr.sin_family);
#endif
family = sa->sa_family;
ret = krb5_sockaddr2address (sa, &address);
free (buf);
if (ret)
return ret;
hostent = gethostbyaddr (address.address.data,
address.address.length,
family);
if (hostent == NULL)
return h_errno;