From a1d408df49407759e5a5040f1faf2e772846b9ee Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 30 Dec 1996 14:12:36 +0000 Subject: [PATCH] - Man page fix, updates. - minor cosmetic tweaks Obtained from: a diff of FreeBSD vs. OpenBSD/NetBSD rpc code. --- lib/libc/rpc/bindresvport.3 | 9 +++++++-- lib/libc/rpc/bindresvport.c | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/libc/rpc/bindresvport.3 b/lib/libc/rpc/bindresvport.3 index 8b9f3bf25326..5dd71e35d25f 100644 --- a/lib/libc/rpc/bindresvport.3 +++ b/lib/libc/rpc/bindresvport.3 @@ -9,11 +9,11 @@ .Fd #include .Fd #include .Ft int -.Fn bindresvport "int sd "struct sockaddr_in **sin" +.Fn bindresvport "int sd" "struct sockaddr_in **sin" .Sh DESCRIPTION .Nm Bindresvport is used to bind a socket descriptor to a privileged -.Em IP +.Tn IP port, that is, a port number in the range 0-1023. The routine returns 0 if it is successful, @@ -23,3 +23,8 @@ set to reflect the cause of the error. .Pp Only root can bind to a privileged port; this call will fail for any other users. +.Pp +If the value of sin->sin_port is non-zero +.Fn bindresvport +will attempt to use that specific port. If it fails, it chooses another +privileged port automatically. diff --git a/lib/libc/rpc/bindresvport.c b/lib/libc/rpc/bindresvport.c index 4411ba95cf4f..950881804b64 100644 --- a/lib/libc/rpc/bindresvport.c +++ b/lib/libc/rpc/bindresvport.c @@ -31,7 +31,7 @@ /*static char *sccsid = "from: @(#)bindresvport.c 1.8 88/02/08 SMI";*/ /*static char *sccsid = "from: @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC";*/ /*from: OpenBSD: bindresvport.c,v 1.7 1996/07/30 16:25:47 downsj Exp */ -static char *rcsid = "$Id: bindresvport.c,v 1.4 1996/06/10 00:49:15 jraynard Exp $"; +static char *rcsid = "$Id: bindresvport.c,v 1.5 1996/08/12 14:09:46 peter Exp $"; #endif /* @@ -61,8 +61,8 @@ bindresvport(sd, sin) if (sin == (struct sockaddr_in *)0) { sin = &myaddr; - memset(sin, 0, sizeof(*sin)); - sin->sin_len = sizeof(*sin); + memset(sin, 0, sinlen); + sin->sin_len = sinlen; sin->sin_family = AF_INET; } else if (sin->sin_family != AF_INET) { errno = EPFNOSUPPORT; @@ -83,7 +83,7 @@ bindresvport(sd, sin) return(error); } - error = bind(sd, (struct sockaddr *)sin, sizeof(*sin)); + error = bind(sd, (struct sockaddr *)sin, sinlen); if (sin->sin_port == 0) { int saved_errno = errno; @@ -96,8 +96,6 @@ bindresvport(sd, sin) } if (sin != &myaddr) { - int sinlen = sizeof(*sin); - /* Hmm, what did the kernel assign... */ if (getsockname(sd, (struct sockaddr *)sin, &sinlen) < 0)