{ "delay", my_delay, { OPT|INT, NO, NO, NO },
{ "msec", "", "", "" },
"set the delay added to encryption time stamps" },
- { "host", host, { OPT|NTP_STR, NO, NO, NO },
- { "hostname", "", "", "" },
+ { "host", host, { OPT|NTP_STR, OPT|NTP_STR, NO, NO },
+ { "-4|-6", "hostname", "", "" },
"specify the host whose NTP server we talk to" },
{ "passwd", passwd, { OPT|NTP_STR, NO, NO, NO },
{ "", "", "", "" },
#define MAXCMDS 100 /* maximum commands on cmd line */
#define MAXHOSTS 200 /* maximum hosts on cmd line */
#define MAXLINE 512 /* maximum line length */
-#define MAXTOKENS (1+MAXARGS+2) /* maximum number of usable tokens */
+#define MAXTOKENS (1+1+MAXARGS+2) /* maximum number of usable tokens */
+ /* command + -4|-6 + MAXARGS + */
+ /* redirection */
/*
* Some variables used and manipulated locally
static char currenthost[LENHOSTNAME]; /* current host name */
static int showhostnames = 1; /* show host names by default */
+static int ai_fam_templ; /* address family */
static int sockfd; /* fd socket is opened on */
static int havehost = 0; /* set to 1 when host open */
int s_port = 0;
#endif
progname = argv[0];
- while ((c = ntp_getopt(argc, argv, "c:dilnps")) != EOF)
+ 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;
}
if (errflg) {
(void) fprintf(stderr,
- "usage: %s [-dilnps] [-c cmd] host ...\n",
+ "usage: %s [-46dilnps] [-c cmd] host ...\n",
progname);
exit(2);
}
memset((char *)&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_ADDRCONFIG|AI_CANONNAME;
+ hints.ai_family = ai_fam_templ;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_socktype = SOCK_DGRAM;
char *tokens[1+MAXARGS+2];
struct parse pcmd;
int ntok;
- static int i;
+ int i, ti;
+ int rval;
struct xcmd *xcmd;
+ ai_fam_templ = 0;
/*
* Tokenize the command line. If nothing on it, return.
*/
*/
pcmd.keyword = tokens[0];
pcmd.nargs = 0;
- for (i = 0; i < MAXARGS && xcmd->arg[i] != NO; i++) {
- if ((i+1) >= ntok) {
+ ti = 1;
+ for (i = 0; i < MAXARGS && xcmd->arg[i] != NO;) {
+ if ((i+ti) >= ntok) {
if (!(xcmd->arg[i] & OPT)) {
printusage(xcmd, stderr);
return;
}
break;
}
- if ((xcmd->arg[i] & OPT) && (*tokens[i+1] == '>'))
- break;
- if (!getarg(tokens[i+1], (int)xcmd->arg[i], &pcmd.argval[i]))
- return;
+ if ((xcmd->arg[i] & OPT) && (*tokens[i+ti] == '>'))
+ break;
+ rval = getarg(tokens[i+ti], (int)xcmd->arg[i], &pcmd.argval[i]);
+ if (rval == -1) {
+ ti++;
+ continue;
+ }
+ if (rval == 0)
+ return;
pcmd.nargs++;
+ i++;
}
- i++;
+ i += ti;
if (i < ntok && *tokens[i] == '>') {
char *fname;
}
- /*
+/*
* getarg - interpret an argument token
+ *
+ * return: 0 - failure
+ * 1 - success
+ * -1 - skip to next token
*/
static int
getarg(
argp->string = str;
break;
case ADD:
+ if (!strcmp("-6", str)) {
+ ai_fam_templ = AF_INET6;
+ return -1;
+ } else if (!strcmp("-4", str)) {
+ ai_fam_templ = AF_INET;
+ return -1;
+ }
if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) {
return 0;
}
argp->ival = -argp->ival;
}
break;
- case IP_VERSION:
- if (*str) {
- if (*str == '6') /* we want the v6 version*/
- argp->ival = 6 ;
- else if (*str == '4')
- argp->ival = 4 ;
- else{
- (void) fprintf(stderr, "***Version must be either 4 or 6\n");
- return 0;
- }
+ 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");
+ return 0;
}
break;
}
FILE *fp
)
{
- register int i;
+ int i, opt46;
+ opt46 = 0;
(void) fprintf(fp, "usage: %s", xcp->keyword);
for (i = 0; i < MAXARGS && xcp->arg[i] != NO; i++) {
+ if (opt46 == 0 && (xcp->arg[i] & ~OPT) == ADD) {
+ (void) fprintf(fp, " [ -4|-6 ]");
+ opt46 = 1;
+ }
if (xcp->arg[i] & OPT)
(void) fprintf(fp, " [ %s ]", xcp->desc[i]);
else
FILE *fp
)
{
+ int i;
+
if (pcmd->nargs == 0) {
if (havehost)
(void) fprintf(fp, "current host is %s\n", currenthost);
else
(void) fprintf(fp, "no current host\n");
- } else if (openhost(pcmd->argval[0].string)) {
+ return;
+ }
+
+ i = 0;
+ if (pcmd->nargs == 2) {
+ if (!strcmp("-4", pcmd->argval[i].string))
+ ai_fam_templ = AF_INET;
+ else if (!strcmp("-6", pcmd->argval[i].string))
+ ai_fam_templ = AF_INET6;
+ else {
+ if (havehost)
+ (void) fprintf(fp,
+ "current host remains %s\n", currenthost);
+ else
+ (void) fprintf(fp, "still no current host\n");
+ return;
+ }
+ i = 1;
+ }
+ if (openhost(pcmd->argval[i].string)) {
(void) fprintf(fp, "current host set to %s\n", currenthost);
} else {
if (havehost)
*/
struct xcmd opcmds[] = {
{ "listpeers", peerlist, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"display list of peers the server knows about [IP Version]" },
{ "peers", peers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"display peer summary information [IP Version]" },
{ "dmpeers", dmpeers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"display peer summary info the way Dave Mills likes it (IP Version)" },
{ "showpeer", showpeer, { ADD, OPT|ADD, OPT|ADD, OPT|ADD},
{ "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" },
{ "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." },
"clear a system flag (auth, bclient, monitor, pll, kernel, stats)" },
{ "reslist", reslist, {OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"display the server's restrict list" },
{ "restrict", new_restrict, { ADD, ADD, NTP_STR, OPT|NTP_STR },
{ "address", "mask",
{ "delay", auth_delay, { OPT|INT, NO, NO, NO },
{ "msec", "", "", "" },
"set the delay added to encryption time stamps" },
- { "host", host, { OPT|STR, NO, NO, NO },
- { "hostname", "", "", "" },
+ { "host", host, { OPT|STR, OPT|STR, NO, NO },
+ { "-4|-6", "hostname", "", "" },
"specify the host whose NTP server we talk to" },
{ "poll", ntp_poll, { OPT|UINT, OPT|STR, NO, NO },
{ "n", "verbose", "", "" },
struct sockaddr_in hostaddr = { 0 }; /* host address */
int showhostnames = 1; /* show host names by default */
+int ai_fam_templ; /* address family */
int sockfd; /* fd socket is opened on */
int havehost = 0; /* set to 1 when host open */
int s_port = 0;
delay_time.l_uf = DEFDELAY;
progname = argv[0];
- while ((c = ntp_getopt(argc, argv, "c:dinp")) != EOF)
+ 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;
}
if (errflg) {
(void) fprintf(stderr,
- "usage: %s [-dinp] [-c cmd] host ...\n",
+ "usage: %s [-46dinp] [-c cmd] host ...\n",
progname);
exit(2);
}
memset((char *)&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_ADDRCONFIG|AI_CANONNAME;
+ hints.ai_family = ai_fam_templ;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_socktype = SOCK_DGRAM;
}
break;
case IP_VERSION:
- if (*str) {
- if (*str == '6') /* We want the v6 version */
- argp->ival = 6;
- else if (*str == '4') /* Gimme the IPV4 */
- argp->ival = 4;
- else {
- (void) fprintf(stderr, "***Version must be either 4 or 6\n");
- return 0;
- }
+ 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");
+ return 0;
}
break;
}
FILE *fp
)
{
+ int i;
+
if (pcmd->nargs == 0) {
if (havehost)
(void) fprintf(fp, "current host is %s\n", currenthost);
else
(void) fprintf(fp, "no current host\n");
- } else if (openhost(pcmd->argval[0].string)) {
+ return;
+ }
+
+ i = 0;
+ ai_fam_templ = 0;
+ if (pcmd->nargs == 2) {
+ if (!strcmp("-4", pcmd->argval[i].string))
+ ai_fam_templ = AF_INET;
+ else if (!strcmp("-6", pcmd->argval[i].string))
+ ai_fam_templ = AF_INET6;
+ else {
+ if (havehost)
+ (void) fprintf(fp,
+ "current host remains %s\n", currenthost);
+ else
+ (void) fprintf(fp, "still no current host\n");
+ return;
+ }
+ i = 1;
+ }
+ if (openhost(pcmd->argval[i].string)) {
(void) fprintf(fp, "current host set to %s\n", currenthost);
numassoc = 0;
} else {
{ "assocID", "", "", "" },
"print status information returned for a peer" },
{ "peers", peers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"obtain and print a list of the server's peers [IP version]" },
{ "lpeers", lpeers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"obtain and print a list of all peers and clients [IP version]" },
{ "opeers", opeers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "-4|-6", "", "", "" },
"print peer list the old way, with dstadr shown rather than refid [IP version]" },
- { "lopeers", lopeers, { OPT|IP_VERSION, NO, NO, NO },
- { "6|4", "", "", "" },
+ { "lopeers", lopeers, { OPT|IP_VERSION, NO, NO, NO },
+ { "-4|-6", "", "", "" },
"obtain and print a list of all peers and clients showing dstadr [IP version]" },
{ 0, 0, { NO, NO, NO, NO },
- { "6|4", "", "", "" }, "" }
+ { "-4|-6", "", "", "" }, "" }
};