Deleted Added
full compact
ntpdate.c (82498) ntpdate.c (106163)
1/*
2 * ntpdate - set the time of day by polling one or more NTP servers
3 */
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif
8
9#ifdef HAVE_NETINFO
10#include <netinfo/ni.h>
11#endif
12
1/*
2 * ntpdate - set the time of day by polling one or more NTP servers
3 */
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif
8
9#ifdef HAVE_NETINFO
10#include <netinfo/ni.h>
11#endif
12
13#include "ntp_machine.h"
13#include "ntp_fp.h"
14#include "ntp.h"
15#include "ntp_io.h"
16#include "ntp_unixtime.h"
17#include "ntpdate.h"
18#include "ntp_string.h"
19#include "ntp_syslog.h"
20#include "ntp_select.h"

--- 6 unchanged lines hidden (view full) ---

27#include <stdio.h>
28#include <signal.h>
29#include <ctype.h>
30#ifdef HAVE_POLL_H
31# include <poll.h>
32#endif
33#ifndef SYS_WINNT
34# include <netdb.h>
14#include "ntp_fp.h"
15#include "ntp.h"
16#include "ntp_io.h"
17#include "ntp_unixtime.h"
18#include "ntpdate.h"
19#include "ntp_string.h"
20#include "ntp_syslog.h"
21#include "ntp_select.h"

--- 6 unchanged lines hidden (view full) ---

28#include <stdio.h>
29#include <signal.h>
30#include <ctype.h>
31#ifdef HAVE_POLL_H
32# include <poll.h>
33#endif
34#ifndef SYS_WINNT
35# include <netdb.h>
35# include <sys/signal.h>
36# ifdef HAVE_SYS_SIGNAL_H
37# include <sys/signal.h>
38# else
39# include <signal.h>
40# endif
36# ifdef HAVE_SYS_IOCTL_H
37# include <sys/ioctl.h>
38# endif
39#endif /* SYS_WINNT */
40#ifdef HAVE_SYS_RESOURCE_H
41# include <sys/resource.h>
42#endif /* HAVE_SYS_RESOURCE_H */
43

--- 374 unchanged lines hidden (view full) ---

418 ++errflg;
419 break;
420 default:
421 break;
422 }
423
424 if (errflg) {
425 (void) fprintf(stderr,
41# ifdef HAVE_SYS_IOCTL_H
42# include <sys/ioctl.h>
43# endif
44#endif /* SYS_WINNT */
45#ifdef HAVE_SYS_RESOURCE_H
46# include <sys/resource.h>
47#endif /* HAVE_SYS_RESOURCE_H */
48

--- 374 unchanged lines hidden (view full) ---

423 ++errflg;
424 break;
425 default:
426 break;
427 }
428
429 if (errflg) {
430 (void) fprintf(stderr,
426 "usage: %s [-bBdqsv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-r rate] [-t timeo] server ...\n",
431 "usage: %s [-bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-r rate] [-t timeo] server ...\n",
427 progname);
428 exit(2);
429 }
430
431 if (debug || simple_query) {
432#ifdef HAVE_SETVBUF
433 static char buf[BUFSIZ];
434 setvbuf(stdout, buf, _IOLBF, BUFSIZ);

--- 295 unchanged lines hidden (view full) ---

730static void
731receive(
732 struct recvbuf *rbufp
733 )
734{
735 register struct pkt *rpkt;
736 register struct server *server;
737 register s_fp di;
432 progname);
433 exit(2);
434 }
435
436 if (debug || simple_query) {
437#ifdef HAVE_SETVBUF
438 static char buf[BUFSIZ];
439 setvbuf(stdout, buf, _IOLBF, BUFSIZ);

--- 295 unchanged lines hidden (view full) ---

735static void
736receive(
737 struct recvbuf *rbufp
738 )
739{
740 register struct pkt *rpkt;
741 register struct server *server;
742 register s_fp di;
738 l_fp t10, t23;
743 l_fp t10, t23, tmp;
739 l_fp org;
740 l_fp rec;
741 l_fp ci;
742 int has_mac;
743 int is_authentic;
744
745 if (debug)
746 printf("receive(%s)\n", ntoa(&rbufp->recv_srcadr));

--- 105 unchanged lines hidden (view full) ---

852 */
853 t10 = server->org; /* pkt.xmt == t1 */
854 L_SUB(&t10, &rbufp->recv_time); /* recv_time == t0*/
855
856 t23 = rec; /* pkt.rec == t2 */
857 L_SUB(&t23, &org); /* pkt->org == t3 */
858
859 /* now have (t2 - t3) and (t0 - t1). Calculate (ci) and (di) */
744 l_fp org;
745 l_fp rec;
746 l_fp ci;
747 int has_mac;
748 int is_authentic;
749
750 if (debug)
751 printf("receive(%s)\n", ntoa(&rbufp->recv_srcadr));

--- 105 unchanged lines hidden (view full) ---

857 */
858 t10 = server->org; /* pkt.xmt == t1 */
859 L_SUB(&t10, &rbufp->recv_time); /* recv_time == t0*/
860
861 t23 = rec; /* pkt.rec == t2 */
862 L_SUB(&t23, &org); /* pkt->org == t3 */
863
864 /* now have (t2 - t3) and (t0 - t1). Calculate (ci) and (di) */
865 /*
866 * Calculate (ci) = ((t1 - t0) / 2) + ((t2 - t3) / 2)
867 * For large offsets this may prevent an overflow on '+'
868 */
860 ci = t10;
869 ci = t10;
861 L_ADD(&ci, &t23);
862 L_RSHIFT(&ci);
870 L_RSHIFT(&ci);
871 tmp = t23;
872 L_RSHIFT(&tmp);
873 L_ADD(&ci, &tmp);
863
864 /*
865 * Calculate di in t23 in full precision, then truncate
866 * to an s_fp.
867 */
868 L_SUB(&t23, &t10);
869 di = LFPTOFP(&t23);
870

--- 139 unchanged lines hidden (view full) ---

1010 * are most likely to succeed. We run through the list
1011 * doing the sanity checks and trying to insert anyone who
1012 * looks okay. We are at all times aware that we should
1013 * only keep samples from the top two strata and we only need
1014 * NTP_MAXLIST of them.
1015 */
1016 nlist = 0; /* none yet */
1017 for (server = sys_servers; server != NULL; server = server->next_server) {
874
875 /*
876 * Calculate di in t23 in full precision, then truncate
877 * to an s_fp.
878 */
879 L_SUB(&t23, &t10);
880 di = LFPTOFP(&t23);
881

--- 139 unchanged lines hidden (view full) ---

1021 * are most likely to succeed. We run through the list
1022 * doing the sanity checks and trying to insert anyone who
1023 * looks okay. We are at all times aware that we should
1024 * only keep samples from the top two strata and we only need
1025 * NTP_MAXLIST of them.
1026 */
1027 nlist = 0; /* none yet */
1028 for (server = sys_servers; server != NULL; server = server->next_server) {
1018 if (server->delay == 0)
1019 continue; /* no data */
1020 if (server->stratum > NTP_INFIN)
1021 continue; /* stratum no good */
1029 if (server->delay == 0) {
1030 if (debug)
1031 printf("%s: Server dropped: no data\n", ntoa(&server->srcadr));
1032 continue; /* no data */
1033 }
1034 if (server->stratum > NTP_INFIN) {
1035 if (debug)
1036 printf("%s: Server dropped: strata too high\n", ntoa(&server->srcadr));
1037 continue; /* stratum no good */
1038 }
1022 if (server->delay > NTP_MAXWGT) {
1039 if (server->delay > NTP_MAXWGT) {
1023 continue; /* too far away */
1040 if (debug)
1041 printf("%s: Server dropped: server too far away\n",
1042 ntoa(&server->srcadr));
1043 continue; /* too far away */
1024 }
1044 }
1025 if (server->leap == LEAP_NOTINSYNC)
1026 continue; /* he's in trouble */
1045 if (server->leap == LEAP_NOTINSYNC) {
1046 if (debug)
1047 printf("%s: Server dropped: Leap not in sync\n", ntoa(&server->srcadr));
1048 continue; /* he's in trouble */
1049 }
1027 if (!L_ISHIS(&server->org, &server->reftime)) {
1050 if (!L_ISHIS(&server->org, &server->reftime)) {
1028 continue; /* very broken host */
1051 if (debug)
1052 printf("%s: Server dropped: server is very broken\n",
1053 ntoa(&server->srcadr));
1054 continue; /* very broken host */
1029 }
1030 if ((server->org.l_ui - server->reftime.l_ui)
1055 }
1056 if ((server->org.l_ui - server->reftime.l_ui)
1031 >= NTP_MAXAGE) {
1057 >= NTP_MAXAGE) {
1058 if (debug)
1059 printf("%s: Server dropped: Server has gone too long without sync\n",
1060 ntoa(&server->srcadr));
1032 continue; /* too long without sync */
1033 }
1034 if (server->trust != 0) {
1061 continue; /* too long without sync */
1062 }
1063 if (server->trust != 0) {
1064 if (debug)
1065 printf("%s: Server dropped: Server is untrusted\n",
1066 ntoa(&server->srcadr));
1035 continue;
1036 }
1037
1038 /*
1039 * This one seems sane. Find where he belongs
1040 * on the list.
1041 */
1042 d = server->dispersion + server->dispersion;

--- 1013 unchanged lines hidden ---
1067 continue;
1068 }
1069
1070 /*
1071 * This one seems sane. Find where he belongs
1072 * on the list.
1073 */
1074 d = server->dispersion + server->dispersion;

--- 1013 unchanged lines hidden ---