From 47dc94a94db59eb276035a8e2cb09c7533f43631 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 4 Aug 1996 15:45:27 +0000 Subject: use bindresvport --- bin/date/netdate.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'bin/date/netdate.c') diff --git a/bin/date/netdate.c b/bin/date/netdate.c index 6c51040f255..da7b8d94af9 100644 --- a/bin/date/netdate.c +++ b/bin/date/netdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netdate.c,v 1.2 1996/06/23 14:19:43 deraadt Exp $ */ +/* $OpenBSD: netdate.c,v 1.3 1996/08/04 15:45:26 deraadt Exp $ */ /* $NetBSD: netdate.c,v 1.10 1995/09/07 06:21:06 jtc Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)netdate.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: netdate.c,v 1.2 1996/06/23 14:19:43 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: netdate.c,v 1.3 1996/08/04 15:45:26 deraadt Exp $"; #endif #endif /* not lint */ @@ -81,7 +81,7 @@ netsettime(tval) struct sockaddr_in sin, dest, from; fd_set ready; long waittime; - int s, length, port, timed_ack, found, err; + int s, length, timed_ack, found, err; char hostname[MAXHOSTNAMELEN]; if ((sp = getservbyname("timed", "udp")) == NULL) { @@ -104,17 +104,7 @@ netsettime(tval) memset(&sin, 0, sizeof(sin)); sin.sin_len = sizeof(struct sockaddr_in); sin.sin_family = AF_INET; - for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) { - sin.sin_port = htons((u_short)port); - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - break; - if (errno == EADDRINUSE) - continue; - if (errno != EADDRNOTAVAIL) - warn("bind"); - goto bad; - } - if (port == IPPORT_RESERVED / 2) { + if (bindresvport(s, &sin) < 0) { warnx("all ports in use"); goto bad; } -- cgit v1.2.3