- (djm) Sync bsd-* support files:
   - deraadt@cvs.openbsd.org 2000/01/26 03:43:20
     [rresvport.c bindresvport.c]
     new bindresvport() semantics that itojun, shin, jean-luc and i have
     agreed on, which will be happy for the future. bindresvport_sa() for
     sockaddr *, too.  docs later..
   - deraadt@cvs.openbsd.org 2000/01/24 02:24:21
     [bindresvport.c]
     in bindresvport(), if sin is non-NULL, example sin->sin_family for
     the actual family being processed
diff --git a/ChangeLog b/ChangeLog
index d15dd1d..eafed7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+20010125
+ - (djm) Sync bsd-* support files:
+   - deraadt@cvs.openbsd.org 2000/01/26 03:43:20
+     [rresvport.c bindresvport.c]
+     new bindresvport() semantics that itojun, shin, jean-luc and i have 
+     agreed on, which will be happy for the future. bindresvport_sa() for
+     sockaddr *, too.  docs later..
+   - deraadt@cvs.openbsd.org 2000/01/24 02:24:21
+     [bindresvport.c]
+     in bindresvport(), if sin is non-NULL, example sin->sin_family for 
+     the actual family being processed
+
 20010124
  - (bal) OpenBSD Resync
    - markus@cvs.openbsd.org 2001/01/23 10:45:10
diff --git a/bsd-bindresvport.c b/bsd-bindresvport.c
index 7faf731..332bcb0 100644
--- a/bsd-bindresvport.c
+++ b/bsd-bindresvport.c
@@ -1,3 +1,5 @@
+/* This file has be modified from the original OpenBSD source */
+
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -29,10 +31,10 @@
 
 #include "config.h"
 
-#ifndef HAVE_BINDRESVPORT_AF
+#ifndef HAVE_BINDRESVPORT_SA
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: bindresvport.c,v 1.11 1999/12/17 19:22:08 deraadt Exp $";
+static char *rcsid = "$OpenBSD: bindresvport.c,v 1.13 2000/01/26 03:43:21 deraadt Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /*
@@ -51,12 +53,11 @@
  * Bind a socket to a privileged IP port
  */
 int
-bindresvport_af(sd, sa, af)
+bindresvport_sa(sd, sa)
 	int sd;
 	struct sockaddr *sa;
-	int af;
 {
-	int error;
+	int error, af;
 	struct sockaddr_storage myaddr;
 	struct sockaddr_in *sin;
 	struct sockaddr_in6 *sin6;
@@ -68,7 +69,14 @@
 	if (sa == NULL) {
 		memset(&myaddr, 0, sizeof(myaddr));
 		sa = (struct sockaddr *)&myaddr;
-	}
+
+		if (getsockname(sd, sa, &salen) == -1)
+			return -1;	/* errno is correctly set */
+
+		af = sa->sa_family;
+		memset(&myaddr, 0, salen);
+	} else
+		af = sa->sa_family;
 
 	if (af == AF_INET) {
 		sin = (struct sockaddr_in *)sa;
@@ -95,7 +103,7 @@
 		*portp = htons(port);
 		
 		error = bind(sd, sa, salen);
-		
+
 		/* Terminate on success */
 		if (error == 0)
 			break;
@@ -112,4 +120,4 @@
 	return (error);
 }
 
-#endif /* HAVE_BINDRESVPORT_AF */
+#endif /* HAVE_BINDRESVPORT_SA */
diff --git a/bsd-bindresvport.h b/bsd-bindresvport.h
index 4ef4c2f..6dbf8a2 100644
--- a/bsd-bindresvport.h
+++ b/bsd-bindresvport.h
@@ -3,8 +3,8 @@
 
 #include "config.h"
 
-#ifndef HAVE_BINDRESVPORT_AF
-int bindresvport_af(int sd, struct sockaddr *sa, int af);
-#endif /* !HAVE_BINDRESVPORT_AF */
+#ifndef HAVE_BINDRESVPORT_SA
+int bindresvport_sa(int sd, struct sockaddr *sa);
+#endif /* !HAVE_BINDRESVPORT_SA */
 
 #endif /* _BSD_BINDRESVPORT_H */
diff --git a/bsd-rresvport.c b/bsd-rresvport.c
index 392768c..44eac20 100644
--- a/bsd-rresvport.c
+++ b/bsd-rresvport.c
@@ -38,7 +38,7 @@
 #ifndef HAVE_RRESVPORT_AF
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: rresvport.c,v 1.4 1999/12/17 20:48:03 deraadt Exp $";
+static char *rcsid = "$OpenBSD: rresvport.c,v 1.5 2000/01/26 03:43:20 deraadt Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #include "includes.h"
@@ -94,7 +94,8 @@
 	}
 
 	*portp = 0;
-	if (bindresvport_af(s, sa, af) == -1) {
+	sa->sa_family = af;
+	if (bindresvport_sa(s, sa) == -1) {
 		(void)close(s);
 		return (-1);
 	}
diff --git a/configure.in b/configure.in
index 7cc5858..f217e5a 100644
--- a/configure.in
+++ b/configure.in
@@ -315,7 +315,7 @@
 AC_CHECK_HEADERS(bstring.h endian.h floatingpoint.h getopt.h lastlog.h limits.h login.h login_cap.h maillock.h netdb.h netgroup.h netinet/in_systm.h paths.h poll.h pty.h regex.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/queue.h sys/select.h sys/stat.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h sys/un.h stddef.h time.h ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h)
 
 dnl    Checks for library functions.
-AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_af clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
+AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_sa clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
 dnl    Checks for time functions
 AC_CHECK_FUNCS(gettimeofday time)
 dnl    Checks for libutil functions