4 * cmd_args.c = command-line argument processing
11 #include "ntp_stdlib.h"
12 #include "ntp_cmdargs.h"
14 #include "ntpd-opts.h"
17 * Definitions of things either imported from or exported to outside
19 extern char const *progname
;
20 extern const char *specific_interface
;
21 extern short default_ai_family
;
24 extern int check_netinfo
;
29 * getCmdOpts - get command line options
37 extern const char *config_file
;
39 tOptions
*myOptions
= &ntpdOptions
;
42 * Initialize, initialize
47 default_ai_family
= AF_INET
;
48 else if (HAVE_OPT( IPV6
))
49 default_ai_family
= AF_INET6
;
51 if (HAVE_OPT( AUTHREQ
))
52 proto_config(PROTO_AUTHENTICATE
, 1, 0., NULL
);
53 else if (HAVE_OPT( AUTHNOREQ
))
54 proto_config(PROTO_AUTHENTICATE
, 0, 0., NULL
);
56 if (HAVE_OPT( BCASTSYNC
))
57 proto_config(PROTO_BROADCLIENT
, 1, 0., NULL
);
59 if (HAVE_OPT( CONFIGFILE
)) {
60 config_file
= OPT_ARG( CONFIGFILE
);
66 if (HAVE_OPT( DRIFTFILE
))
67 stats_config(STATS_FREQ_FILE
, OPT_ARG( DRIFTFILE
));
69 if (HAVE_OPT( PANICGATE
))
73 if (HAVE_OPT( JAILDIR
)) {
75 chrootdir
= OPT_ARG( JAILDIR
);
79 if (HAVE_OPT( KEYFILE
))
80 getauthkeys(OPT_ARG( KEYFILE
));
82 if (HAVE_OPT( PIDFILE
))
83 stats_config(STATS_PID_FILE
, OPT_ARG( PIDFILE
));
88 if (HAVE_OPT( PROPAGATIONDELAY
))
91 const char *my_ntp_optarg
= OPT_ARG( PROPAGATIONDELAY
);
93 if (sscanf(my_ntp_optarg
, "%lf", &tmp
) != 1) {
95 "command line broadcast delay value %s undecodable",
98 proto_config(PROTO_BROADDELAY
, 0, tmp
, NULL
);
102 if (HAVE_OPT( STATSDIR
))
103 stats_config(STATS_STATSDIR
, OPT_ARG( STATSDIR
));
105 if (HAVE_OPT( TRUSTEDKEY
)) {
106 int ct
= STACKCT_OPT( TRUSTEDKEY
);
107 const char** pp
= STACKLST_OPT( TRUSTEDKEY
);
111 const char* p
= *pp
++;
114 if (tkey
== 0 || tkey
> NTP_MAXKEY
) {
116 "command line trusted key %s is invalid",
125 if (HAVE_OPT( USER
)) {
127 user
= estrdup(OPT_ARG( USER
));
128 group
= rindex(user
, ':');
130 *group
++ = '\0'; /* get rid of the ':' */
134 if (HAVE_OPT( VAR
)) {
135 int ct
= STACKCT_OPT( VAR
);
136 const char** pp
= STACKLST_OPT( VAR
);
139 const char* my_ntp_optarg
= *pp
++;
141 set_sys_var(my_ntp_optarg
, strlen(my_ntp_optarg
)+1,
146 if (HAVE_OPT( DVAR
)) {
147 int ct
= STACKCT_OPT( DVAR
);
148 const char** pp
= STACKLST_OPT( DVAR
);
151 const char* my_ntp_optarg
= *pp
++;
153 set_sys_var(my_ntp_optarg
, strlen(my_ntp_optarg
)+1,
154 (u_short
) (RW
| DEF
));
158 if (HAVE_OPT( SLEW
)) {
162 if (HAVE_OPT( UPDATEINTERVAL
)) {
163 long val
= OPT_VALUE_UPDATEINTERVAL
;
166 interface_interval
= val
;
169 "command line interface update interval %ld must not be negative\n",
172 "command line interface update interval %ld must not be negative",
180 * The simulator no longer takes any command line arguments. Hence,
181 * all the code that was here has been removed.
186 if (errflg
|| argc
) {
188 fprintf(stderr
, "argc after processing is <%d>\n", argc
);
189 optionUsage(myOptions
, 2);