+* Allow ntpq &1 associd use without preceding association-fetching.
(4.2.7p101) 2010/12/22 Released by Harlan Stenn <stenn@ntp.org>
* from 4.2.6p3-RC12: Upgrade to libopts 34.0.9 from AutoGen 5.11.6pre7.
* from 4.2.6p3-RC12: Relax minimum Automake version to 1.10 with updated
+ ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */
+extern const char *months[12];
+extern const char *daynames[7];
extern void caljulian (u_int32, struct calendar *);
extern u_int32 caltontp (const struct calendar *);
int32
ntpcal_edate_to_eradays(
int32 years ,
- int32 months ,
+ int32 mons ,
int32 mdays )
{
ntpcal_split tmp;
int32 res;
- if (months) {
- tmp = ntpcal_days_in_months(months);
+ if (mons) {
+ tmp = ntpcal_days_in_months(mons);
res = ntpcal_days_in_years(years + tmp.hi) + tmp.lo;
} else
res = ntpcal_days_in_years(years);
int32
ntpcal_edate_to_yeardays(
int32 years ,
- int32 months,
+ int32 mons,
int32 mdays )
{
ntpcal_split tmp;
- if (0 <= months && months < 12) {
+ if (0 <= mons && mons < 12) {
years += 1;
- mdays += real_month_table[is_leapyear(years)][months];
+ mdays += real_month_table[is_leapyear(years)][mons];
} else {
- tmp = ntpcal_days_in_months(months);
+ tmp = ntpcal_days_in_months(mons);
mdays += tmp.lo
+ ntpcal_days_in_years(years + tmp.hi)
- ntpcal_days_in_years(years);
static char *common_prettydate(l_fp *, int);
-const char *months[] = {
+const char * months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
-static const char *days[] = {
+const char * daynames[7] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
ntpcal_time_to_date(&jd, &sec);
snprintf(bp, LIB_BUFLENGTH, pfmt[local != 0],
(u_long)ts->l_ui, (u_long)ts->l_uf,
- days[jd.weekday], months[jd.month-1],
+ daynames[jd.weekday], months[jd.month-1],
jd.monthday, jd.year, jd.hour,
jd.minute, jd.second, msec);
} else
snprintf(bp, LIB_BUFLENGTH, pfmt[0],
(u_long)ts->l_ui, (u_long)ts->l_uf,
- days[tm->tm_wday], months[tm->tm_mon],
+ daynames[tm->tm_wday], months[tm->tm_mon],
tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour,
tm->tm_min, tm->tm_sec, msec);
return bp;
#include "ntp_io.h"
#include "ntp_unixtime.h"
#include "ntp_refclock.h"
+#include "ntp_calendar.h"
#include "ntp_stdlib.h"
#include <stdio.h>
* Gj in UT as of 3.0, 1999 , Bj as of 1.3
*/
-static char *Month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jly",
- "Aug", "Sep", "Oct", "Nov", "Dec" };
-
#define DEVICE1 "/dev/oncore.serial.%d" /* name of serial device */
#define DEVICE2 "/dev/oncore.pps.%d" /* name of pps device */
struct refclockproc *pp;
int fd1, fd2;
char device1[STRING_LEN], device2[STRING_LEN], Msg[160];
+#ifndef SYS_WINNT
struct stat stat1, stat2;
+#endif
/* create instance structure for this unit */
snprintf(Msg, sizeof(Msg),
"Date/Time set to: %d%s%d %2d:%02d:%02d GMT (GMT offset is %s%02d:%02d)",
- d, Month[mo-1], y, h, m, s, gmts, gmth, gmtm);
+ d, months[mo-1], y, h, m, s, gmts, gmth, gmtm);
oncore_log(instance, LOG_NOTICE, Msg);
}
if (dt) {
snprintf(Msg, sizeof(Msg),
"Leap second (%d) scheduled for %d%s%d at %d:%d:%d",
- dt, buf[9], Month[buf[8] - 1],
+ dt, buf[9], months[buf[8] - 1],
256 * buf[6] + buf[7], buf[15], buf[16],
buf[17]);
oncore_log(instance, LOG_NOTICE, Msg);
char *argv[]
)
{
- extern int ntp_optind;
delay_time.l_ui = 0;
delay_time.l_uf = DEFDELAY;
interactive = 1;
}
-#if 0
- ai_fam_templ = ai_fam_default;
- while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF)
- switch (c) {
- case '4':
- ai_fam_templ = AF_INET;
- break;
- case '6':
- ai_fam_templ = AF_INET6;
- break;
- case 'c':
- ADDCMD(ntp_optarg);
- break;
- case 'd':
- ++debug;
- break;
- case 'i':
- interactive = 1;
- break;
- case 'l':
- ADDCMD("listpeers");
- break;
- case 'n':
- showhostnames = 0;
- break;
- case 'p':
- ADDCMD("peers");
- break;
- case 's':
- ADDCMD("dmpeers");
- break;
- default:
- errflg++;
- break;
- }
-
- if (errflg) {
- (void) fprintf(stderr,
- "usage: %s [-46dilnps] [-c cmd] host ...\n",
- progname);
- exit(2);
- }
-
- if (ntp_optind == argc) {
- ADDHOST(DEFHOST);
- } else {
- for (; ntp_optind < argc; ntp_optind++)
- ADDHOST(argv[ntp_optind]);
- }
-
- if (numcmds == 0 && interactive == 0
- && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
- interactive = 1;
- }
-#endif
-
#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
if (interactive)
(void) signal_no_reset(SIGINT, abortcmd);
#include "libntpq.h"
-/* the following functions are required internally by a number of libntpq functions
- * and since they are defined as static in ntpq-subs.c, they need to be exported here
- */
-
int ntpq_dogetassoc(void)
{
- if ( dogetassoc(NULL))
- {
+ if (dogetassoc(NULL))
return numassoc;
- } else {
- return 0;
- }
+ else
+ return 0;
}
+/* the following functions are required internally by a number of libntpq functions
+ * and since they are defined as static in ntpq-subs.c, they need to be exported here
+ */
+
char ntpq_decodeaddrtype(sockaddr_u *sock)
{
return decodeaddrtype(sock);
extern char * chosts[];
extern char currenthost[];
-extern int numhosts;
int maxhostlen;
/*
static int findassidrange (u_int32, u_int32, int *, int *);
static void mreadlist (struct parse *, FILE *);
static void mreadvar (struct parse *, FILE *);
-static int dogetassoc (FILE *);
static void printassoc (int, FILE *);
static void associations (struct parse *, FILE *);
static void lassociations (struct parse *, FILE *);
extern int rawmode;
extern struct servent *server_entry;
extern struct association assoc_cache[];
-extern int numassoc;
extern u_char pktversion;
extern struct ctl_var peer_var[];
{
associd_t assids[2];
int ind[COUNTOF(assids)];
- int i;
+ u_int i;
size_t a;
assids[0] = checkassocid(assid1);
/*
* dogetassoc - query the host for its list of associations
*/
-static int
+int
dogetassoc(
FILE *fp
)
if (dsize == 0) {
if (numhosts > 1)
- (void) fprintf(fp, "server=%s ", currenthost);
- (void) fprintf(fp, "No association ID's returned\n");
+ fprintf(fp, "server=%s ", currenthost);
+ fprintf(fp, "No association ID's returned\n");
return 0;
}
)
{
register char *bp;
- int i;
+ u_int i;
u_char statval;
int event;
u_long event_count;
int af
)
{
- register int i;
+ u_int i;
char fullname[LENHOSTNAME];
sockaddr_u netnum;
FILE *fp
)
{
- char *cfgcmd;
+ const char *cfgcmd;
u_short rstatus;
int rsize;
const char *rdata;
char parms_buf[128];
char buf[24];
char *parms;
- char *arg;
+ const char *arg;
size_t cb;
mru **sorted;
mru **ppentry;
static int sendpkt (void *, size_t);
static int getresponse (int, int, u_short *, int *, const char **, int);
-static int sendrequest (int, associd_t, int, int, char *);
+static int sendrequest (int, associd_t, int, int, const char *);
static char * tstflags (u_long);
#ifndef BUILD_AS_LIB
static void getcmds (void);
#endif /* SYS_WINNT */
static void docmd (const char *);
static void tokenize (const char *, char **, int *);
-static int getarg (char *, int, arg_v *);
+static int getarg (const char *, int, arg_v *);
#endif /* BUILD_AS_LIB */
-static int findcmd (char *, struct xcmd *, struct xcmd *, struct xcmd **);
+static int findcmd (const char *, struct xcmd *,
+ struct xcmd *, struct xcmd **);
static int rtdatetolfp (char *, l_fp *);
static int decodearr (char *, int *, l_fp *);
static void help (struct parse *, FILE *);
* Holds association data for use with the &n operator.
*/
struct association assoc_cache[MAXASSOC];
-int numassoc = 0; /* number of cached associations */
+u_int numassoc = 0; /* number of cached associations */
/*
* For commands typed on the command line (with the -c option)
/*
* When multiple hosts are specified.
*/
-int numhosts = 0;
+u_int numhosts;
const char *chosts[MAXHOSTS];
#define ADDHOST(cp) if (numhosts < MAXHOSTS) chosts[numhosts++] = (cp)
char *argv[]
)
{
- extern int ntp_optind;
+ u_int ihost;
+ int icmd;
+
#ifdef SYS_VXWORKS
clear_globals();
old_rv = HAVE_OPT(OLD_RV);
-#if 0
- while ((c = ntp_getopt(argc, argv, "46c:dinp")) != EOF)
- switch (c) {
- case '4':
- ai_fam_templ = AF_INET;
- break;
- case '6':
- ai_fam_templ = AF_INET6;
- break;
- case 'c':
- ADDCMD(ntp_optarg);
- break;
- case 'd':
- ++debug;
- break;
- case 'i':
- interactive = 1;
- break;
- case 'n':
- showhostnames = 0;
- break;
- case 'p':
- ADDCMD("peers");
- break;
- default:
- errflg++;
- break;
- }
- if (errflg) {
- (void) fprintf(stderr,
- "usage: %s [-46dinp] [-c cmd] host ...\n",
- progname);
- exit(2);
- }
-#endif
- NTP_INSIST(ntp_optind <= argc);
- if (ntp_optind == argc) {
+ if (0 == argc) {
ADDHOST(DEFHOST);
} else {
- for (; ntp_optind < argc; ntp_optind++)
- ADDHOST(argv[ntp_optind]);
+ for (ihost = 0; ihost < (u_int)argc; ihost++)
+ ADDHOST(argv[ihost]);
}
if (numcmds == 0 && interactive == 0
(void) openhost(chosts[0]);
getcmds();
} else {
- int ihost;
- int icmd;
-
for (ihost = 0; ihost < numhosts; ihost++) {
if (openhost(chosts[ihost]))
for (icmd = 0; icmd < numcmds; icmd++)
associd_t associd,
int auth,
int qsize,
- char *qdata
+ const char *qdata
)
{
struct ntp_control qpkt;
associd_t associd,
int auth,
int qsize,
- char *qdata,
+ const char *qdata,
u_short *rstatus,
int *rsize,
const char **rdata
associd_t associd,
int auth,
int qsize,
- char *qdata,
+ const char *qdata,
u_short *rstatus,
int *rsize,
const char **rdata,
*/
static int
getarg(
- char *str,
+ const char *str,
int code,
arg_v *argp
)
{
- int isneg;
- char *cp, *np;
- static const char *digits = "0123456789";
+ u_long ul;
switch (code & ~OPT) {
- case NTP_STR:
+ case NTP_STR:
argp->string = str;
break;
- case NTP_ADD:
- if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) {
+
+ case NTP_ADD:
+ if (!getnetnum(str, &argp->netnum, NULL, 0))
return 0;
- }
break;
- case NTP_INT:
- case NTP_UINT:
- isneg = 0;
- np = str;
- if (*np == '&') {
- np++;
- isneg = atoi(np);
- if (isneg <= 0) {
- (void) fprintf(stderr,
- "***Association value `%s' invalid/undecodable\n", str);
+
+ case NTP_UINT:
+ if ('&' == str[0]) {
+ if (!atouint(&str[1], &ul)) {
+ fprintf(stderr,
+ "***Association value `%s' invalid/undecodable\n",
+ str);
return 0;
}
- if (isneg > numassoc) {
- if (numassoc == 0) {
- (void) fprintf(stderr,
- "***Association for `%s' unknown (max &%d)\n",
- str, numassoc);
- return 0;
- } else {
- isneg = numassoc;
- }
+ if (0 == numassoc)
+ dogetassoc(stdout);
+ if (ul > numassoc) {
+ fprintf(stderr,
+ "***Association for `%s' unknown (max &%d)\n",
+ str, numassoc);
+ return 0;
}
- argp->uval = assoc_cache[isneg-1].assid;
+ argp->uval = assoc_cache[ul - 1].assid;
break;
}
-
- if (*np == '-') {
- np++;
- isneg = 1;
+ if (!atouint(str, &argp->uval)) {
+ fprintf(stderr, "***Illegal unsigned value %s\n",
+ str);
+ return 0;
}
+ break;
- argp->uval = 0;
- do {
- cp = strchr(digits, *np);
- if (cp == NULL) {
- (void) fprintf(stderr,
- "***Illegal integer value %s\n", str);
- return 0;
- }
- argp->uval *= 10;
- argp->uval += (cp - digits);
- } while (*(++np) != '\0');
-
- if (isneg) {
- if ((code & ~OPT) == NTP_UINT) {
- (void) fprintf(stderr,
- "***Value %s should be unsigned\n", str);
- return 0;
- }
- argp->ival = -argp->ival;
+ case NTP_INT:
+ if (!atoint(str, &argp->ival)) {
+ fprintf(stderr, "***Illegal integer value %s\n",
+ str);
+ return 0;
}
break;
- case IP_VERSION:
- if (!strcmp("-6", str))
- argp->ival = 6 ;
- else if (!strcmp("-4", str))
- argp->ival = 4 ;
- else {
- (void) fprintf(stderr,
- "***Version must be either 4 or 6\n");
+
+ case IP_VERSION:
+ if (!strcmp("-6", str)) {
+ argp->ival = 6;
+ } else if (!strcmp("-4", str)) {
+ argp->ival = 4;
+ } else {
+ fprintf(stderr, "***Version must be either 4 or 6\n");
return 0;
}
break;
*/
static int
findcmd(
- register char *str,
- struct xcmd *clist1,
- struct xcmd *clist2,
- struct xcmd **cmd
+ const char * str,
+ struct xcmd * clist1,
+ struct xcmd * clist2,
+ struct xcmd ** cmd
)
{
- register struct xcmd *cl;
- register int clen;
+ struct xcmd *cl;
+ int clen;
int nmatch;
struct xcmd *nearmatch = NULL;
struct xcmd *clist;
register int i;
struct calendar cal;
char buf[4];
- static const char *months[12] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
cal.yearday = 0;
)
{
struct xcmd *xcp = NULL; /* quiet warning */
- char *cmd;
+ const char *cmd;
const char *list[100];
size_t word, words;
size_t row, rows;
FILE *fp
)
{
- char *pass;
+ const char *pass;
if (info_auth_keyid == 0) {
info_auth_keyid = getkeyid("Keyid: ");
return;
}
}
- authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
+ authusekey(info_auth_keyid, info_auth_keytype,
+ (const u_char *)pass);
authtrust(info_auth_keyid, 1);
}
* Arguments are returned in a union
*/
typedef union {
- char *string;
+ const char *string;
long ival;
u_long uval;
sockaddr_u netnum;
extern int interactive; /* are we prompting? */
extern int old_rv; /* use old rv behavior? --old-rv */
+extern u_int numhosts;
+extern u_int numassoc;
extern void asciize (int, char *, FILE *);
extern int getnetnum (const char *, sockaddr_u *, char *, int);
extern void sortassoc (void);
extern void show_error_msg (int, associd_t);
-extern int doquery (int, associd_t, int, int, char *,
+extern int dogetassoc (FILE *);
+extern int doquery (int, associd_t, int, int, const char *,
u_short *, int *, const char **);
-extern int doqueryex (int, associd_t, int, int, char *,
+extern int doqueryex (int, associd_t, int, int, const char *,
u_short *, int *, const char **, int);
extern char * nntohost (sockaddr_u *);
extern int decodets (char *, l_fp *);