From 1c157b1394d007386211ad35cf132450e6256584 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 28 Mar 2003 22:59:45 +0000 Subject: [PATCH] * kcmd.c (kcmd_connect): Log errors if a connect to port 0 is attempted. Report port number in connection failure. (setup_secondary_channel): Use socklen_t for socket address length. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15307 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 7 +++++++ src/appl/bsd/kcmd.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index 303400170..e5cdb1225 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,10 @@ +2003-03-28 Ken Raeburn + + * kcmd.c (kcmd_connect): Log errors if a connect to port 0 is + attempted. Report port number in connection failure. + (setup_secondary_channel): Use socklen_t for socket address + length. + 2003-03-04 Ken Raeburn * compat_recv.c: Only include krb.h if KRB5_KRB4_COMPAT. diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 5388e7a7b..2069ce93f 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -201,6 +201,10 @@ kcmd_connect (int *sp, int *addrfamilyp, struct sockaddr_in *sockinp, char rport_buf[10]; GETSOCKNAME_ARG3_TYPE sin_len; + if (rport == 0) { + fprintf(stderr, "can't connect to %s port 0\n", hname); + return -1; + } sprintf(rport_buf, "%d", ntohs(rport)); memset(&aihints, 0, sizeof(aihints)); aihints.ai_socktype = SOCK_STREAM; @@ -231,9 +235,28 @@ kcmd_connect (int *sp, int *addrfamilyp, struct sockaddr_in *sockinp, for (ap2 = ap; ap; ap = ap->ai_next) { char hostbuf[NI_MAXHOST]; + char portbuf[NI_MAXSERV]; int oerrno; int af = ap->ai_family; + /* @@ Debugging. Yuck. */ + switch (af) { + case AF_INET: + if (((struct sockaddr_in *)ap->ai_addr)->sin_port == 0) { + fprintf(stderr, "internal error: got ipv4 address but port zero?\n"); + continue; + } + break; +#ifdef KRB5_USE_INET6 + case AF_INET6: + if (((struct sockaddr_in6 *)ap->ai_addr)->sin6_port == 0) { + fprintf(stderr, "internal error: got ipv6 address but port zero?\n"); + continue; + } + break; +#endif + } + for (;;) { s = getport(lportp, &af); if (s < 0) { @@ -254,12 +277,14 @@ kcmd_connect (int *sp, int *addrfamilyp, struct sockaddr_in *sockinp, oerrno = errno; aierr = getnameinfo(ap->ai_addr, ap->ai_addrlen, - hostbuf, sizeof(hostbuf), 0, 0, NI_NUMERICHOST); + hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf), + NI_NUMERICHOST | NI_NUMERICSERV); if (aierr) fprintf(stderr, "connect to : ", gai_strerror (aierr)); else - fprintf(stderr, "connect to address %s: ", hostbuf); + fprintf(stderr, "connect to address %s port %s: ", hostbuf, + portbuf); errno = oerrno; perror(0); @@ -292,7 +317,7 @@ setup_secondary_channel (int s, int *fd2p, int *lportp, int *addrfamilyp, *lportp = 0; } else { char num[8]; - int len = sizeof (*fromp); + socklen_t len = sizeof (*fromp); size_t slen; int s2 = getport(lportp, addrfamilyp), s3; fd_set rfds, xfds; -- 2.26.2