From 7b4851649d5c70bd2eae32e8ea14d0dd1f0d92d7 Mon Sep 17 00:00:00 2001 From: lukem Date: Sun, 18 Jan 1998 06:22:19 +0000 Subject: [PATCH] use bindresvport for rresvport (from freebsd). old code #if 0-ed out --- lib/libc/net/rcmd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 7f3602f68c76..31cf24997aed 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rcmd.c,v 1.22 1997/12/21 17:14:24 christos Exp $ */ +/* $NetBSD: rcmd.c,v 1.23 1998/01/18 06:22:19 lukem Exp $ */ /* * Copyright (c) 1997 Matthew R. Green. @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #else -__RCSID("$NetBSD: rcmd.c,v 1.22 1997/12/21 17:14:24 christos Exp $"); +__RCSID("$NetBSD: rcmd.c,v 1.23 1998/01/18 06:22:19 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,6 +51,7 @@ __RCSID("$NetBSD: rcmd.c,v 1.22 1997/12/21 17:14:24 christos Exp $"); #include #include +#include #include #include @@ -396,6 +397,7 @@ rresvport(alport) s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) return (-1); +#if 0 for (;;) { sin.sin_port = htons((u_short)*alport); if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) @@ -411,6 +413,18 @@ rresvport(alport) return (-1); } } +#else + sin.sin_port = 0; + if (bindresvport(s, &sin) < 0) { + int sverr = errno; + + (void)close(s); + errno = sverr; + return (-1); + } + *alport = (int)ntohs(sin.sin_port); + return (s); +#endif } int __check_rhosts_file = 1;