1 /* $NetBSD: cmd_args.c,v 1.6 2008/08/23 09:10:31 kardel Exp $ */
4 * cmd_args.c = command-line argument processing
11 #include "ntp_stdlib.h"
12 #include "ntp_cmdargs.h"
16 # include "ntpdsim-opts.h"
17 # define OPTSTRUCT ntpdsimOptions
19 # include "ntpd-opts.h"
20 # define OPTSTRUCT ntpdOptions
24 * Definitions of things either imported from or exported to outside
26 extern char const *progname
;
27 extern const char *specific_interface
;
28 extern short default_ai_family
;
31 extern int check_netinfo
;
36 * getCmdOpts - get command line options
44 extern const char *config_file
;
46 tOptions
*myOptions
= &OPTSTRUCT
;
49 * Initialize, initialize
53 switch (WHICH_IDX_IPV4
) {
55 default_ai_family
= AF_INET
;
58 default_ai_family
= AF_INET6
;
61 /* ai_fam_templ = ai_fam_default; */
65 if (HAVE_OPT( AUTHREQ
))
66 proto_config(PROTO_AUTHENTICATE
, 1, 0., NULL
);
68 if (HAVE_OPT( AUTHNOREQ
))
69 proto_config(PROTO_AUTHENTICATE
, 0, 0., NULL
);
71 if (HAVE_OPT( BCASTSYNC
))
72 proto_config(PROTO_BROADCLIENT
, 1, 0., NULL
);
74 if (HAVE_OPT( CONFIGFILE
)) {
75 config_file
= OPT_ARG( CONFIGFILE
);
81 if (HAVE_OPT( DRIFTFILE
))
82 stats_config(STATS_FREQ_FILE
, OPT_ARG( DRIFTFILE
));
84 if (HAVE_OPT( PANICGATE
))
87 if (HAVE_OPT( JAILDIR
)) {
90 chrootdir
= (char *)OPT_ARG( JAILDIR
);
93 "command line -i option (jaildir) is not supported by this binary"
95 ",\n" "can not drop root privileges. See configure options\n"
96 "--enable-clockctl and --enable-linuxcaps.\n");
101 "command line -i option (jaildir) is not supported by this binary.");
106 if (HAVE_OPT( KEYFILE
))
107 getauthkeys(OPT_ARG( KEYFILE
));
109 if (HAVE_OPT( PIDFILE
))
110 stats_config(STATS_PID_FILE
, OPT_ARG( PIDFILE
));
112 if (HAVE_OPT( QUIT
))
115 if (HAVE_OPT( PROPAGATIONDELAY
))
118 const char *my_ntp_optarg
= OPT_ARG( PROPAGATIONDELAY
);
120 if (sscanf(my_ntp_optarg
, "%lf", &tmp
) != 1) {
122 "command line broadcast delay value %s undecodable",
125 proto_config(PROTO_BROADDELAY
, 0, tmp
, NULL
);
129 if (HAVE_OPT( STATSDIR
))
130 stats_config(STATS_STATSDIR
, OPT_ARG( STATSDIR
));
132 if (HAVE_OPT( TRUSTEDKEY
)) {
133 int ct
= STACKCT_OPT( TRUSTEDKEY
);
134 const char** pp
= STACKLST_OPT( TRUSTEDKEY
);
138 const char* p
= *pp
++;
141 if (tkey
== 0 || tkey
> NTP_MAXKEY
) {
143 "command line trusted key %s is invalid",
151 if (HAVE_OPT( USER
)) {
153 char *ntp_optarg
= (char *)OPT_ARG( USER
);
156 user
= emalloc(strlen(ntp_optarg
) + 1);
157 (void)strncpy(user
, ntp_optarg
, strlen(ntp_optarg
) + 1);
158 group
= rindex(user
, ':');
160 *group
++ = '\0'; /* get rid of the ':' */
163 "command line -u/--user option is not supported by this binary"
165 ",\n" "can not drop root privileges. See configure options\n"
166 "--enable-clockctl and --enable-linuxcaps.\n");
171 "command line -u/--user option is not supported by this binary.");
176 if (HAVE_OPT( VAR
)) {
177 int ct
= STACKCT_OPT( VAR
);
178 const char** pp
= STACKLST_OPT( VAR
);
181 const char* my_ntp_optarg
= *pp
++;
183 set_sys_var(my_ntp_optarg
, strlen(my_ntp_optarg
)+1,
188 if (HAVE_OPT( DVAR
)) {
189 int ct
= STACKCT_OPT( DVAR
);
190 const char** pp
= STACKLST_OPT( DVAR
);
193 const char* my_ntp_optarg
= *pp
++;
195 set_sys_var(my_ntp_optarg
, strlen(my_ntp_optarg
)+1,
196 (u_short
) (RW
| DEF
));
200 if (HAVE_OPT( SLEW
))
203 if (HAVE_OPT( UPDATEINTERVAL
)) {
204 long val
= OPT_VALUE_UPDATEINTERVAL
;
207 interface_interval
= val
;
210 "command line interface update interval %ld must not be negative\n",
213 "command line interface update interval %ld must not be negative",
219 if (HAVE_OPT( SIMBROADCASTDELAY
))
220 sscanf(OPT_ARG( SIMBROADCASTDELAY
), "%lf", &ntp_node
.bdly
);
222 if (HAVE_OPT( PHASENOISE
))
223 sscanf(OPT_ARG( PHASENOISE
), "%lf", &ntp_node
.snse
);
225 if (HAVE_OPT( SIMSLEW
))
226 sscanf(OPT_ARG( SIMSLEW
), "%lf", &ntp_node
.slew
);
228 if (HAVE_OPT( SERVERTIME
))
229 sscanf(OPT_ARG( SERVERTIME
), "%lf", &ntp_node
.clk_time
);
231 if (HAVE_OPT( ENDSIMTIME
))
232 sscanf(OPT_ARG( ENDSIMTIME
), "%lf", &ntp_node
.sim_time
);
234 if (HAVE_OPT( FREQERR
))
235 sscanf(OPT_ARG( FREQERR
), "%lf", &ntp_node
.ferr
);
237 if (HAVE_OPT( WALKNOISE
))
238 sscanf(OPT_ARG( WALKNOISE
), "%lf", &ntp_node
.fnse
);
240 if (HAVE_OPT( NDELAY
))
241 sscanf(OPT_ARG( NDELAY
), "%lf", &ntp_node
.ndly
);
243 if (HAVE_OPT( PDELAY
))
244 sscanf(OPT_ARG( PDELAY
), "%lf", &ntp_node
.pdly
);
248 if (errflg
|| argc
) {
250 fprintf(stderr
, "argc after processing is <%d>\n", argc
);
251 optionUsage(myOptions
, 2);