From 7e6a7da60042dbf033cc3136877a2862bf825bd1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 13 Feb 2019 20:00:53 -0600 Subject: Move nanomove(), nanodiff(), union socksaddr, and xrecvwait() to lib. --- toys/net/sntp.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) (limited to 'toys') diff --git a/toys/net/sntp.c b/toys/net/sntp.c index edccd209..96139e8f 100644 --- a/toys/net/sntp.c +++ b/toys/net/sntp.c @@ -6,7 +6,7 @@ modes: oneshot display, oneshot set, persist, serve, multi -USE_SNTP(NEWTOY(sntp, "m:Sp:asdDqr#<4>17=10[!as]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_SNTP(NEWTOY(sntp, "M:m:Sp:asdDqr#<4>17=10[!as]", TOYFLAG_USR|TOYFLAG_BIN)) config SNTP bool "sntp" @@ -21,6 +21,7 @@ config SNTP -a Adjust system clock gradually -S Serve time instead of querying (bind to SERVER address if specified) -m Wait for updates from multicast ADDRESS (RFC 4330 says use 224.0.1.1) + -M Multicast server on ADDRESS -d Daemonize (run in background re-querying ) -D Daemonize but stay in foreground: re-query time every 1000 seconds -r Retry shift (every 1<= 0) { - struct pollfd pfd; - - pfd.fd = fd; - pfd.events = POLLIN; - if (!xpoll(&pfd, 1, timeout)) return 0; - } - - len = recvfrom(fd, buf, len, 0, (void *)sa, &sl); - if (len<0) perror_exit("recvfrom"); - - return len; -} - -// Adjust timespec by nanosecond offset -static void nanomove(struct timespec *ts, long long offset) -{ - long long nano = ts->tv_nsec + offset, secs = nano/1000000000; - - ts->tv_sec += secs; - nano %= 1000000000; - if (nano<0) { - ts->tv_sec--; - nano += 1000000000; - } - ts->tv_nsec = nano; -} - // Get time and return ntptime (saving timespec in pointer if not null) // NTP time is high 32 bits = seconds since 1970 (blame RFC 868), low 32 bits // fraction of a second. -- cgit v1.2.3