diff options
| author | christos <christos@NetBSD.org> | 1998-03-06 18:17:13 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 1998-03-06 18:17:13 +0000 |
| commit | 50e0331ef5b2b92b6cf95cb1b8d72ceb689e017f (patch) | |
| tree | ba11a87ed0efcdfc69bed151dda9c4f20bd17c5c /lib | |
| parent | a5e6bce521ae3e0d81a27a4438b098633a54b0f7 (diff) | |
Resolve conflicts.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libntp/atolfp.c | 4 | ||||
| -rw-r--r-- | lib/libntp/auth12crypt.c | 12 | ||||
| -rw-r--r-- | lib/libntp/authdecrypt.c | 10 | ||||
| -rw-r--r-- | lib/libntp/authencrypt.c | 10 | ||||
| -rw-r--r-- | lib/libntp/authkeys.c | 50 | ||||
| -rw-r--r-- | lib/libntp/authreadkeys.c | 4 | ||||
| -rw-r--r-- | lib/libntp/authusekey.c | 6 | ||||
| -rw-r--r-- | lib/libntp/buftvtots.c | 4 | ||||
| -rw-r--r-- | lib/libntp/caljulian.c | 171 | ||||
| -rw-r--r-- | lib/libntp/caltontp.c | 107 | ||||
| -rw-r--r-- | lib/libntp/clocktypes.c | 6 | ||||
| -rw-r--r-- | lib/libntp/findconfig.c | 3 | ||||
| -rw-r--r-- | lib/libntp/getopt.c | 6 | ||||
| -rw-r--r-- | lib/libntp/hextolfp.c | 4 | ||||
| -rw-r--r-- | lib/libntp/humandate.c | 10 | ||||
| -rw-r--r-- | lib/libntp/machines.c | 125 | ||||
| -rw-r--r-- | lib/libntp/modetoa.c | 6 | ||||
| -rw-r--r-- | lib/libntp/msyslog.c | 27 | ||||
| -rw-r--r-- | lib/libntp/prettydate.c | 6 | ||||
| -rw-r--r-- | lib/libntp/statestr.c | 8 | ||||
| -rw-r--r-- | lib/libntp/systime.c | 11 |
21 files changed, 332 insertions, 258 deletions
diff --git a/lib/libntp/atolfp.c b/lib/libntp/atolfp.c index 218e1c7c055..9eedf47f8e9 100644 --- a/lib/libntp/atolfp.c +++ b/lib/libntp/atolfp.c @@ -1,4 +1,4 @@ -/* $NetBSD: atolfp.c,v 1.2 1998/01/09 03:15:52 perry Exp $ */ +/* $NetBSD: atolfp.c,v 1.3 1998/03/06 18:17:13 christos Exp $ */ /* * atolfp - convert an ascii string to an l_fp number @@ -37,7 +37,7 @@ atolfp(str, lfp) char *ind; int ndec; int isneg; - static char *digits = "0123456789"; + static const char *digits = "0123456789"; isneg = 0; dec_i = dec_f = 0; diff --git a/lib/libntp/auth12crypt.c b/lib/libntp/auth12crypt.c index 8528746c8d8..cee05047abe 100644 --- a/lib/libntp/auth12crypt.c +++ b/lib/libntp/auth12crypt.c @@ -1,4 +1,4 @@ -/* $NetBSD: auth12crypt.c,v 1.2 1998/01/09 03:15:53 perry Exp $ */ +/* $NetBSD: auth12crypt.c,v 1.3 1998/03/06 18:17:13 christos Exp $ */ /* * auth12crypt.c - routines to support two stage NTP encryption @@ -23,9 +23,9 @@ /* * Imported from the key data base module */ -extern u_long cache_keyid; /* cached key ID */ -extern u_long DEScache_ekeys[]; /* cached decryption keys */ -extern u_long DESzeroekeys[]; /* zero key decryption keys */ +extern u_int32 cache_keyid; /* cached key ID */ +extern u_int32 DEScache_ekeys[]; /* cached decryption keys */ +extern u_int32 DESzeroekeys[]; /* zero key decryption keys */ /* * Stat counters, from the database module @@ -40,7 +40,7 @@ extern u_int32 authnokey; */ void DESauth1crypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* length of all encrypted data */ { @@ -93,7 +93,7 @@ DESauth1crypt(keyno, pkt, length) */ int DESauth2crypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* total length of encrypted area */ { diff --git a/lib/libntp/authdecrypt.c b/lib/libntp/authdecrypt.c index e04934ab371..0558b0a82e6 100644 --- a/lib/libntp/authdecrypt.c +++ b/lib/libntp/authdecrypt.c @@ -1,4 +1,4 @@ -/* $NetBSD: authdecrypt.c,v 1.2 1998/01/09 03:15:54 perry Exp $ */ +/* $NetBSD: authdecrypt.c,v 1.3 1998/03/06 18:17:13 christos Exp $ */ /* * authdecrypt - routine to decrypt a packet to see if this guy knows our key. @@ -21,9 +21,9 @@ /* * Imported from the key data base module */ -extern u_long cache_keyid; /* cached key ID */ -extern u_long DEScache_dkeys[]; /* cached decryption keys */ -extern u_long DESzerodkeys[]; /* zero key decryption keys */ +extern u_int32 cache_keyid; /* cached key ID */ +extern u_int32 DEScache_dkeys[]; /* cached decryption keys */ +extern u_int32 DESzerodkeys[]; /* zero key decryption keys */ /* * Stat counters, imported from data base module @@ -33,7 +33,7 @@ extern u_int32 authkeyuncached; int DESauthdecrypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; const u_int32 *pkt; int length; /* length of variable data in octets */ { diff --git a/lib/libntp/authencrypt.c b/lib/libntp/authencrypt.c index 72b2405d44e..f3bf23ca288 100644 --- a/lib/libntp/authencrypt.c +++ b/lib/libntp/authencrypt.c @@ -1,4 +1,4 @@ -/* $NetBSD: authencrypt.c,v 1.2 1998/01/09 03:15:55 perry Exp $ */ +/* $NetBSD: authencrypt.c,v 1.3 1998/03/06 18:17:13 christos Exp $ */ /* * authencrypt - compute and encrypt the mac field in an NTP packet @@ -21,9 +21,9 @@ /* * Imported from the key data base module */ -extern u_long cache_keyid; /* cached key ID */ -extern u_long DEScache_ekeys[]; /* cached decryption keys */ -extern u_long DESzeroekeys[]; /* zero key decryption keys */ +extern u_int32 cache_keyid; /* cached key ID */ +extern u_int32 DEScache_ekeys[]; /* cached decryption keys */ +extern u_int32 DESzeroekeys[]; /* zero key decryption keys */ /* * Stat counters from the database module @@ -34,7 +34,7 @@ extern u_int32 authnokey; int DESauthencrypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* length of encrypted portion of packet */ { diff --git a/lib/libntp/authkeys.c b/lib/libntp/authkeys.c index 19e965d6d44..9f3e0f15048 100644 --- a/lib/libntp/authkeys.c +++ b/lib/libntp/authkeys.c @@ -1,4 +1,4 @@ -/* $NetBSD: authkeys.c,v 1.2 1998/01/09 03:15:56 perry Exp $ */ +/* $NetBSD: authkeys.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * authkeys.c - routines to manage the storage of authentication keys @@ -24,7 +24,7 @@ struct savekey { char MD5_key[32]; #endif } k; - u_long keyid; + u_int32 keyid; u_short flags; #ifdef MD5 int keylen; @@ -73,9 +73,9 @@ int authnumfreekeys; #ifdef DES /* - * Size of the key schedule (in u_longs for fast DES) + * Size of the key schedule (in u_int32s for fast DES) */ -#define KEY_SCHED_SIZE ((128+sizeof(u_long)-1)/sizeof(u_long)) +#define KEY_SCHED_SIZE ((128+sizeof(u_int32)-1)/sizeof(u_int32)) /* * The zero key, which we always have. Store the permutted key @@ -86,16 +86,16 @@ int authnumfreekeys; /* * fast DES code expects base address aligned to u_long */ -u_long DESzeroekeys[KEY_SCHED_SIZE]; -u_long DESzerodkeys[KEY_SCHED_SIZE]; -u_long DEScache_ekeys[KEY_SCHED_SIZE]; -u_long DEScache_dkeys[KEY_SCHED_SIZE]; +u_int32 DESzeroekeys[KEY_SCHED_SIZE]; +u_int32 DESzerodkeys[KEY_SCHED_SIZE]; +u_int32 DEScache_ekeys[KEY_SCHED_SIZE]; +u_int32 DEScache_dkeys[KEY_SCHED_SIZE]; #endif /* * The key cache. We cache the last key we looked at here. */ -u_long cache_keyid; +u_int32 cache_keyid; u_short cache_flags; #ifdef MD5 @@ -141,7 +141,7 @@ init_auth() */ struct savekey * auth_findkey(keyno) - u_long keyno; + u_int32 keyno; { register struct savekey *sk; @@ -160,7 +160,7 @@ auth_findkey(keyno) */ int auth_havekey(keyno) - u_long keyno; + u_int32 keyno; { register struct savekey *sk; @@ -190,7 +190,7 @@ auth_havekey(keyno) */ int authhavekey(keyno) - u_long keyno; + u_int32 keyno; { register struct savekey *sk; @@ -257,7 +257,7 @@ auth_moremem() */ void authtrust(keyno, trust) - u_long keyno; + u_int32 keyno; int trust; { register struct savekey *sk; @@ -326,7 +326,7 @@ authtrust(keyno, trust) */ int authistrusted(keyno) - u_long keyno; + u_int32 keyno; { register struct savekey *sk; @@ -355,7 +355,7 @@ authistrusted(keyno) */ void DESauth_setkey(keyno, key) - u_long keyno; + u_int32 keyno; const u_int32 *key; { register struct savekey *sk; @@ -404,7 +404,7 @@ DESauth_setkey(keyno, key) #ifdef MD5 void MD5auth_setkey(keyno, key) - u_long keyno; + u_int32 keyno; const u_int32 *key; { register struct savekey *sk; @@ -416,8 +416,8 @@ MD5auth_setkey(keyno, key) sk = key_hash[KEYHASH(keyno)]; while (sk != 0) { if (keyno == sk->keyid) { - strncpy(sk->k.MD5_key, (char *)key, sizeof(sk->k.MD5_key)); - if ((sk->keylen = strlen((char *)key)) > + strncpy(sk->k.MD5_key, (const char *)key, sizeof(sk->k.MD5_key)); + if ((sk->keylen = strlen((const char *)key)) > sizeof(sk->k.MD5_key)) sk->keylen = sizeof(sk->k.MD5_key); @@ -443,8 +443,8 @@ MD5auth_setkey(keyno, key) authfreekeys = sk->next; authnumfreekeys--; - strncpy(sk->k.MD5_key, (char *)key, sizeof(sk->k.MD5_key)); - if ((sk->keylen = strlen((char *)key)) > sizeof(sk->k.MD5_key)) + strncpy(sk->k.MD5_key, (const char *)key, sizeof(sk->k.MD5_key)); + if ((sk->keylen = strlen((const char *)key)) > sizeof(sk->k.MD5_key)) sk->keylen = sizeof(sk->k.MD5_key); sk->keyid = keyno; @@ -500,7 +500,7 @@ auth_delkeys() */ void auth1crypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* length of all encrypted data */ { @@ -529,11 +529,11 @@ auth1crypt(keyno, pkt, length) /* - * auth1crypt - support for two stage encryption, part 1. + * auth2crypt - support for two stage encryption, part 2. */ int auth2crypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* total length of encrypted area */ { @@ -560,7 +560,7 @@ auth2crypt(keyno, pkt, length) int authencrypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* length of encrypted portion of packet */ { @@ -589,7 +589,7 @@ authencrypt(keyno, pkt, length) int authdecrypt(keyno, pkt, length) - u_long keyno; + u_int32 keyno; u_int32 *pkt; int length; /* length of variable data in octets */ { diff --git a/lib/libntp/authreadkeys.c b/lib/libntp/authreadkeys.c index 276d11232dd..8e01e05403b 100644 --- a/lib/libntp/authreadkeys.c +++ b/lib/libntp/authreadkeys.c @@ -1,4 +1,4 @@ -/* $NetBSD: authreadkeys.c,v 1.2 1998/01/09 03:15:58 perry Exp $ */ +/* $NetBSD: authreadkeys.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * authreadkeys.c - routines to support the reading of the key file @@ -85,7 +85,7 @@ authreadkeys(file) FILE *fp; char *line; char *token; - u_long keyno; + u_int32 keyno; int keytype; char buf[512]; /* lots of room for line? */ #if !defined(VMS) /* wjm - what are these lines doing here? */ diff --git a/lib/libntp/authusekey.c b/lib/libntp/authusekey.c index b868e939ac2..501a49ad8fb 100644 --- a/lib/libntp/authusekey.c +++ b/lib/libntp/authusekey.c @@ -1,4 +1,4 @@ -/* $NetBSD: authusekey.c,v 1.2 1998/01/09 03:15:59 perry Exp $ */ +/* $NetBSD: authusekey.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * authusekey - decode a key from ascii and use it @@ -32,7 +32,7 @@ int authusekey(keyno, keytype, str) - u_long keyno; + u_int32 keyno; int keytype; const char *str; { @@ -41,7 +41,7 @@ authusekey(keyno, keytype, str) u_char keybytes[8]; char *xdigit; int i; - static char *hex = "0123456789abcdef"; + static const char *hex = "0123456789abcdef"; #endif const char *cp; int len; diff --git a/lib/libntp/buftvtots.c b/lib/libntp/buftvtots.c index ca59ee193fd..5ccb318b666 100644 --- a/lib/libntp/buftvtots.c +++ b/lib/libntp/buftvtots.c @@ -1,4 +1,4 @@ -/* $NetBSD: buftvtots.c,v 1.2 1998/01/09 03:16:00 perry Exp $ */ +/* $NetBSD: buftvtots.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * buftvtots - pull a Unix-format (struct timeval) time stamp out of @@ -18,7 +18,7 @@ buftvtots(bufp, ts) register u_long usec; #ifdef XNTP_BIG_ENDIAN - bp = (u_char *)bufp; + bp = (const u_char *)bufp; sec = (u_long)*bp++ & 0xff; sec <<= 8; diff --git a/lib/libntp/caljulian.c b/lib/libntp/caljulian.c index e707928a5c0..d8f50528bb3 100644 --- a/lib/libntp/caljulian.c +++ b/lib/libntp/caljulian.c @@ -1,4 +1,4 @@ -/* $NetBSD: caljulian.c,v 1.2 1998/01/09 03:16:01 perry Exp $ */ +/* $NetBSD: caljulian.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * caljulian - determine the Julian date from an NTP time. @@ -10,98 +10,107 @@ #include "ntp_stdlib.h" /* - * calmonthtab - month start offsets from the beginning of a cycle. + * calmonthtab - days-in-the-month table */ -static u_short calmonthtab[12] = { - 0, /* March */ - MAR, /* April */ - (MAR+APR), /* May */ - (MAR+APR+MAY), /* June */ - (MAR+APR+MAY+JUN), /* July */ - (MAR+APR+MAY+JUN+JUL), /* August */ - (MAR+APR+MAY+JUN+JUL+AUG), /* September */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP), /* October */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT), /* November */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV), /* December */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC), /* January */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC+JAN), /* February */ -}; - -/* - * caldaytab - calendar year start day offsets - */ -static u_short caldaytab[YEARSPERCYCLE] = { - (DAYSPERYEAR - (JAN + FEB)), - ((DAYSPERYEAR * 2) - (JAN + FEB)), - ((DAYSPERYEAR * 3) - (JAN + FEB)), - ((DAYSPERYEAR * 4) - (JAN + FEB)), +static u_short calmonthtab[11] = { + JAN, + FEB, + MAR, + APR, + MAY, + JUN, + JUL, + AUG, + SEP, + OCT, + NOV }; void caljulian(ntptime, jt) - u_long ntptime; - register struct calendar *jt; + u_long ntptime; + register struct calendar *jt; { - register int i; - register u_long nt; - register u_short snt; - register int cyear; + u_long ntp_day; + u_long minutes; + /* + * Absolute, zero-adjusted Christian era day, starting from the + * mythical day 12/1/1 BC + */ + u_long acez_day; + + u_long d400; /* Days into a Gregorian cycle */ + u_long d100; /* Days into a normal century */ + u_long d4; /* Days into a 4-year cycle */ + u_long n400; /* # of Gregorian cycles */ + u_long n100; /* # of normal centuries */ + u_long n4; /* # of 4-year cycles */ + u_long n1; /* # of years into a leap year */ + /* cycle */ + /* + * Do the easy stuff first: take care of hh:mm:ss, ignoring leap + * seconds + */ + jt->second = ntptime % SECSPERMIN; + minutes = ntptime / SECSPERMIN; + jt->minute = minutes % MINSPERHR; + jt->hour = (minutes / MINSPERHR) % HRSPERDAY; + + /* + * Find the day past 1900/01/01 00:00 UTC + */ + ntp_day = ntptime / SECSPERDAY; + acez_day = DAY_NTP_STARTS + ntp_day - 1; + n400 = acez_day/GREGORIAN_CYCLE_DAYS; + d400 = acez_day%GREGORIAN_CYCLE_DAYS; + n100 = d400 / GREGORIAN_NORMAL_CENTURY_DAYS; + d100 = d400 % GREGORIAN_NORMAL_CENTURY_DAYS; + n4 = d100 / GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; + d4 = d100 % GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; + n1 = d4 / DAYSPERYEAR; + + /* + * Calculate the year and year-of-day + */ + jt->yearday = 1 + d4%DAYSPERYEAR; + jt->year = 400*n400 + 100*n100 + n4*4 + n1; + + if (n100 == 4 || n1 == 4) + { /* - * Find the start of the cycle this is in. + * If the cycle year ever comes out to 4, it must be December 31st + * of a leap year. */ - nt = ntptime; - if (nt >= MAR1988) { - cyear = CYCLE22; - nt -= MAR1988; - } else { - cyear = 0; - nt -= MAR1900; - } - while (nt >= SECSPERCYCLE) { - nt -= SECSPERCYCLE; - cyear++; - } - + jt->month = 12; + jt->monthday = 31; + jt->yearday = 366; + } + else + { /* - * Seconds, minutes and hours are too hard to do without - * divides, so we don't. + * Else, search forwards through the months to get the right month + * and date. */ - jt->second = (u_char) (nt % SECSPERMIN); - nt /= SECSPERMIN; /* nt in minutes */ - jt->minute = (u_char) (nt % MINSPERHR); - snt = (u_short) (nt / MINSPERHR); /* snt in hours */ - jt->hour = (u_char) (snt % HRSPERDAY); - snt /= HRSPERDAY; /* nt in days */ + int monthday; - /* - * snt is now the number of days into the cycle, from 0 to 1460. - */ - cyear <<= 2; - if (snt < caldaytab[0]) { - jt->yearday = snt + JAN + FEBLEAP + 1; /* first year is leap */ - } else { - for (i = 1; i < YEARSPERCYCLE; i++) - if (snt < caldaytab[i]) - break; - jt->yearday = snt - caldaytab[i-1] + 1; - cyear += i; - } - jt->year = cyear + 1900; + jt->year++; + monthday = jt->yearday; - /* - * One last task, to compute the month and day. Normalize snt to - * a day within a cycle year. - */ - while (snt >= DAYSPERYEAR) - snt -= DAYSPERYEAR; - for (i = 0; i < 11; i++) - if (snt < calmonthtab[i+1]) - break; + for (jt->month=0;jt->month<11; jt->month++) + { + int t; - if (i > 9) - jt->month = i - 9; /* January or February */ - else - jt->month = i + 3; /* March through December */ - jt->monthday = snt - calmonthtab[i] + 1; + t = monthday - calmonthtab[jt->month]; + if (jt->month == 1 && is_leapyear(jt->year)) + t--; + + if (t > 0) + monthday = t; + else + break; + } + jt->month++; + jt->monthday = monthday; + } } diff --git a/lib/libntp/caltontp.c b/lib/libntp/caltontp.c index 43d982e4fc5..948c738fefa 100644 --- a/lib/libntp/caltontp.c +++ b/lib/libntp/caltontp.c @@ -1,7 +1,7 @@ -/* $NetBSD: caltontp.c,v 1.2 1998/01/09 03:16:02 perry Exp $ */ +/* $NetBSD: caltontp.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* - * caltontp - convert a julian date to an NTP time + * caltontp - convert a date to an NTP time */ #include <sys/types.h> @@ -9,84 +9,35 @@ #include "ntp_calendar.h" #include "ntp_stdlib.h" -/* - * calmonthtab - month start offsets from the beginning of a cycle. - */ -static u_short calmonthtab[12] = { - 0, /* March */ - MAR, /* April */ - (MAR+APR), /* May */ - (MAR+APR+MAY), /* June */ - (MAR+APR+MAY+JUN), /* July */ - (MAR+APR+MAY+JUN+JUL), /* August */ - (MAR+APR+MAY+JUN+JUL+AUG), /* September */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP), /* October */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT), /* November */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV), /* December */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC), /* January */ - (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC+JAN), /* February */ -}; - u_long caltontp(jt) register const struct calendar *jt; { - register int cyear; - register int resyear; - register u_long nt; - register int yearday; - - /* - * Find the start of the cycle this is in. - */ - cyear = (int)(jt->year - 1900) >> 2; - resyear = (jt->year - 1900) - (cyear << 2); - yearday = 0; - if (resyear == 0) { - if (jt->yearday == 0) { - if (jt->month == 1 || jt->month == 2) { - cyear--; - resyear = 3; - } - } else { - if (jt->yearday <= (u_short)(JAN+FEBLEAP)) { - cyear--; - resyear = 3; - yearday = calmonthtab[10] + jt->yearday; - } else { - yearday = jt->yearday - (JAN+FEBLEAP); - } - } - } else { - if (jt->yearday == 0) { - if (jt->month == 1 || jt->month == 2) - resyear--; - } else { - if (jt->yearday <= (u_short)(JAN+FEB)) { - resyear--; - yearday = calmonthtab[10] + jt->yearday; - } else { - yearday = jt->yearday - (JAN+FEB); - } - } - } - - if (yearday == 0) { - if (jt->month >= 3) { - yearday = calmonthtab[jt->month - 3] + jt->monthday; - } else { - yearday = calmonthtab[jt->month + 9] + jt->monthday; - } - } - - nt = TIMESDPERC((u_long)cyear); - while (resyear-- > 0) - nt += DAYSPERYEAR; - nt += (u_long) (yearday - 1); - - nt = TIMES24(nt) + (u_long)jt->hour; - nt = TIMES60(nt) + (u_long)jt->minute; - nt = TIMES60(nt) + (u_long)jt->second; - - return nt + MAR1900; + u_long ace_days; /* absolute Christian Era days */ + u_long ntp_days; + int prior_years; + u_long ntp_time; + + /* + * First convert today's date to absolute days past 12/1/1 BC + */ + prior_years = jt->year-1; + ace_days = jt->yearday /* days this year */ + +(DAYSPERYEAR*prior_years) /* plus days in previous years */ + +(prior_years/4) /* plus prior years's leap days */ + -(prior_years/100) /* minus leapless century years */ + +(prior_years/400); /* plus leapful Gregorian yrs */ + + /* + * Subtract out 1/1/1900, the beginning of the NTP epoch + */ + ntp_days = ace_days - DAY_NTP_STARTS; + + /* + * Do the obvious: + */ + ntp_time = + ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute); + + return ntp_time; } diff --git a/lib/libntp/clocktypes.c b/lib/libntp/clocktypes.c index 5ebc314e794..06d6f39a61c 100644 --- a/lib/libntp/clocktypes.c +++ b/lib/libntp/clocktypes.c @@ -1,4 +1,4 @@ -/* $NetBSD: clocktypes.c,v 1.2 1998/01/09 03:16:05 perry Exp $ */ +/* $NetBSD: clocktypes.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ /* * Data for pretty printing clock types @@ -66,6 +66,10 @@ struct clktype clktypes[] = { "TRUETIME" }, { REFCLK_GPS_HP, "HP 58503A GPS Time & Frequency Receiver (26)", "GPS_HP" }, + { REFCLK_ARCRON_MSF, "ARCRON MSF (and DCF77) Receiver (27)", + "ARCRON_MSF" }, + { REFCLK_SHM, "Clock attached thru shared Memory (28)", + "SHM" }, { -1, "", "" } }; diff --git a/lib/libntp/findconfig.c b/lib/libntp/findconfig.c index 928e3c256bc..edbdee78d45 100644 --- a/lib/libntp/findconfig.c +++ b/lib/libntp/findconfig.c @@ -1,4 +1,4 @@ -/* $NetBSD: findconfig.c,v 1.2 1998/01/09 03:16:09 perry Exp $ */ +/* $NetBSD: findconfig.c,v 1.3 1998/03/06 18:17:14 christos Exp $ */ #ifdef HAVE_CONFIG_H @@ -11,6 +11,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/utsname.h> +#include <unistd.h> char * FindConfig(base) diff --git a/lib/libntp/getopt.c b/lib/libntp/getopt.c index 52b07cfae12..5cadce62093 100644 --- a/lib/libntp/getopt.c +++ b/lib/libntp/getopt.c @@ -1,4 +1,4 @@ -/* $NetBSD: getopt.c,v 1.4 1998/01/09 03:16:12 perry Exp $ */ +/* $NetBSD: getopt.c,v 1.5 1998/03/06 18:17:15 christos Exp $ */ /* * getopt - get option letter from argv @@ -30,9 +30,7 @@ int ntp_opterr = 1; /* for compatibility, should error be printed? */ int ntp_optopt; /* for compatibility, option character checked */ static char *scan = NULL; /* Private scan pointer. */ -static char *prog = "amnesia"; - -static int badopt __P((char *, int)); +static const char *prog = "amnesia"; /* * Print message about a bad option. diff --git a/lib/libntp/hextolfp.c b/lib/libntp/hextolfp.c index 5f52304b69b..c98b2f94029 100644 --- a/lib/libntp/hextolfp.c +++ b/lib/libntp/hextolfp.c @@ -1,4 +1,4 @@ -/* $NetBSD: hextolfp.c,v 1.2 1998/01/09 03:16:14 perry Exp $ */ +/* $NetBSD: hextolfp.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* * hextolfp - convert an ascii hex string to an l_fp number @@ -20,7 +20,7 @@ hextolfp(str, lfp) register u_long dec_i; register u_long dec_f; char *ind = NULL; - static char *digits = "0123456789abcdefABCDEF"; + static const char *digits = "0123456789abcdefABCDEF"; dec_i = dec_f = 0; cp = str; diff --git a/lib/libntp/humandate.c b/lib/libntp/humandate.c index 549edcbd6be..7a766951ae7 100644 --- a/lib/libntp/humandate.c +++ b/lib/libntp/humandate.c @@ -1,10 +1,10 @@ -/* $NetBSD: humandate.c,v 1.3 1998/01/09 03:16:15 perry Exp $ */ +/* $NetBSD: humandate.c,v 1.4 1998/03/06 18:17:15 christos Exp $ */ /* * humandate - convert an NTP (or the current) time to something readable */ #include <stdio.h> - +#include "time.h" #include "ntp_fp.h" #include "ntp_unixtime.h" /* includes <sys/time.h> */ #include "lib_strbuf.h" @@ -14,13 +14,11 @@ #include <time.h> #endif -char *humanlogtime __P((void)); - -static char *months[] = { +static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static char *days[] = { +static const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; diff --git a/lib/libntp/machines.c b/lib/libntp/machines.c index 649f13ac4ed..7f90ebafe6b 100644 --- a/lib/libntp/machines.c +++ b/lib/libntp/machines.c @@ -1,4 +1,4 @@ -/* $NetBSD: machines.c,v 1.2 1998/01/09 03:16:18 perry Exp $ */ +/* $NetBSD: machines.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* machines.c - provide special support for peculiar architectures * @@ -11,6 +11,92 @@ #ifndef SYS_WINNT +#ifdef SYS_VXWORKS +#include "taskLib.h" +#include "sysLib.h" +#include "time.h" +#include "ntp_syslog.h" + +/* some translations to the world of vxWorkings -casey */ +/* first some netdb type things */ +#include "ioLib.h" +#include <socket.h> +int h_errno; + +struct hostent *gethostbyname(char *name) + { + struct hostent *host1; + h_errno = 0; /* we are always successful!!! */ + host1 = (struct hostent *) malloc (sizeof(struct hostent)); + host1->h_name = name; + host1->h_addrtype = AF_INET; + host1->h_aliases = name; + host1->h_length = 4; + host1->h_addr_list[0] = (char *)hostGetByName (name); + host1->h_addr_list[1] = NULL; + return host1; + } + +struct hostent *gethostbyaddr(char *name, int size, int addr_type) + { + struct hostent *host1; + h_errno = 0; /* we are always successful!!! */ + host1 = (struct hostent *) malloc (sizeof(struct hostent)); + host1->h_name = name; + host1->h_addrtype = AF_INET; + host1->h_aliases = name; + host1->h_length = 4; + host1->h_addr_list = NULL; + return host1; + } + +struct servent *getservbyname (char *name, char *type) + { + struct servent *serv1; + serv1 = (struct servent *) malloc (sizeof(struct servent)); + serv1->s_name = "ntp"; /* official service name */ + serv1->s_aliases = NULL; /* alias list */ + serv1->s_port = 123; /* port # */ + serv1->s_proto = "udp"; /* protocol to use */ + return serv1; + } + +/* second + * vxworks thinks it has insomnia + * we have to sleep for number of seconds + */ + +#define CLKRATE sysClkRateGet() + +/* I am not sure how valid the granularity is - it is from G. Eger's port */ +#define CLK_GRANULARITY 1 /* Granularity of system clock in usec */ + /* Used to round down # usecs/tick */ + /* On a VCOM-100, PIT gets 8 MHz clk, */ + /* & it prescales by 32, thus 4 usec */ + /* on mv167, granularity is 1usec anyway*/ + /* To defeat rounding, set to 1 */ +#define USECS_PER_SEC 1000000L /* Microseconds per second */ +#define TICK (((USECS_PER_SEC / CLKRATE) / CLK_GRANULARITY) * CLK_GRANULARITY) + +/* emulate unix sleep + * casey + */ +void sleep(int seconds) + { + taskDelay(seconds*TICK); + } +/* emulate unix alarm + * that pauses and calls SIGALRM after the seconds are up... + * so ... taskDelay() fudged for seconds should amount to the same thing. + * casey + */ +void alarm (int seconds) + { + sleep(seconds); + } + +#endif /* SYS_VXWORKS */ + #ifdef SYS_PTX /* Does PTX still need this? */ /*#include <sys/types.h> */ #include <sys/procstats.h> @@ -29,10 +115,10 @@ gettimeofday(tvp) #endif /* SYS_PTX */ #ifdef HAVE_SETTIMEOFDAY -char *set_tod_using = "settimeofday"; +const char *set_tod_using = "settimeofday"; #else /* not HAVE_SETTIMEOFDAY */ # ifdef HAVE_CLOCK_SETTIME -char *set_tod_using = "clock_settime"; +const char *set_tod_using = "clock_settime"; /*#include <time.h> */ @@ -77,18 +163,32 @@ settimeofday(tvp, tzp) char * set_tod_using = "SetSystemTime"; -/* Windows NT versions of gettimeofday and settimeofday */ +/* Windows NT versions of gettimeofday and settimeofday + * + * ftime() has internal DayLightSavings related BUGS + * therefore switched to GetSystemTimeAsFileTime() + */ + +/* 100ns intervals between 1/1/1601 and 1/1/1970 as reported by + * SystemTimeToFileTime() + */ + +#define FILETIME_1970 0x019db1ded53e8000 +const BYTE DWLEN = sizeof(DWORD) * 8; /* number of bits in DWORD */ int gettimeofday(tv) - struct timeval *tv; + struct timeval *tv; { - struct _timeb timebuffer; - - _ftime(&timebuffer); - tv->tv_sec = (long) timebuffer.time; - tv->tv_usec = (long) (1000 * (timebuffer.millitm)); - return 0; + FILETIME ft; + __int64 msec; + + GetSystemTimeAsFileTime(&ft); /* 100ns intervals since 1/1/1601 */ + msec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime; + msec = (msec - FILETIME_1970) / 10; + tv->tv_sec = (long) (msec / 1000000); + tv->tv_usec = (long) (msec % 1000000); + return 0; } @@ -119,6 +219,9 @@ settimeofday(tv) } +#endif /* SYS_WINNT */ + +#if defined (SYS_WINNT) || defined (SYS_VXWORKS) /* getpass is used in ntpq.c and ntpdc.c */ char * diff --git a/lib/libntp/modetoa.c b/lib/libntp/modetoa.c index 578db827244..79746a6c695 100644 --- a/lib/libntp/modetoa.c +++ b/lib/libntp/modetoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: modetoa.c,v 1.2 1998/01/09 03:16:22 perry Exp $ */ +/* $NetBSD: modetoa.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* * modetoa - return an asciized mode @@ -8,12 +8,12 @@ #include "lib_strbuf.h" #include "ntp_stdlib.h" -char * +const char * modetoa(mode) int mode; { char *bp; - static char *modestrings[] = { + static const char *modestrings[] = { "unspec", "sym_active", "sym_passive", diff --git a/lib/libntp/msyslog.c b/lib/libntp/msyslog.c index 703d60932ec..12edd77c927 100644 --- a/lib/libntp/msyslog.c +++ b/lib/libntp/msyslog.c @@ -1,4 +1,4 @@ -/* $NetBSD: msyslog.c,v 1.2 1998/01/09 03:16:24 perry Exp $ */ +/* $NetBSD: msyslog.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* * msyslog - either send a message to the terminal or print it on @@ -41,6 +41,7 @@ #endif int syslogit = 1; + FILE *syslog_file = NULL; u_long ntp_syslogmask = ~ (u_long) 0; @@ -61,7 +62,7 @@ static WORD event_type[] = { extern char *progname; #if defined(__STDC__) -void msyslog(int level, char *fmt, ...) +void msyslog(int level, const char *fmt, ...) #else /*VARARGS*/ void msyslog(va_alist) @@ -70,15 +71,16 @@ void msyslog(va_alist) { #ifndef __STDC__ int level; - char *fmt; + const char *fmt; #endif va_list ap; char buf[1025], nfmt[256]; -#if !defined(VMS) && !defined(SYS_WINNT) +#if !defined(VMS) char xerr[50]; #endif register int c; - register char *n, *f, *prog; + register char *n, *prog; + register const char *f; #ifdef CHAR_SYS_ERRLIST extern int sys_nerr; extern char *sys_errlist[]; @@ -110,22 +112,23 @@ void msyslog(va_alist) *n++ = c; continue; } - -#if !defined(VMS) && !defined(SYS_WINNT) + err = 0; +#if !defined(VMS) && !defined(SYS_WINNT) && !defined (SYS_VXWORKS) if ((unsigned)olderrno > sys_nerr) sprintf((char *)(err = xerr), "error %d", olderrno); else err = sys_errlist[olderrno]; -#elif defined(VMS) +#elif defined(VMS) || defined (SYS_VXWORKS) err = strerror(olderrno); #else /* SYS_WINNT */ + err = xerr; FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ (LPTSTR) err, - 0, /* Indicates that func. allocates buffer */ + sizeof(xerr), NULL); #endif /* VMS && SYS_WINNT */ @@ -141,7 +144,7 @@ void msyslog(va_alist) *n = '\0'; vsprintf(buf, nfmt, ap); -#if !defined(VMS) +#if !defined(VMS) && !defined (SYS_VXWORKS) if (syslogit) #ifndef SYS_WINNT syslog(level, "%s", buf); @@ -173,7 +176,7 @@ void msyslog(va_alist) else { #else { -#endif /* VMS */ +#endif /* VMS && SYS_VXWORKS*/ extern char * humanlogtime P((void)); FILE *out_file = syslog_file ? syslog_file diff --git a/lib/libntp/prettydate.c b/lib/libntp/prettydate.c index 17e28483929..d80daa7218e 100644 --- a/lib/libntp/prettydate.c +++ b/lib/libntp/prettydate.c @@ -1,4 +1,4 @@ -/* $NetBSD: prettydate.c,v 1.2 1998/01/09 03:16:29 perry Exp $ */ +/* $NetBSD: prettydate.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* * prettydate - convert a time stamp to something readable @@ -22,11 +22,11 @@ prettydate(ts) struct tm *tm; time_t sec; u_long msec; - static char *months[] = { + static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - static char *days[] = { + static const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; diff --git a/lib/libntp/statestr.c b/lib/libntp/statestr.c index 9591e20f49e..c48e86daff6 100644 --- a/lib/libntp/statestr.c +++ b/lib/libntp/statestr.c @@ -1,4 +1,4 @@ -/* $NetBSD: statestr.c,v 1.2 1998/01/09 03:16:31 perry Exp $ */ +/* $NetBSD: statestr.c,v 1.3 1998/03/06 18:17:15 christos Exp $ */ /* * pretty printing of status information @@ -17,7 +17,7 @@ */ struct codestring { int code; - char *string; + const char *string; }; /* @@ -117,13 +117,13 @@ struct codestring peer_codes[] = { }; /* Forwards */ -static char *getcode P((int, struct codestring *)); +static const char *getcode P((int, struct codestring *)); static char *getevents P((int)); /* * getcode - return string corresponding to code */ -static char * +static const char * getcode(code, codetab) int code; struct codestring *codetab; diff --git a/lib/libntp/systime.c b/lib/libntp/systime.c index c46fa1e0b2b..61027155790 100644 --- a/lib/libntp/systime.c +++ b/lib/libntp/systime.c @@ -1,4 +1,4 @@ -/* $NetBSD: systime.c,v 1.2 1998/01/09 03:16:32 perry Exp $ */ +/* $NetBSD: systime.c,v 1.3 1998/03/06 18:17:16 christos Exp $ */ /* * systime -- routines to fiddle a UNIX clock. @@ -321,6 +321,7 @@ adj_systime(now) */ if ( #ifndef SYS_WINNT + /* casey - we need a posix type thang here */ (adjtime(&adjtv, &oadjtv) < 0) #else (!SetSystemTimeAdjustment(dwTimeAdjustment, FALSE)) @@ -438,7 +439,13 @@ step_systime_real(now) } #if DEBUG if (debug) { - GETTIMEOFDAY(&timetv, (struct timezone *) 0); +#ifdef HAVE_GETCLOCK + (void) getclock(TIMEOFDAY, &ts); + timetv.tv_sec = ts.tv_sec; + timetv.tv_usec = ts.tv_nsec / 1000; +#else /* not HAVE_GETCLOCK */ + (void) GETTIMEOFDAY(&timetv, (struct timezone *)0); +#endif /* not HAVE_GETCLOCK */ printf("step: new timetv = %s sec\n", utvtoa(&timetv)); } #endif |
