diff options
Diffstat (limited to 'crypto/heimdal/lib/krb5/sock_principal.c')
-rw-r--r-- | crypto/heimdal/lib/krb5/sock_principal.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/crypto/heimdal/lib/krb5/sock_principal.c b/crypto/heimdal/lib/krb5/sock_principal.c index d7a77a4..7bb0bdf 100644 --- a/crypto/heimdal/lib/krb5/sock_principal.c +++ b/crypto/heimdal/lib/krb5/sock_principal.c @@ -33,7 +33,7 @@ #include "krb5_locl.h" -RCSID("$Id: sock_principal.c,v 1.13 2001/05/14 06:14:51 assar Exp $"); +RCSID("$Id: sock_principal.c,v 1.16 2001/07/26 09:05:30 assar Exp $"); krb5_error_code krb5_sock_to_principal (krb5_context context, @@ -43,48 +43,28 @@ krb5_sock_to_principal (krb5_context context, krb5_principal *ret_princ) { krb5_error_code ret; - krb5_address address; struct sockaddr_storage __ss; struct sockaddr *sa = (struct sockaddr *)&__ss; - socklen_t len = sizeof(__ss); - struct hostent *hostent; - int family; - char *hname = NULL; + socklen_t salen = sizeof(__ss); + char hostname[NI_MAXHOST]; - if (getsockname (sock, sa, &len) < 0) { + if (getsockname (sock, sa, &salen) < 0) { ret = errno; krb5_set_error_string (context, "getsockname: %s", strerror(ret)); return ret; } - family = sa->sa_family; - - ret = krb5_sockaddr2address (context, sa, &address); - if (ret) - return ret; - - hostent = roken_gethostbyaddr (address.address.data, - address.address.length, - family); - - if (hostent == NULL) { - krb5_set_error_string (context, "gethostbyaddr: %s", - hstrerror(h_errno)); - return krb5_h_errno_to_heim_errno(h_errno); - } - hname = hostent->h_name; - if (strchr(hname, '.') == NULL) { - char **a; + ret = getnameinfo (sa, salen, hostname, sizeof(hostname), NULL, 0, 0); + if (ret) { + int save_errno = errno; - for (a = hostent->h_aliases; a != NULL && *a != NULL; ++a) - if (strchr(*a, '.') != NULL) { - hname = *a; - break; - } + krb5_set_error_string (context, "getnameinfo: %s", gai_strerror(ret)); + return krb5_eai_to_heim_errno(ret, save_errno); } - return krb5_sname_to_principal (context, - hname, - sname, - type, - ret_princ); + ret = krb5_sname_to_principal (context, + hostname, + sname, + type, + ret_princ); + return ret; } |