summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-11 17:15:26 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-11 17:15:26 +0000
commitbf43c0c082cf7240e06c2a1cfac0231c6ba35c66 (patch)
treec2c435d2c454db9ea5d546f0336237cc68b39c57
parentf94bcc243c2f1b9dd29af2a552ec3fbc9d86e7e2 (diff)
dynamic fd_set (please check, todd)
-rw-r--r--bin/date/netdate.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/bin/date/netdate.c b/bin/date/netdate.c
index 3e68bc182c5..b4190ce4f0f 100644
--- a/bin/date/netdate.c
+++ b/bin/date/netdate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netdate.c,v 1.6 1997/03/26 19:08:06 deraadt Exp $ */
+/* $OpenBSD: netdate.c,v 1.7 1997/06/11 17:15:25 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.6 1997/03/26 19:08:06 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: netdate.c,v 1.7 1997/06/11 17:15:25 deraadt Exp $";
#endif
#endif /* not lint */
@@ -80,9 +80,10 @@ netsettime(tval)
struct servent *sp;
struct tsp msg;
struct sockaddr_in sin, dest, from;
- fd_set ready;
+ int fdsn;
+ fd_set *fdsp = NULL;
long waittime;
- int s, length, timed_ack, found, err;
+ int s, length, timed_ack, found, error;
char hostname[MAXHOSTNAMELEN];
if ((sp = getservbyname("timed", "udp")) == NULL) {
@@ -133,23 +134,27 @@ netsettime(tval)
timed_ack = -1;
waittime = WAITACK;
+
+ fdsn = howmany(s+1, NFDBITS) * sizeof(fd_mask);
+ if ((fdsp = (fd_set *)malloc(fdsn)) == NULL)
+ err(1, "malloc");
loop:
tout.tv_sec = waittime;
tout.tv_usec = 0;
- FD_ZERO(&ready);
- FD_SET(s, &ready);
- found = select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout);
+ memset(fdsp, 0, fdsn);
+ FD_SET(s, fdsp);
+ found = select(s+1, fdsp, (fd_set *)0, (fd_set *)0, &tout);
- length = sizeof(err);
+ length = sizeof(error);
if (!getsockopt(s,
- SOL_SOCKET, SO_ERROR, (char *)&err, &length) && err) {
- if (err != ECONNREFUSED)
+ SOL_SOCKET, SO_ERROR, (char *)&error, &length) && error) {
+ if (error != ECONNREFUSED)
warn("send (delayed error)");
goto bad;
}
- if (found > 0 && FD_ISSET(s, &ready)) {
+ if (found > 0 && FD_ISSET(s, fdsp)) {
length = sizeof(struct sockaddr_in);
if (recvfrom(s, &msg, sizeof(struct tsp), 0,
(struct sockaddr *)&from, &length) < 0) {
@@ -167,6 +172,7 @@ loop:
goto loop;
case TSP_DATEACK:
(void)close(s);
+ free(fdsp);
return (0);
default:
warnx("wrong ack received from timed: %s",
@@ -179,6 +185,8 @@ loop:
warnx("can't reach time daemon, time set locally");
bad:
+ if (fdsp)
+ free(fdsp);
(void)close(s);
return (retval = 2);
}