diff options
author | Assar Westerlund <assar@sics.se> | 1999-08-05 11:39:57 +0000 |
---|---|---|
committer | Assar Westerlund <assar@sics.se> | 1999-08-05 11:39:57 +0000 |
commit | 106427eaa1397e39b3259961c73a10355d8fca32 (patch) | |
tree | 54cf98e7cac659c1ac98648fc3c2478c781757ff /appl/kf | |
parent | d2120e06709b92df97ce40c73469ea09bacafdfe (diff) |
make v6 friendly and simplify
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6751 ec53bebd-3082-4978-b11e-865c3cabbd6b
Diffstat (limited to 'appl/kf')
-rw-r--r-- | appl/kf/kf.c | 77 | ||||
-rw-r--r-- | appl/kf/kfd.c | 28 |
2 files changed, 30 insertions, 75 deletions
diff --git a/appl/kf/kf.c b/appl/kf/kf.c index 222336259..324f36fd9 100644 --- a/appl/kf/kf.c +++ b/appl/kf/kf.c @@ -129,9 +129,6 @@ client_setup(krb5_context *context, int *argc, char **argv) static int proto (int sock, const char *hostname, const char *service) { - struct sockaddr_in remote, local; - int addrlen; - krb5_address remote_addr, local_addr; krb5_auth_context auth_context; krb5_error_code status; krb5_principal server; @@ -146,38 +143,15 @@ proto (int sock, const char *hostname, const char *service) krb5_principal principal; char ret_string[10]; - addrlen = sizeof(local); - if (getsockname (sock, (struct sockaddr *)&local, &addrlen) < 0 - || addrlen != sizeof(local)) { - warn ("getsockname(%s)", hostname); - return 1; - } - - addrlen = sizeof(remote); - if (getpeername (sock, (struct sockaddr *)&remote, &addrlen) < 0 - || addrlen != sizeof(remote)) { - warn ("getpeername(%s)", hostname); - return 1; - } - status = krb5_auth_con_init (context, &auth_context); if (status) { krb5_warn (context, status, "krb5_auth_con_init"); return 1; } - local_addr.addr_type = AF_INET; - local_addr.address.length = sizeof(local.sin_addr); - local_addr.address.data = &local.sin_addr; - - remote_addr.addr_type = AF_INET; - remote_addr.address.length = sizeof(remote.sin_addr); - remote_addr.address.data = &remote.sin_addr; - - status = krb5_auth_con_setaddrs (context, - auth_context, - &local_addr, - &remote_addr); + status = krb5_auth_con_setaddrs_from_fd (context, + auth_context, + &sock); if (status) { krb5_warn (context, status, "krb5_auth_con_setaddr"); return 1; @@ -329,32 +303,35 @@ proto (int sock, const char *hostname, const char *service) static int doit (const char *hostname, int port, const char *service) { - struct in_addr **h; - struct hostent *hostent; - - hostent = roken_gethostbyname (hostname); - if (hostent == NULL) { - warn ("gethostbyname '%s' failed: %s", - hostname, - hstrerror(h_errno)); - return 1; - } - - for (h = (struct in_addr **)hostent->h_addr_list; - *h != NULL; - ++h) { - struct sockaddr_in addr; + struct hostent *hostent = NULL; + char **h; + int error; + int af; + +#ifdef HAVE_IPV6 + if (hostent == NULL) + hostent = getipnodebyname (hostname, AF_INET6, 0, &error); +#endif + if (hostent == NULL) + hostent = getipnodebyname (hostname, AF_INET, 0, &error); + + if (hostent == NULL) + errx(1, "gethostbyname '%s' failed: %s", hostname, hstrerror(error)); + + af = hostent->h_addrtype; + + for (h = hostent->h_addr_list; *h != NULL; ++h) { + struct sockaddr_storage sa_ss; + struct sockaddr *sa = (struct sockaddr *)&sa_ss; int s; - memset (&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = port; - addr.sin_addr = **h; + sa->sa_family = af; + socket_set_address_and_port (sa, *h, port); - s = socket (AF_INET, SOCK_STREAM, 0); + s = socket (af, SOCK_STREAM, 0); if (s < 0) err (1, "socket"); - if (connect (s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + if (connect (s, sa, socket_sockaddr_size(sa)) < 0) { warn ("connect(%s)", hostname); close (s); continue; diff --git a/appl/kf/kfd.c b/appl/kf/kfd.c index 76f50abb4..3e3451ade 100644 --- a/appl/kf/kfd.c +++ b/appl/kf/kfd.c @@ -130,9 +130,6 @@ syslog_and_cont (const char *m, ...) static int proto (int sock, const char *service) { - struct sockaddr_in remote, local; - int addrlen; - krb5_address remote_addr, local_addr; krb5_auth_context auth_context; krb5_error_code status; krb5_principal server; @@ -150,33 +147,14 @@ proto (int sock, const char *service) char ccname[MAXPATHLEN]; struct passwd *pwd; - addrlen = sizeof(local); - if (getsockname (sock, (struct sockaddr *)&local, &addrlen) < 0 - || addrlen != sizeof(local)) - syslog_and_die("getsockname: %s",strerror(errno)); - - addrlen = sizeof(remote); - if (getpeername (sock, (struct sockaddr *)&remote, &addrlen) < 0 - || addrlen != sizeof(remote)) - syslog_and_die("getpeername: %s",strerror(errno)); - status = krb5_auth_con_init (context, &auth_context); if (status) syslog_and_die("krb5_auth_con_init: %s", krb5_get_err_text(context, status)); - local_addr.addr_type = AF_INET; - local_addr.address.length = sizeof(local.sin_addr); - local_addr.address.data = &local.sin_addr; - - remote_addr.addr_type = AF_INET; - remote_addr.address.length = sizeof(remote.sin_addr); - remote_addr.address.data = &remote.sin_addr; - - status = krb5_auth_con_setaddrs (context, - auth_context, - &local_addr, - &remote_addr); + status = krb5_auth_con_setaddrs_from_fd (context, + auth_context, + &sock); if (status) syslog_and_die("krb5_auth_con_setaddr: %s", krb5_get_err_text(context, status)); |