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 );
94 if (HAVE_OPT( KEYFILE ))
95 getauthkeys(OPT_ARG( KEYFILE ));
97 if (HAVE_OPT( PIDFILE ))
98 stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE ));
100 if (HAVE_OPT( QUIT ))
103 if (HAVE_OPT( PROPAGATIONDELAY ))
106 const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY );
108 if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) {
110 "command line broadcast delay value %s undecodable",
113 proto_config(PROTO_BROADDELAY, 0, tmp, NULL);
117 if (HAVE_OPT( STATSDIR ))
118 stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
120 if (HAVE_OPT( TRUSTEDKEY )) {
121 int ct = STACKCT_OPT( TRUSTEDKEY );
122 const char** pp = STACKLST_OPT( TRUSTEDKEY );
126 const char* p = *pp++;
129 if (tkey == 0 || tkey > NTP_MAXKEY) {
131 "command line trusted key %s is invalid",
139 if (HAVE_OPT( USER )) {
141 char *ntp_optarg = OPT_ARG( USER );
144 user = malloc(strlen(ntp_optarg) + 1);
148 (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
149 group = rindex(user, ':');
151 *group++ = '\0'; /* get rid of the ':' */
158 if (HAVE_OPT( VAR )) {
159 int ct = STACKCT_OPT( VAR );
160 const char** pp = STACKLST_OPT( VAR );
163 const char* my_ntp_optarg = *pp++;
165 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
170 if (HAVE_OPT( DVAR )) {
171 int ct = STACKCT_OPT( DVAR );
172 const char** pp = STACKLST_OPT( DVAR );
175 const char* my_ntp_optarg = *pp++;
177 set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1,
178 (u_short) (RW | DEF));
182 if (HAVE_OPT( SLEW ))
185 if (HAVE_OPT( UPDATEINTERVAL )) {
186 long val = OPT_VALUE_UPDATEINTERVAL;
189 interface_interval = val;
192 "command line interface update interval %ld must be greater or equal to 0",
198 if (HAVE_OPT( SIMBROADCASTDELAY ))
199 sscanf(OPT_ARG( SIMBROADCASTDELAY ), "%lf", &ntp_node.bdly);
201 if (HAVE_OPT( PHASENOISE ))
202 sscanf(OPT_ARG( PHASENOISE ), "%lf", &ntp_node.snse);
204 if (HAVE_OPT( SIMSLEW ))
205 sscanf(OPT_ARG( SIMSLEW ), "%lf", &ntp_node.slew);
207 if (HAVE_OPT( SERVERTIME ))
208 sscanf(OPT_ARG( SERVERTIME ), "%lf", &ntp_node.clk_time);
210 if (HAVE_OPT( ENDSIMTIME ))
211 sscanf(OPT_ARG( ENDSIMTIME ), "%lf", &ntp_node.sim_time);
213 if (HAVE_OPT( FREQERR ))
214 sscanf(OPT_ARG( FREQERR ), "%lf", &ntp_node.ferr);
216 if (HAVE_OPT( WALKNOISE ))
217 sscanf(OPT_ARG( WALKNOISE ), "%lf", &ntp_node.fnse);
219 if (HAVE_OPT( NDELAY ))
220 sscanf(OPT_ARG( NDELAY ), "%lf", &ntp_node.ndly);
222 if (HAVE_OPT( PDELAY ))
223 sscanf(OPT_ARG( PDELAY ), "%lf", &ntp_node.pdly);
227 if (errflg || argc) {
228 printf("argc is <%d>\n", argc);
229 optionUsage(myOptions, 2);