make v6 friendly and simplify

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6751 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-08-05 11:39:57 +00:00
parent d2120e0670
commit 106427eaa1
2 changed files with 28 additions and 73 deletions

View File

@@ -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;
struct hostent *hostent = NULL;
char **h;
int error;
int af;
hostent = roken_gethostbyname (hostname);
if (hostent == NULL) {
warn ("gethostbyname '%s' failed: %s",
hostname,
hstrerror(h_errno));
return 1;
}
#ifdef HAVE_IPV6
if (hostent == NULL)
hostent = getipnodebyname (hostname, AF_INET6, 0, &error);
#endif
if (hostent == NULL)
hostent = getipnodebyname (hostname, AF_INET, 0, &error);
for (h = (struct in_addr **)hostent->h_addr_list;
*h != NULL;
++h) {
struct sockaddr_in addr;
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;

View File

@@ -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));