2 * cmd_args.c = command-line argument processing
9 #include "ntp_stdlib.h"
10 #include "ntp_cmdargs.h"
14 # include "ntpdsim-opts.h"
15 # define OPTSTRUCT ntpdsimOptions
17 # include "ntpd-opts.h"
18 # define OPTSTRUCT ntpdOptions
22 * Definitions of things either imported from or exported to outside
24 extern char const *progname;
25 extern const char *specific_interface;
26 extern short default_ai_family;
29 extern int check_netinfo;
34 * getCmdOpts - get command line options
42 extern const char *config_file;
44 tOptions *myOptions = &OPTSTRUCT;
47 * Initialize, initialize
51 switch (WHICH_IDX_IPV4) {
53 default_ai_family = AF_INET;
56 default_ai_family = AF_INET6;
59 /* ai_fam_templ = ai_fam_default; */
63 if (HAVE_OPT( AUTHREQ ))
64 proto_config(PROTO_AUTHENTICATE, 1, 0., NULL);
66 if (HAVE_OPT( AUTHNOREQ ))
67 proto_config(PROTO_AUTHENTICATE, 0, 0., NULL);
69 if (HAVE_OPT( BCASTSYNC ))
70 proto_config(PROTO_BROADCLIENT, 1, 0., NULL);
72 if (HAVE_OPT( CONFIGFILE )) {
73 config_file = OPT_ARG( CONFIGFILE );
79 if (HAVE_OPT( DRIFTFILE ))
80 stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE ));
82 if (HAVE_OPT( PANICGATE ))
85 if (HAVE_OPT( JAILDIR )) {
88 chrootdir = OPT_ARG( JAILDIR );
91 "command line -i option (jaildir) is not supported by this binary"
93 ",\n" "can not drop root privileges. See configure options\n"
94 "--enable-clockctl and --enable-linuxcaps.\n");
99 "command line -i option (jaildir) is not supported by this binary.");
104 if (HAVE_OPT( KEYFILE ))
105 getauthkeys(OPT_ARG( KEYFILE ));
107 if (HAVE_OPT( PIDFILE ))
108 stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
110 if (HAVE_OPT( QUIT ))
113 if (HAVE_OPT( PROPAGATIONDELAY ))
116 const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
118 if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
120 "command line broadcast delay value %s undecodable",
123 proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
127 if (HAVE_OPT( STATSDIR ))
128 stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
130 if (HAVE_OPT( TRUSTEDKEY )) {
131 int ct = STACKCT_OPT( TRUSTEDKEY );
132 const char** pp = STACKLST_OPT( TRUSTEDKEY );
136 const char* p = *pp++;
139 if (tkey == 0 || tkey > NTP_MAXKEY) {
141 "command line trusted key %s is invalid",
149 if (HAVE_OPT( USER )) {
151 char *ntp_optarg = OPT_ARG( USER );
154 user = emalloc(strlen(ntp_optarg) + 1);
155 (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
156 group = rindex(user, ':');
158 *group++ = '\0'; /* get rid of the ':' */
161 "command line -u/--user option is not supported by this binary"
163 ",\n" "can not drop root privileges. See configure options\n"
164 "--enable-clockctl and --enable-linuxcaps.\n");
169 "command line -u/--user option is not supported by this binary.");
174 if (HAVE_OPT( VAR )) {
175 int ct = STACKCT_OPT( VAR );
176 const char** pp = STACKLST_OPT( VAR );
179 const char* my_ntp_optarg = *pp++;
181 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
186 if (HAVE_OPT( DVAR )) {
187 int ct = STACKCT_OPT( DVAR );
188 const char** pp = STACKLST_OPT( DVAR );
191 const char* my_ntp_optarg = *pp++;
193 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
194 (u_short) (RW | DEF));
198 if (HAVE_OPT( SLEW ))
201 if (HAVE_OPT( UPDATEINTERVAL )) {
202 long val = OPT_VALUE_UPDATEINTERVAL;
205 interface_interval = val;
208 "command line interface update interval %ld must not be negative\n",
211 "command line interface update interval %ld must not be negative",
217 if (HAVE_OPT( SIMBROADCASTDELAY ))
218 sscanf(OPT_ARG( SIMBROADCASTDELAY ), "%lf", &ntp_node.bdly);
220 if (HAVE_OPT( PHASENOISE ))
221 sscanf(OPT_ARG( PHASENOISE ), "%lf", &ntp_node.snse);
223 if (HAVE_OPT( SIMSLEW ))
224 sscanf(OPT_ARG( SIMSLEW ), "%lf", &ntp_node.slew);
226 if (HAVE_OPT( SERVERTIME ))
227 sscanf(OPT_ARG( SERVERTIME ), "%lf", &ntp_node.clk_time);
229 if (HAVE_OPT( ENDSIMTIME ))
230 sscanf(OPT_ARG( ENDSIMTIME ), "%lf", &ntp_node.sim_time);
232 if (HAVE_OPT( FREQERR ))
233 sscanf(OPT_ARG( FREQERR ), "%lf", &ntp_node.ferr);
235 if (HAVE_OPT( WALKNOISE ))
236 sscanf(OPT_ARG( WALKNOISE ), "%lf", &ntp_node.fnse);
238 if (HAVE_OPT( NDELAY ))
239 sscanf(OPT_ARG( NDELAY ), "%lf", &ntp_node.ndly);
241 if (HAVE_OPT( PDELAY ))
242 sscanf(OPT_ARG( PDELAY ), "%lf", &ntp_node.pdly);
246 if (errflg || argc) {
248 fprintf(stderr, "argc after processing is <%d>\n", argc);
249 optionUsage(myOptions, 2);