2 File autogenerated by gengetopt version 2.17
3 generated with the following command:
4 gengetopt --conf-parser
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
11 /* If we use autoconf. */
24 const char *gengetopt_args_info_purpose
= "";
26 const char *gengetopt_args_info_usage
=
27 "Usage: " CMDLINE_PARSER_PACKAGE
" [OPTIONS]...";
29 const char *gengetopt_args_info_help
[] = {
30 " -h, --help Print help and exit",
31 " -V, --version Print version and exit",
32 " -d, --debug Run in debug mode (default=off)",
33 " -c, --conf=STRING Read configuration file",
34 " --pidfile=STRING Filename of process id file (default=`./sgsnemu.pid')",
35 " --statedir=STRING Directory of nonvolatile data (default=`./')",
36 " --dns=STRING DNS Server to use",
37 " -l, --listen=STRING Local interface",
38 " -r, --remote=STRING Remote host",
39 " --contexts=INT Number of contexts (default=`1')",
40 " --timelimit=INT Exit after timelimit seconds (default=`0')",
41 " --gtpversion=INT GTP version to use (default=`1')",
42 " -a, --apn=STRING Access point name (default=`internet')",
43 " --selmode=INT Selection mode (default=`0x01')",
44 " --rattype=INT Radio Access Technology Type (optional-1to5)",
45 " --userloc=STRING User Location Information (optional-type.MCC.MNC.LAC.CIorSACorRAC)",
46 " --rai=STRING Routing Area Information (optional-MCC.MNC.LAC.RAC)",
47 " --mstz=STRING MS Time Zone (optional- sign.NbQuartersOfAnHour.DSTAdjustment)",
48 " --imeisv=STRING IMEI(SV) International Mobile Equipment Identity (and Software Version) (optional,16 digits)",
49 " -i, --imsi=STRING IMSI (default=`240010123456789')",
50 " --nsapi=INT NSAPI (default=`0')",
51 " -m, --msisdn=STRING Mobile Station ISDN number (default=`46702123456')",
52 " -q, --qos=INT Requested quality of service (default=`0x000b921f')",
53 " --qose1=INT Requested quality of service Extension 1 (example=`0x9396404074f9ffff')",
54 " --qose2=INT Requested quality of service Extension 2 (example=`0x11')",
55 " --qose3=INT Requested quality of service Extension 3 (example=`0x0101')",
56 " --qose4=INT Requested quality of service Extension 4 (example=`0x4040')",
57 " --charging=INT Charging characteristics (default=`0x0800')",
58 " -u, --uid=STRING Login user ID (default=`mig')",
59 " -p, --pwd=STRING Login password (default=`hemmelig')",
60 " --createif Create local network interface (default=off)",
61 " -n, --net=STRING Network address for local interface",
62 " --defaultroute Create default route (default=off)",
63 " --ipup=STRING Script to run after link-up",
64 " --ipdown=STRING Script to run after link-down",
65 " --pinghost=STRING Ping remote host",
66 " --pingrate=INT Number of ping req per second (default=`1')",
67 " --pingsize=INT Number of ping data bytes (default=`56')",
68 " --pingcount=INT Number of ping req to send (default=`0')",
69 " --pingquiet Do not print ping packet info (default=off)",
70 " --norecovery Do not send recovery (default=off)",
75 void clear_given(struct gengetopt_args_info
*args_info
);
77 void clear_args(struct gengetopt_args_info
*args_info
);
80 cmdline_parser_internal(int argc
, char *const *argv
,
81 struct gengetopt_args_info
*args_info
, int override
,
82 int initialize
, int check_required
,
83 const char *additional_error
);
87 struct line_list
*next
;
90 static struct line_list
*cmd_line_list
= 0;
91 static struct line_list
*cmd_line_list_tmp
= 0;
93 static void free_cmd_list(void)
95 /* free the list of a previous call */
97 while (cmd_line_list
) {
98 cmd_line_list_tmp
= cmd_line_list
;
99 cmd_line_list
= cmd_line_list
->next
;
100 free(cmd_line_list_tmp
->string_arg
);
101 free(cmd_line_list_tmp
);
106 static char *gengetopt_strdup(const char *s
);
109 void clear_given(struct gengetopt_args_info
*args_info
)
111 args_info
->help_given
= 0;
112 args_info
->version_given
= 0;
113 args_info
->debug_given
= 0;
114 args_info
->conf_given
= 0;
115 args_info
->pidfile_given
= 0;
116 args_info
->statedir_given
= 0;
117 args_info
->dns_given
= 0;
118 args_info
->listen_given
= 0;
119 args_info
->remote_given
= 0;
120 args_info
->contexts_given
= 0;
121 args_info
->timelimit_given
= 0;
122 args_info
->gtpversion_given
= 0;
123 args_info
->apn_given
= 0;
124 args_info
->selmode_given
= 0;
125 args_info
->rattype_given
= 0;
126 args_info
->userloc_given
= 0;
127 args_info
->rai_given
= 0;
128 args_info
->mstz_given
= 0;
129 args_info
->imeisv_given
= 0;
130 args_info
->imsi_given
= 0;
131 args_info
->nsapi_given
= 0;
132 args_info
->msisdn_given
= 0;
133 args_info
->qos_given
= 0;
134 args_info
->qose1_given
= 0;
135 args_info
->qose2_given
= 0;
136 args_info
->qose3_given
= 0;
137 args_info
->qose4_given
= 0;
138 args_info
->charging_given
= 0;
139 args_info
->uid_given
= 0;
140 args_info
->pwd_given
= 0;
141 args_info
->createif_given
= 0;
142 args_info
->net_given
= 0;
143 args_info
->defaultroute_given
= 0;
144 args_info
->ipup_given
= 0;
145 args_info
->ipdown_given
= 0;
146 args_info
->pinghost_given
= 0;
147 args_info
->pingrate_given
= 0;
148 args_info
->pingsize_given
= 0;
149 args_info
->pingcount_given
= 0;
150 args_info
->pingquiet_given
= 0;
151 args_info
->norecovery_given
= 0;
155 void clear_args(struct gengetopt_args_info
*args_info
)
157 args_info
->debug_flag
= 0;
158 args_info
->conf_arg
= NULL
;
159 args_info
->conf_orig
= NULL
;
160 args_info
->pidfile_arg
= gengetopt_strdup("./sgsnemu.pid");
161 args_info
->pidfile_orig
= NULL
;
162 args_info
->statedir_arg
= gengetopt_strdup("./");
163 args_info
->statedir_orig
= NULL
;
164 args_info
->dns_arg
= NULL
;
165 args_info
->dns_orig
= NULL
;
166 args_info
->listen_arg
= NULL
;
167 args_info
->listen_orig
= NULL
;
168 args_info
->remote_arg
= NULL
;
169 args_info
->remote_orig
= NULL
;
170 args_info
->contexts_arg
= 1;
171 args_info
->contexts_orig
= NULL
;
172 args_info
->timelimit_arg
= 0;
173 args_info
->timelimit_orig
= NULL
;
174 args_info
->gtpversion_arg
= 1;
175 args_info
->gtpversion_orig
= NULL
;
176 args_info
->apn_arg
= gengetopt_strdup("internet");
177 args_info
->apn_orig
= NULL
;
178 args_info
->selmode_arg
= 0x01;
179 args_info
->selmode_orig
= NULL
;
180 args_info
->rattype_arg
= "1";
181 args_info
->rattype_orig
= NULL
;
182 args_info
->userloc_arg
= strdup("02509946241207");
183 args_info
->userloc_orig
= NULL
;
184 args_info
->rai_arg
= strdup("02509946241207");
185 args_info
->rai_orig
= NULL
;
186 args_info
->mstz_arg
= strdup("0");
187 args_info
->mstz_orig
= NULL
;
188 args_info
->imeisv_arg
= strdup("2143658709214365");
189 args_info
->imeisv_orig
= NULL
;
190 args_info
->imsi_arg
= gengetopt_strdup("240010123456789");
191 args_info
->imsi_orig
= NULL
;
192 args_info
->nsapi_arg
= 0;
193 args_info
->nsapi_orig
= NULL
;
194 args_info
->msisdn_arg
= gengetopt_strdup("46702123456");
195 args_info
->msisdn_orig
= NULL
;
196 args_info
->qos_arg
= 0x000b921f;
197 args_info
->qos_orig
= NULL
;
198 args_info
->qose1_arg
= 0x9396404074f9ffff;
199 args_info
->qose1_orig
= NULL
;
200 args_info
->qose2_arg
= 0x11;
201 args_info
->qose2_orig
= NULL
;
202 args_info
->qose3_arg
= 0x0101;
203 args_info
->qose3_orig
= NULL
;
204 args_info
->qose4_arg
= 0x4040;
205 args_info
->qose4_orig
= NULL
;
206 args_info
->charging_arg
= 0x0800;
207 args_info
->charging_orig
= NULL
;
208 args_info
->uid_arg
= gengetopt_strdup("mig");
209 args_info
->uid_orig
= NULL
;
210 args_info
->pwd_arg
= gengetopt_strdup("hemmelig");
211 args_info
->pwd_orig
= NULL
;
212 args_info
->createif_flag
= 0;
213 args_info
->net_arg
= NULL
;
214 args_info
->net_orig
= NULL
;
215 args_info
->defaultroute_flag
= 0;
216 args_info
->ipup_arg
= NULL
;
217 args_info
->ipup_orig
= NULL
;
218 args_info
->ipdown_arg
= NULL
;
219 args_info
->ipdown_orig
= NULL
;
220 args_info
->pinghost_arg
= NULL
;
221 args_info
->pinghost_orig
= NULL
;
222 args_info
->pingrate_arg
= 1;
223 args_info
->pingrate_orig
= NULL
;
224 args_info
->pingsize_arg
= 56;
225 args_info
->pingsize_orig
= NULL
;
226 args_info
->pingcount_arg
= 0;
227 args_info
->pingcount_orig
= NULL
;
228 args_info
->pingquiet_flag
= 0;
229 args_info
->norecovery_flag
= 0;
234 void init_args_info(struct gengetopt_args_info
*args_info
)
236 args_info
->help_help
= gengetopt_args_info_help
[0];
237 args_info
->version_help
= gengetopt_args_info_help
[1];
238 args_info
->debug_help
= gengetopt_args_info_help
[2];
239 args_info
->conf_help
= gengetopt_args_info_help
[3];
240 args_info
->pidfile_help
= gengetopt_args_info_help
[4];
241 args_info
->statedir_help
= gengetopt_args_info_help
[5];
242 args_info
->dns_help
= gengetopt_args_info_help
[6];
243 args_info
->listen_help
= gengetopt_args_info_help
[7];
244 args_info
->remote_help
= gengetopt_args_info_help
[8];
245 args_info
->contexts_help
= gengetopt_args_info_help
[9];
246 args_info
->timelimit_help
= gengetopt_args_info_help
[10];
247 args_info
->gtpversion_help
= gengetopt_args_info_help
[11];
248 args_info
->apn_help
= gengetopt_args_info_help
[12];
249 args_info
->selmode_help
= gengetopt_args_info_help
[13];
250 args_info
->imsi_help
= gengetopt_args_info_help
[14];
251 args_info
->nsapi_help
= gengetopt_args_info_help
[15];
252 args_info
->msisdn_help
= gengetopt_args_info_help
[16];
253 args_info
->qos_help
= gengetopt_args_info_help
[17];
254 args_info
->charging_help
= gengetopt_args_info_help
[18];
255 args_info
->uid_help
= gengetopt_args_info_help
[19];
256 args_info
->pwd_help
= gengetopt_args_info_help
[20];
257 args_info
->createif_help
= gengetopt_args_info_help
[21];
258 args_info
->net_help
= gengetopt_args_info_help
[22];
259 args_info
->defaultroute_help
= gengetopt_args_info_help
[23];
260 args_info
->ipup_help
= gengetopt_args_info_help
[24];
261 args_info
->ipdown_help
= gengetopt_args_info_help
[25];
262 args_info
->pinghost_help
= gengetopt_args_info_help
[26];
263 args_info
->pingrate_help
= gengetopt_args_info_help
[27];
264 args_info
->pingsize_help
= gengetopt_args_info_help
[28];
265 args_info
->pingcount_help
= gengetopt_args_info_help
[29];
266 args_info
->pingquiet_help
= gengetopt_args_info_help
[30];
267 args_info
->norecovery_help
= gengetopt_args_info_help
[31];
271 void cmdline_parser_print_version(void)
273 printf("%s %s\n", CMDLINE_PARSER_PACKAGE
, CMDLINE_PARSER_VERSION
);
276 void cmdline_parser_print_help(void)
279 cmdline_parser_print_version();
281 if (strlen(gengetopt_args_info_purpose
) > 0)
282 printf("\n%s\n", gengetopt_args_info_purpose
);
284 printf("\n%s\n\n", gengetopt_args_info_usage
);
285 while (gengetopt_args_info_help
[i
])
286 printf("%s\n", gengetopt_args_info_help
[i
++]);
289 void cmdline_parser_init(struct gengetopt_args_info
*args_info
)
291 clear_given(args_info
);
292 clear_args(args_info
);
293 init_args_info(args_info
);
296 static void cmdline_parser_release(struct gengetopt_args_info
*args_info
)
299 if (args_info
->conf_arg
) {
300 free(args_info
->conf_arg
); /* free previous argument */
301 args_info
->conf_arg
= 0;
303 if (args_info
->conf_orig
) {
304 free(args_info
->conf_orig
); /* free previous argument */
305 args_info
->conf_orig
= 0;
307 if (args_info
->pidfile_arg
) {
308 free(args_info
->pidfile_arg
); /* free previous argument */
309 args_info
->pidfile_arg
= 0;
311 if (args_info
->pidfile_orig
) {
312 free(args_info
->pidfile_orig
); /* free previous argument */
313 args_info
->pidfile_orig
= 0;
315 if (args_info
->statedir_arg
) {
316 free(args_info
->statedir_arg
); /* free previous argument */
317 args_info
->statedir_arg
= 0;
319 if (args_info
->statedir_orig
) {
320 free(args_info
->statedir_orig
); /* free previous argument */
321 args_info
->statedir_orig
= 0;
323 if (args_info
->dns_arg
) {
324 free(args_info
->dns_arg
); /* free previous argument */
325 args_info
->dns_arg
= 0;
327 if (args_info
->dns_orig
) {
328 free(args_info
->dns_orig
); /* free previous argument */
329 args_info
->dns_orig
= 0;
331 if (args_info
->listen_arg
) {
332 free(args_info
->listen_arg
); /* free previous argument */
333 args_info
->listen_arg
= 0;
335 if (args_info
->listen_orig
) {
336 free(args_info
->listen_orig
); /* free previous argument */
337 args_info
->listen_orig
= 0;
339 if (args_info
->remote_arg
) {
340 free(args_info
->remote_arg
); /* free previous argument */
341 args_info
->remote_arg
= 0;
343 if (args_info
->remote_orig
) {
344 free(args_info
->remote_orig
); /* free previous argument */
345 args_info
->remote_orig
= 0;
347 if (args_info
->contexts_orig
) {
348 free(args_info
->contexts_orig
); /* free previous argument */
349 args_info
->contexts_orig
= 0;
351 if (args_info
->timelimit_orig
) {
352 free(args_info
->timelimit_orig
); /* free previous argument */
353 args_info
->timelimit_orig
= 0;
355 if (args_info
->gtpversion_orig
) {
356 free(args_info
->gtpversion_orig
); /* free previous argument */
357 args_info
->gtpversion_orig
= 0;
359 if (args_info
->apn_arg
) {
360 free(args_info
->apn_arg
); /* free previous argument */
361 args_info
->apn_arg
= 0;
363 if (args_info
->apn_orig
) {
364 free(args_info
->apn_orig
); /* free previous argument */
365 args_info
->apn_orig
= 0;
367 if (args_info
->selmode_orig
) {
368 free(args_info
->selmode_orig
); /* free previous argument */
369 args_info
->selmode_orig
= 0;
371 if (args_info
->imsi_arg
) {
372 free(args_info
->imsi_arg
); /* free previous argument */
373 args_info
->imsi_arg
= 0;
375 if (args_info
->imsi_orig
) {
376 free(args_info
->imsi_orig
); /* free previous argument */
377 args_info
->imsi_orig
= 0;
379 if (args_info
->nsapi_orig
) {
380 free(args_info
->nsapi_orig
); /* free previous argument */
381 args_info
->nsapi_orig
= 0;
383 if (args_info
->msisdn_arg
) {
384 free(args_info
->msisdn_arg
); /* free previous argument */
385 args_info
->msisdn_arg
= 0;
387 if (args_info
->msisdn_orig
) {
388 free(args_info
->msisdn_orig
); /* free previous argument */
389 args_info
->msisdn_orig
= 0;
391 if (args_info
->qos_orig
) {
392 free(args_info
->qos_orig
); /* free previous argument */
393 args_info
->qos_orig
= 0;
395 if (args_info
->charging_orig
) {
396 free(args_info
->charging_orig
); /* free previous argument */
397 args_info
->charging_orig
= 0;
399 if (args_info
->uid_arg
) {
400 free(args_info
->uid_arg
); /* free previous argument */
401 args_info
->uid_arg
= 0;
403 if (args_info
->uid_orig
) {
404 free(args_info
->uid_orig
); /* free previous argument */
405 args_info
->uid_orig
= 0;
407 if (args_info
->pwd_arg
) {
408 free(args_info
->pwd_arg
); /* free previous argument */
409 args_info
->pwd_arg
= 0;
411 if (args_info
->pwd_orig
) {
412 free(args_info
->pwd_orig
); /* free previous argument */
413 args_info
->pwd_orig
= 0;
415 if (args_info
->net_arg
) {
416 free(args_info
->net_arg
); /* free previous argument */
417 args_info
->net_arg
= 0;
419 if (args_info
->net_orig
) {
420 free(args_info
->net_orig
); /* free previous argument */
421 args_info
->net_orig
= 0;
423 if (args_info
->ipup_arg
) {
424 free(args_info
->ipup_arg
); /* free previous argument */
425 args_info
->ipup_arg
= 0;
427 if (args_info
->ipup_orig
) {
428 free(args_info
->ipup_orig
); /* free previous argument */
429 args_info
->ipup_orig
= 0;
431 if (args_info
->ipdown_arg
) {
432 free(args_info
->ipdown_arg
); /* free previous argument */
433 args_info
->ipdown_arg
= 0;
435 if (args_info
->ipdown_orig
) {
436 free(args_info
->ipdown_orig
); /* free previous argument */
437 args_info
->ipdown_orig
= 0;
439 if (args_info
->pinghost_arg
) {
440 free(args_info
->pinghost_arg
); /* free previous argument */
441 args_info
->pinghost_arg
= 0;
443 if (args_info
->pinghost_orig
) {
444 free(args_info
->pinghost_orig
); /* free previous argument */
445 args_info
->pinghost_orig
= 0;
447 if (args_info
->pingrate_orig
) {
448 free(args_info
->pingrate_orig
); /* free previous argument */
449 args_info
->pingrate_orig
= 0;
451 if (args_info
->pingsize_orig
) {
452 free(args_info
->pingsize_orig
); /* free previous argument */
453 args_info
->pingsize_orig
= 0;
455 if (args_info
->pingcount_orig
) {
456 free(args_info
->pingcount_orig
); /* free previous argument */
457 args_info
->pingcount_orig
= 0;
460 clear_given(args_info
);
464 cmdline_parser_file_save(const char *filename
,
465 struct gengetopt_args_info
*args_info
)
470 outfile
= fopen(filename
, "w");
473 fprintf(stderr
, "%s: cannot open file for writing: %s\n",
474 CMDLINE_PARSER_PACKAGE
, filename
);
478 if (args_info
->help_given
) {
479 fprintf(outfile
, "%s\n", "help");
481 if (args_info
->version_given
) {
482 fprintf(outfile
, "%s\n", "version");
484 if (args_info
->debug_given
) {
485 fprintf(outfile
, "%s\n", "debug");
487 if (args_info
->conf_given
) {
488 if (args_info
->conf_orig
) {
489 fprintf(outfile
, "%s=\"%s\"\n", "conf",
490 args_info
->conf_orig
);
492 fprintf(outfile
, "%s\n", "conf");
495 if (args_info
->pidfile_given
) {
496 if (args_info
->pidfile_orig
) {
497 fprintf(outfile
, "%s=\"%s\"\n", "pidfile",
498 args_info
->pidfile_orig
);
500 fprintf(outfile
, "%s\n", "pidfile");
503 if (args_info
->statedir_given
) {
504 if (args_info
->statedir_orig
) {
505 fprintf(outfile
, "%s=\"%s\"\n", "statedir",
506 args_info
->statedir_orig
);
508 fprintf(outfile
, "%s\n", "statedir");
511 if (args_info
->dns_given
) {
512 if (args_info
->dns_orig
) {
513 fprintf(outfile
, "%s=\"%s\"\n", "dns",
514 args_info
->dns_orig
);
516 fprintf(outfile
, "%s\n", "dns");
519 if (args_info
->listen_given
) {
520 if (args_info
->listen_orig
) {
521 fprintf(outfile
, "%s=\"%s\"\n", "listen",
522 args_info
->listen_orig
);
524 fprintf(outfile
, "%s\n", "listen");
527 if (args_info
->remote_given
) {
528 if (args_info
->remote_orig
) {
529 fprintf(outfile
, "%s=\"%s\"\n", "remote",
530 args_info
->remote_orig
);
532 fprintf(outfile
, "%s\n", "remote");
535 if (args_info
->contexts_given
) {
536 if (args_info
->contexts_orig
) {
537 fprintf(outfile
, "%s=\"%s\"\n", "contexts",
538 args_info
->contexts_orig
);
540 fprintf(outfile
, "%s\n", "contexts");
543 if (args_info
->timelimit_given
) {
544 if (args_info
->timelimit_orig
) {
545 fprintf(outfile
, "%s=\"%s\"\n", "timelimit",
546 args_info
->timelimit_orig
);
548 fprintf(outfile
, "%s\n", "timelimit");
551 if (args_info
->gtpversion_given
) {
552 if (args_info
->gtpversion_orig
) {
553 fprintf(outfile
, "%s=\"%s\"\n", "gtpversion",
554 args_info
->gtpversion_orig
);
556 fprintf(outfile
, "%s\n", "gtpversion");
559 if (args_info
->apn_given
) {
560 if (args_info
->apn_orig
) {
561 fprintf(outfile
, "%s=\"%s\"\n", "apn",
562 args_info
->apn_orig
);
564 fprintf(outfile
, "%s\n", "apn");
567 if (args_info
->selmode_given
) {
568 if (args_info
->selmode_orig
) {
569 fprintf(outfile
, "%s=\"%s\"\n", "selmode",
570 args_info
->selmode_orig
);
572 fprintf(outfile
, "%s\n", "selmode");
575 if (args_info
->imsi_given
) {
576 if (args_info
->imsi_orig
) {
577 fprintf(outfile
, "%s=\"%s\"\n", "imsi",
578 args_info
->imsi_orig
);
580 fprintf(outfile
, "%s\n", "imsi");
583 if (args_info
->nsapi_given
) {
584 if (args_info
->nsapi_orig
) {
585 fprintf(outfile
, "%s=\"%s\"\n", "nsapi",
586 args_info
->nsapi_orig
);
588 fprintf(outfile
, "%s\n", "nsapi");
591 if (args_info
->msisdn_given
) {
592 if (args_info
->msisdn_orig
) {
593 fprintf(outfile
, "%s=\"%s\"\n", "msisdn",
594 args_info
->msisdn_orig
);
596 fprintf(outfile
, "%s\n", "msisdn");
599 if (args_info
->qos_given
) {
600 if (args_info
->qos_orig
) {
601 fprintf(outfile
, "%s=\"%s\"\n", "qos",
602 args_info
->qos_orig
);
604 fprintf(outfile
, "%s\n", "qos");
607 if (args_info
->charging_given
) {
608 if (args_info
->charging_orig
) {
609 fprintf(outfile
, "%s=\"%s\"\n", "charging",
610 args_info
->charging_orig
);
612 fprintf(outfile
, "%s\n", "charging");
615 if (args_info
->uid_given
) {
616 if (args_info
->uid_orig
) {
617 fprintf(outfile
, "%s=\"%s\"\n", "uid",
618 args_info
->uid_orig
);
620 fprintf(outfile
, "%s\n", "uid");
623 if (args_info
->pwd_given
) {
624 if (args_info
->pwd_orig
) {
625 fprintf(outfile
, "%s=\"%s\"\n", "pwd",
626 args_info
->pwd_orig
);
628 fprintf(outfile
, "%s\n", "pwd");
631 if (args_info
->createif_given
) {
632 fprintf(outfile
, "%s\n", "createif");
634 if (args_info
->net_given
) {
635 if (args_info
->net_orig
) {
636 fprintf(outfile
, "%s=\"%s\"\n", "net",
637 args_info
->net_orig
);
639 fprintf(outfile
, "%s\n", "net");
642 if (args_info
->defaultroute_given
) {
643 fprintf(outfile
, "%s\n", "defaultroute");
645 if (args_info
->ipup_given
) {
646 if (args_info
->ipup_orig
) {
647 fprintf(outfile
, "%s=\"%s\"\n", "ipup",
648 args_info
->ipup_orig
);
650 fprintf(outfile
, "%s\n", "ipup");
653 if (args_info
->ipdown_given
) {
654 if (args_info
->ipdown_orig
) {
655 fprintf(outfile
, "%s=\"%s\"\n", "ipdown",
656 args_info
->ipdown_orig
);
658 fprintf(outfile
, "%s\n", "ipdown");
661 if (args_info
->pinghost_given
) {
662 if (args_info
->pinghost_orig
) {
663 fprintf(outfile
, "%s=\"%s\"\n", "pinghost",
664 args_info
->pinghost_orig
);
666 fprintf(outfile
, "%s\n", "pinghost");
669 if (args_info
->pingrate_given
) {
670 if (args_info
->pingrate_orig
) {
671 fprintf(outfile
, "%s=\"%s\"\n", "pingrate",
672 args_info
->pingrate_orig
);
674 fprintf(outfile
, "%s\n", "pingrate");
677 if (args_info
->pingsize_given
) {
678 if (args_info
->pingsize_orig
) {
679 fprintf(outfile
, "%s=\"%s\"\n", "pingsize",
680 args_info
->pingsize_orig
);
682 fprintf(outfile
, "%s\n", "pingsize");
685 if (args_info
->pingcount_given
) {
686 if (args_info
->pingcount_orig
) {
687 fprintf(outfile
, "%s=\"%s\"\n", "pingcount",
688 args_info
->pingcount_orig
);
690 fprintf(outfile
, "%s\n", "pingcount");
693 if (args_info
->pingquiet_given
) {
694 fprintf(outfile
, "%s\n", "pingquiet");
696 if (args_info
->norecovery_given
) {
697 fprintf(outfile
, "%s\n", "norecovery");
706 void cmdline_parser_free(struct gengetopt_args_info
*args_info
)
708 cmdline_parser_release(args_info
);
711 /* gengetopt_strdup() */
712 /* strdup.c replacement of strdup, which is not standard */
713 char *gengetopt_strdup(const char *s
)
719 result
= (char *)malloc(strlen(s
) + 1);
720 if (result
== (char *)0)
727 cmdline_parser(int argc
, char *const *argv
,
728 struct gengetopt_args_info
*args_info
)
730 return cmdline_parser2(argc
, argv
, args_info
, 0, 1, 1);
734 cmdline_parser2(int argc
, char *const *argv
,
735 struct gengetopt_args_info
*args_info
, int override
,
736 int initialize
, int check_required
)
741 cmdline_parser_internal(argc
, argv
, args_info
, override
, initialize
,
742 check_required
, NULL
);
744 if (result
== EXIT_FAILURE
) {
745 cmdline_parser_free(args_info
);
753 cmdline_parser_required(struct gengetopt_args_info
*args_info
,
754 const char *prog_name
)
760 cmdline_parser_internal(int argc
, char *const *argv
,
761 struct gengetopt_args_info
*args_info
, int override
,
762 int initialize
, int check_required
,
763 const char *additional_error
)
765 int c
; /* Character of the parsed option. */
768 struct gengetopt_args_info local_args_info
;
771 cmdline_parser_init(args_info
);
773 cmdline_parser_init(&local_args_info
);
781 int option_index
= 0;
784 static struct option long_options
[] = {
785 {"help", 0, NULL
, 'h'},
786 {"version", 0, NULL
, 'V'},
787 {"debug", 0, NULL
, 'd'},
788 {"conf", 1, NULL
, 'c'},
789 {"pidfile", 1, NULL
, 0},
790 {"statedir", 1, NULL
, 0},
792 {"listen", 1, NULL
, 'l'},
793 {"remote", 1, NULL
, 'r'},
794 {"contexts", 1, NULL
, 0},
795 {"timelimit", 1, NULL
, 0},
796 {"gtpversion", 1, NULL
, 0},
797 {"apn", 1, NULL
, 'a'},
798 {"selmode", 1, NULL
, 0},
799 {"rattype", 1, NULL
, 0},
800 {"userloc", 1, NULL
, 0},
802 {"mstz", 1, NULL
, 0},
803 {"imeisv", 1, NULL
, 0},
804 {"imsi", 1, NULL
, 'i'},
805 {"nsapi", 1, NULL
, 0},
806 {"msisdn", 1, NULL
, 'm'},
807 {"qos", 1, NULL
, 'q'},
808 {"qose1", 1, NULL
, 0},
809 {"qose2", 1, NULL
, 0},
810 {"qose3", 1, NULL
, 0},
811 {"qose4", 1, NULL
, 0},
812 {"charging", 1, NULL
, 0},
813 {"uid", 1, NULL
, 'u'},
814 {"pwd", 1, NULL
, 'p'},
815 {"createif", 0, NULL
, 0},
816 {"net", 1, NULL
, 'n'},
817 {"defaultroute", 0, NULL
, 0},
818 {"ipup", 1, NULL
, 0},
819 {"ipdown", 1, NULL
, 0},
820 {"pinghost", 1, NULL
, 0},
821 {"pingrate", 1, NULL
, 0},
822 {"pingsize", 1, NULL
, 0},
823 {"pingcount", 1, NULL
, 0},
824 {"pingquiet", 0, NULL
, 0},
825 {"norecovery", 0, NULL
, 0},
830 c
= getopt_long(argc
, argv
, "hVdc:l:r:a:i:m:q:u:p:n:",
831 long_options
, &option_index
);
834 break; /* Exit from `while (1)' loop. */
837 case 'h': /* Print help and exit. */
838 cmdline_parser_print_help();
839 cmdline_parser_free(&local_args_info
);
842 case 'V': /* Print version and exit. */
843 cmdline_parser_print_version();
844 cmdline_parser_free(&local_args_info
);
847 case 'd': /* Run in debug mode. */
848 if (local_args_info
.debug_given
) {
850 "%s: `--debug' (`-d') option given more than once%s\n",
852 (additional_error
? additional_error
:
856 if (args_info
->debug_given
&& !override
)
858 local_args_info
.debug_given
= 1;
859 args_info
->debug_given
= 1;
860 args_info
->debug_flag
= !(args_info
->debug_flag
);
863 case 'c': /* Read configuration file. */
864 if (local_args_info
.conf_given
) {
866 "%s: `--conf' (`-c') option given more than once%s\n",
868 (additional_error
? additional_error
:
872 if (args_info
->conf_given
&& !override
)
874 local_args_info
.conf_given
= 1;
875 args_info
->conf_given
= 1;
876 if (args_info
->conf_arg
)
877 free(args_info
->conf_arg
); /* free previous string */
878 args_info
->conf_arg
= gengetopt_strdup(optarg
);
879 if (args_info
->conf_orig
)
880 free(args_info
->conf_orig
); /* free previous string */
881 args_info
->conf_orig
= gengetopt_strdup(optarg
);
884 case 'l': /* Local interface. */
885 if (local_args_info
.listen_given
) {
887 "%s: `--listen' (`-l') option given more than once%s\n",
889 (additional_error
? additional_error
:
893 if (args_info
->listen_given
&& !override
)
895 local_args_info
.listen_given
= 1;
896 args_info
->listen_given
= 1;
897 if (args_info
->listen_arg
)
898 free(args_info
->listen_arg
); /* free previous string */
899 args_info
->listen_arg
= gengetopt_strdup(optarg
);
900 if (args_info
->listen_orig
)
901 free(args_info
->listen_orig
); /* free previous string */
902 args_info
->listen_orig
= gengetopt_strdup(optarg
);
905 case 'r': /* Remote host. */
906 if (local_args_info
.remote_given
) {
908 "%s: `--remote' (`-r') option given more than once%s\n",
910 (additional_error
? additional_error
:
914 if (args_info
->remote_given
&& !override
)
916 local_args_info
.remote_given
= 1;
917 args_info
->remote_given
= 1;
918 if (args_info
->remote_arg
)
919 free(args_info
->remote_arg
); /* free previous string */
920 args_info
->remote_arg
= gengetopt_strdup(optarg
);
921 if (args_info
->remote_orig
)
922 free(args_info
->remote_orig
); /* free previous string */
923 args_info
->remote_orig
= gengetopt_strdup(optarg
);
926 case 'a': /* Access point name. */
927 if (local_args_info
.apn_given
) {
929 "%s: `--apn' (`-a') option given more than once%s\n",
931 (additional_error
? additional_error
:
935 if (args_info
->apn_given
&& !override
)
937 local_args_info
.apn_given
= 1;
938 args_info
->apn_given
= 1;
939 if (args_info
->apn_arg
)
940 free(args_info
->apn_arg
); /* free previous string */
941 args_info
->apn_arg
= gengetopt_strdup(optarg
);
942 if (args_info
->apn_orig
)
943 free(args_info
->apn_orig
); /* free previous string */
944 args_info
->apn_orig
= gengetopt_strdup(optarg
);
947 case 'i': /* IMSI. */
948 if (local_args_info
.imsi_given
) {
950 "%s: `--imsi' (`-i') option given more than once%s\n",
952 (additional_error
? additional_error
:
956 if (args_info
->imsi_given
&& !override
)
958 local_args_info
.imsi_given
= 1;
959 args_info
->imsi_given
= 1;
960 if (args_info
->imsi_arg
)
961 free(args_info
->imsi_arg
); /* free previous string */
962 args_info
->imsi_arg
= gengetopt_strdup(optarg
);
963 if (args_info
->imsi_orig
)
964 free(args_info
->imsi_orig
); /* free previous string */
965 args_info
->imsi_orig
= gengetopt_strdup(optarg
);
968 case 'm': /* Mobile Station ISDN number. */
969 if (local_args_info
.msisdn_given
) {
971 "%s: `--msisdn' (`-m') option given more than once%s\n",
973 (additional_error
? additional_error
:
977 if (args_info
->msisdn_given
&& !override
)
979 local_args_info
.msisdn_given
= 1;
980 args_info
->msisdn_given
= 1;
981 if (args_info
->msisdn_arg
)
982 free(args_info
->msisdn_arg
); /* free previous string */
983 args_info
->msisdn_arg
= gengetopt_strdup(optarg
);
984 if (args_info
->msisdn_orig
)
985 free(args_info
->msisdn_orig
); /* free previous string */
986 args_info
->msisdn_orig
= gengetopt_strdup(optarg
);
989 case 'q': /* Requested quality of service. */
990 if (local_args_info
.qos_given
) {
992 "%s: `--qos' (`-q') option given more than once%s\n",
994 (additional_error
? additional_error
:
998 if (args_info
->qos_given
&& !override
)
1000 local_args_info
.qos_given
= 1;
1001 args_info
->qos_given
= 1;
1002 args_info
->qos_arg
= strtol(optarg
, &stop_char
, 0);
1003 if (!(stop_char
&& *stop_char
== '\0')) {
1005 "%s: invalid numeric value: %s\n",
1009 if (args_info
->qos_orig
)
1010 free(args_info
->qos_orig
); /* free previous string */
1011 args_info
->qos_orig
= gengetopt_strdup(optarg
);
1014 case 'u': /* Login user ID. */
1015 if (local_args_info
.uid_given
) {
1017 "%s: `--uid' (`-u') option given more than once%s\n",
1019 (additional_error
? additional_error
:
1023 if (args_info
->uid_given
&& !override
)
1025 local_args_info
.uid_given
= 1;
1026 args_info
->uid_given
= 1;
1027 if (args_info
->uid_arg
)
1028 free(args_info
->uid_arg
); /* free previous string */
1029 args_info
->uid_arg
= gengetopt_strdup(optarg
);
1030 if (args_info
->uid_orig
)
1031 free(args_info
->uid_orig
); /* free previous string */
1032 args_info
->uid_orig
= gengetopt_strdup(optarg
);
1035 case 'p': /* Login password. */
1036 if (local_args_info
.pwd_given
) {
1038 "%s: `--pwd' (`-p') option given more than once%s\n",
1040 (additional_error
? additional_error
:
1044 if (args_info
->pwd_given
&& !override
)
1046 local_args_info
.pwd_given
= 1;
1047 args_info
->pwd_given
= 1;
1048 if (args_info
->pwd_arg
)
1049 free(args_info
->pwd_arg
); /* free previous string */
1050 args_info
->pwd_arg
= gengetopt_strdup(optarg
);
1051 if (args_info
->pwd_orig
)
1052 free(args_info
->pwd_orig
); /* free previous string */
1053 args_info
->pwd_orig
= gengetopt_strdup(optarg
);
1056 case 'n': /* Network address for local interface. */
1057 if (local_args_info
.net_given
) {
1059 "%s: `--net' (`-n') option given more than once%s\n",
1061 (additional_error
? additional_error
:
1065 if (args_info
->net_given
&& !override
)
1067 local_args_info
.net_given
= 1;
1068 args_info
->net_given
= 1;
1069 if (args_info
->net_arg
)
1070 free(args_info
->net_arg
); /* free previous string */
1071 args_info
->net_arg
= gengetopt_strdup(optarg
);
1072 if (args_info
->net_orig
)
1073 free(args_info
->net_orig
); /* free previous string */
1074 args_info
->net_orig
= gengetopt_strdup(optarg
);
1077 case 0: /* Long option with no short option */
1078 /* Filename of process id file. */
1079 if (strcmp(long_options
[option_index
].name
, "pidfile")
1081 if (local_args_info
.pidfile_given
) {
1083 "%s: `--pidfile' option given more than once%s\n",
1086 additional_error
: ""));
1089 if (args_info
->pidfile_given
&& !override
)
1091 local_args_info
.pidfile_given
= 1;
1092 args_info
->pidfile_given
= 1;
1093 if (args_info
->pidfile_arg
)
1094 free(args_info
->pidfile_arg
); /* free previous string */
1095 args_info
->pidfile_arg
=
1096 gengetopt_strdup(optarg
);
1097 if (args_info
->pidfile_orig
)
1098 free(args_info
->pidfile_orig
); /* free previous string */
1099 args_info
->pidfile_orig
=
1100 gengetopt_strdup(optarg
);
1102 /* Directory of nonvolatile data. */
1104 (long_options
[option_index
].name
,
1106 if (local_args_info
.statedir_given
) {
1108 "%s: `--statedir' option given more than once%s\n",
1111 additional_error
: ""));
1114 if (args_info
->statedir_given
&& !override
)
1116 local_args_info
.statedir_given
= 1;
1117 args_info
->statedir_given
= 1;
1118 if (args_info
->statedir_arg
)
1119 free(args_info
->statedir_arg
); /* free previous string */
1120 args_info
->statedir_arg
=
1121 gengetopt_strdup(optarg
);
1122 if (args_info
->statedir_orig
)
1123 free(args_info
->statedir_orig
); /* free previous string */
1124 args_info
->statedir_orig
=
1125 gengetopt_strdup(optarg
);
1127 /* DNS Server to use. */
1128 else if (strcmp(long_options
[option_index
].name
, "dns")
1130 if (local_args_info
.dns_given
) {
1132 "%s: `--dns' option given more than once%s\n",
1135 additional_error
: ""));
1138 if (args_info
->dns_given
&& !override
)
1140 local_args_info
.dns_given
= 1;
1141 args_info
->dns_given
= 1;
1142 if (args_info
->dns_arg
)
1143 free(args_info
->dns_arg
); /* free previous string */
1144 args_info
->dns_arg
= gengetopt_strdup(optarg
);
1145 if (args_info
->dns_orig
)
1146 free(args_info
->dns_orig
); /* free previous string */
1147 args_info
->dns_orig
= gengetopt_strdup(optarg
);
1149 /* Number of contexts. */
1151 (long_options
[option_index
].name
,
1153 if (local_args_info
.contexts_given
) {
1155 "%s: `--contexts' option given more than once%s\n",
1158 additional_error
: ""));
1161 if (args_info
->contexts_given
&& !override
)
1163 local_args_info
.contexts_given
= 1;
1164 args_info
->contexts_given
= 1;
1165 args_info
->contexts_arg
=
1166 strtol(optarg
, &stop_char
, 0);
1167 if (!(stop_char
&& *stop_char
== '\0')) {
1169 "%s: invalid numeric value: %s\n",
1173 if (args_info
->contexts_orig
)
1174 free(args_info
->contexts_orig
); /* free previous string */
1175 args_info
->contexts_orig
=
1176 gengetopt_strdup(optarg
);
1178 /* Exit after timelimit seconds. */
1180 (long_options
[option_index
].name
,
1181 "timelimit") == 0) {
1182 if (local_args_info
.timelimit_given
) {
1184 "%s: `--timelimit' option given more than once%s\n",
1187 additional_error
: ""));
1190 if (args_info
->timelimit_given
&& !override
)
1192 local_args_info
.timelimit_given
= 1;
1193 args_info
->timelimit_given
= 1;
1194 args_info
->timelimit_arg
=
1195 strtol(optarg
, &stop_char
, 0);
1196 if (!(stop_char
&& *stop_char
== '\0')) {
1198 "%s: invalid numeric value: %s\n",
1202 if (args_info
->timelimit_orig
)
1203 free(args_info
->timelimit_orig
); /* free previous string */
1204 args_info
->timelimit_orig
=
1205 gengetopt_strdup(optarg
);
1207 /* GTP version to use. */
1209 (long_options
[option_index
].name
,
1210 "gtpversion") == 0) {
1211 if (local_args_info
.gtpversion_given
) {
1213 "%s: `--gtpversion' option given more than once%s\n",
1216 additional_error
: ""));
1219 if (args_info
->gtpversion_given
&& !override
)
1221 local_args_info
.gtpversion_given
= 1;
1222 args_info
->gtpversion_given
= 1;
1223 args_info
->gtpversion_arg
=
1224 strtol(optarg
, &stop_char
, 0);
1225 if (!(stop_char
&& *stop_char
== '\0')) {
1227 "%s: invalid numeric value: %s\n",
1231 if (args_info
->gtpversion_orig
)
1232 free(args_info
->gtpversion_orig
); /* free previous string */
1233 args_info
->gtpversion_orig
=
1234 gengetopt_strdup(optarg
);
1236 /* Selection mode. */
1238 (long_options
[option_index
].name
,
1240 if (local_args_info
.selmode_given
) {
1242 "%s: `--selmode' option given more than once%s\n",
1245 additional_error
: ""));
1248 if (args_info
->selmode_given
&& !override
)
1250 local_args_info
.selmode_given
= 1;
1251 args_info
->selmode_given
= 1;
1252 args_info
->selmode_arg
=
1253 strtol(optarg
, &stop_char
, 0);
1254 if (!(stop_char
&& *stop_char
== '\0')) {
1256 "%s: invalid numeric value: %s\n",
1260 if (args_info
->selmode_orig
)
1261 free(args_info
->selmode_orig
); /* free previous string */
1262 args_info
->selmode_orig
=
1263 gengetopt_strdup(optarg
);
1265 /* QoS Extension 1. */
1267 (long_options
[option_index
].name
,
1269 if (args_info
->qose1_given
) {
1271 "%s: `--qose1' option given more than once\n",
1275 args_info
->qose1_given
= 1;
1276 args_info
->qose1_arg
=
1277 strtoull(optarg
, &stop_char
, 0);
1278 if (!(stop_char
&& *stop_char
== '\0')) {
1280 "%s: invalid numeric value: %s\n",
1284 if (args_info
->qose1_orig
)
1285 free(args_info
->qose1_orig
); /* free previous string */
1286 args_info
->qose1_orig
=
1287 gengetopt_strdup(optarg
);
1290 /* QoS Extension 2. */
1292 (long_options
[option_index
].name
,
1294 if (args_info
->qose2_given
) {
1296 "%s: `--qose2' option given more than once\n",
1300 args_info
->qose2_given
= 1;
1301 args_info
->qose2_arg
=
1302 strtol(optarg
, &stop_char
, 0);
1303 if (!(stop_char
&& *stop_char
== '\0')) {
1305 "%s: invalid numeric value: %s\n",
1309 if (args_info
->qose2_orig
)
1310 free(args_info
->qose2_orig
); /* free previous string */
1311 args_info
->qose2_orig
=
1312 gengetopt_strdup(optarg
);
1315 /* QoS Extension 3. */
1317 (long_options
[option_index
].name
,
1319 if (args_info
->qose3_given
) {
1321 "%s: `--qose3' option given more than once\n",
1325 args_info
->qose3_given
= 1;
1326 args_info
->qose3_arg
=
1327 strtol(optarg
, &stop_char
, 0);
1328 if (!(stop_char
&& *stop_char
== '\0')) {
1330 "%s: invalid numeric value: %s\n",
1334 if (args_info
->qose3_orig
)
1335 free(args_info
->qose3_orig
); /* free previous string */
1336 args_info
->qose3_orig
=
1337 gengetopt_strdup(optarg
);
1340 /* QoS Extension 4. */
1342 (long_options
[option_index
].name
,
1344 if (args_info
->qose4_given
) {
1346 "%s: `--qose4' option given more than once\n",
1350 args_info
->qose4_given
= 1;
1351 args_info
->qose4_arg
=
1352 strtol(optarg
, &stop_char
, 0);
1353 if (!(stop_char
&& *stop_char
== '\0')) {
1355 "%s: invalid numeric value: %s\n",
1359 if (args_info
->qose4_orig
)
1360 free(args_info
->qose4_orig
); /* free previous string */
1361 args_info
->qose4_orig
=
1362 gengetopt_strdup(optarg
);
1365 /* Radio Access Technology Type. */
1367 (long_options
[option_index
].name
,
1369 if (args_info
->rattype_given
) {
1371 "%s: `--rattype' option given more than once\n",
1375 args_info
->rattype_given
= 1;
1376 /* args_info->rattype_arg = strtol (optarg,&stop_char,0); */
1377 args_info
->rattype_arg
= strdup(optarg
);
1380 /* User Location Information. */
1382 (long_options
[option_index
].name
,
1384 if (args_info
->userloc_given
) {
1386 "%s: `--userloc' option given more than once\n",
1390 args_info
->userloc_given
= 1;
1391 args_info
->userloc_arg
= strdup(optarg
);
1394 /* Routing Area Information. */
1395 else if (strcmp(long_options
[option_index
].name
, "rai")
1397 if (args_info
->rai_given
) {
1399 "%s: `--rai' option given more than once\n",
1403 args_info
->rai_given
= 1;
1404 args_info
->rai_arg
= strdup(optarg
);
1408 else if (strcmp(long_options
[option_index
].name
, "mstz")
1410 if (args_info
->mstz_given
) {
1412 "%s: `--mstz' option given more than once\n",
1416 args_info
->mstz_given
= 1;
1417 args_info
->mstz_arg
= strdup(optarg
);
1422 (long_options
[option_index
].name
,
1424 if (args_info
->imeisv_given
) {
1426 "%s: `--imeisv' option given more than once\n",
1430 args_info
->imeisv_given
= 1;
1431 args_info
->imeisv_arg
= strdup(optarg
);
1436 (long_options
[option_index
].name
,
1438 if (local_args_info
.nsapi_given
) {
1440 "%s: `--nsapi' option given more than once%s\n",
1443 additional_error
: ""));
1446 if (args_info
->nsapi_given
&& !override
)
1448 local_args_info
.nsapi_given
= 1;
1449 args_info
->nsapi_given
= 1;
1450 args_info
->nsapi_arg
=
1451 strtol(optarg
, &stop_char
, 0);
1452 if (!(stop_char
&& *stop_char
== '\0')) {
1454 "%s: invalid numeric value: %s\n",
1458 if (args_info
->nsapi_orig
)
1459 free(args_info
->nsapi_orig
); /* free previous string */
1460 args_info
->nsapi_orig
=
1461 gengetopt_strdup(optarg
);
1463 /* Charging characteristics. */
1465 (long_options
[option_index
].name
,
1467 if (local_args_info
.charging_given
) {
1469 "%s: `--charging' option given more than once%s\n",
1472 additional_error
: ""));
1475 if (args_info
->charging_given
&& !override
)
1477 local_args_info
.charging_given
= 1;
1478 args_info
->charging_given
= 1;
1479 args_info
->charging_arg
=
1480 strtol(optarg
, &stop_char
, 0);
1481 if (!(stop_char
&& *stop_char
== '\0')) {
1483 "%s: invalid numeric value: %s\n",
1487 if (args_info
->charging_orig
)
1488 free(args_info
->charging_orig
); /* free previous string */
1489 args_info
->charging_orig
=
1490 gengetopt_strdup(optarg
);
1492 /* Create local network interface. */
1494 (long_options
[option_index
].name
,
1496 if (local_args_info
.createif_given
) {
1498 "%s: `--createif' option given more than once%s\n",
1501 additional_error
: ""));
1504 if (args_info
->createif_given
&& !override
)
1506 local_args_info
.createif_given
= 1;
1507 args_info
->createif_given
= 1;
1508 args_info
->createif_flag
=
1509 !(args_info
->createif_flag
);
1511 /* Create default route. */
1513 (long_options
[option_index
].name
,
1514 "defaultroute") == 0) {
1515 if (local_args_info
.defaultroute_given
) {
1517 "%s: `--defaultroute' option given more than once%s\n",
1520 additional_error
: ""));
1523 if (args_info
->defaultroute_given
&& !override
)
1525 local_args_info
.defaultroute_given
= 1;
1526 args_info
->defaultroute_given
= 1;
1527 args_info
->defaultroute_flag
=
1528 !(args_info
->defaultroute_flag
);
1530 /* Script to run after link-up. */
1531 else if (strcmp(long_options
[option_index
].name
, "ipup")
1533 if (local_args_info
.ipup_given
) {
1535 "%s: `--ipup' option given more than once%s\n",
1538 additional_error
: ""));
1541 if (args_info
->ipup_given
&& !override
)
1543 local_args_info
.ipup_given
= 1;
1544 args_info
->ipup_given
= 1;
1545 if (args_info
->ipup_arg
)
1546 free(args_info
->ipup_arg
); /* free previous string */
1547 args_info
->ipup_arg
= gengetopt_strdup(optarg
);
1548 if (args_info
->ipup_orig
)
1549 free(args_info
->ipup_orig
); /* free previous string */
1550 args_info
->ipup_orig
= gengetopt_strdup(optarg
);
1552 /* Script to run after link-down. */
1554 (long_options
[option_index
].name
,
1556 if (local_args_info
.ipdown_given
) {
1558 "%s: `--ipdown' option given more than once%s\n",
1561 additional_error
: ""));
1564 if (args_info
->ipdown_given
&& !override
)
1566 local_args_info
.ipdown_given
= 1;
1567 args_info
->ipdown_given
= 1;
1568 if (args_info
->ipdown_arg
)
1569 free(args_info
->ipdown_arg
); /* free previous string */
1570 args_info
->ipdown_arg
=
1571 gengetopt_strdup(optarg
);
1572 if (args_info
->ipdown_orig
)
1573 free(args_info
->ipdown_orig
); /* free previous string */
1574 args_info
->ipdown_orig
=
1575 gengetopt_strdup(optarg
);
1577 /* Ping remote host. */
1579 (long_options
[option_index
].name
,
1581 if (local_args_info
.pinghost_given
) {
1583 "%s: `--pinghost' option given more than once%s\n",
1586 additional_error
: ""));
1589 if (args_info
->pinghost_given
&& !override
)
1591 local_args_info
.pinghost_given
= 1;
1592 args_info
->pinghost_given
= 1;
1593 if (args_info
->pinghost_arg
)
1594 free(args_info
->pinghost_arg
); /* free previous string */
1595 args_info
->pinghost_arg
=
1596 gengetopt_strdup(optarg
);
1597 if (args_info
->pinghost_orig
)
1598 free(args_info
->pinghost_orig
); /* free previous string */
1599 args_info
->pinghost_orig
=
1600 gengetopt_strdup(optarg
);
1602 /* Number of ping req per second. */
1604 (long_options
[option_index
].name
,
1606 if (local_args_info
.pingrate_given
) {
1608 "%s: `--pingrate' option given more than once%s\n",
1611 additional_error
: ""));
1614 if (args_info
->pingrate_given
&& !override
)
1616 local_args_info
.pingrate_given
= 1;
1617 args_info
->pingrate_given
= 1;
1618 args_info
->pingrate_arg
=
1619 strtol(optarg
, &stop_char
, 0);
1620 if (!(stop_char
&& *stop_char
== '\0')) {
1622 "%s: invalid numeric value: %s\n",
1626 if (args_info
->pingrate_orig
)
1627 free(args_info
->pingrate_orig
); /* free previous string */
1628 args_info
->pingrate_orig
=
1629 gengetopt_strdup(optarg
);
1631 /* Number of ping data bytes. */
1633 (long_options
[option_index
].name
,
1635 if (local_args_info
.pingsize_given
) {
1637 "%s: `--pingsize' option given more than once%s\n",
1640 additional_error
: ""));
1643 if (args_info
->pingsize_given
&& !override
)
1645 local_args_info
.pingsize_given
= 1;
1646 args_info
->pingsize_given
= 1;
1647 args_info
->pingsize_arg
=
1648 strtol(optarg
, &stop_char
, 0);
1649 if (!(stop_char
&& *stop_char
== '\0')) {
1651 "%s: invalid numeric value: %s\n",
1655 if (args_info
->pingsize_orig
)
1656 free(args_info
->pingsize_orig
); /* free previous string */
1657 args_info
->pingsize_orig
=
1658 gengetopt_strdup(optarg
);
1660 /* Number of ping req to send. */
1662 (long_options
[option_index
].name
,
1663 "pingcount") == 0) {
1664 if (local_args_info
.pingcount_given
) {
1666 "%s: `--pingcount' option given more than once%s\n",
1669 additional_error
: ""));
1672 if (args_info
->pingcount_given
&& !override
)
1674 local_args_info
.pingcount_given
= 1;
1675 args_info
->pingcount_given
= 1;
1676 args_info
->pingcount_arg
=
1677 strtol(optarg
, &stop_char
, 0);
1678 if (!(stop_char
&& *stop_char
== '\0')) {
1680 "%s: invalid numeric value: %s\n",
1684 if (args_info
->pingcount_orig
)
1685 free(args_info
->pingcount_orig
); /* free previous string */
1686 args_info
->pingcount_orig
=
1687 gengetopt_strdup(optarg
);
1689 /* Do not print ping packet info. */
1691 (long_options
[option_index
].name
,
1692 "pingquiet") == 0) {
1693 if (local_args_info
.pingquiet_given
) {
1695 "%s: `--pingquiet' option given more than once%s\n",
1698 additional_error
: ""));
1701 if (args_info
->pingquiet_given
&& !override
)
1703 local_args_info
.pingquiet_given
= 1;
1704 args_info
->pingquiet_given
= 1;
1705 args_info
->pingquiet_flag
=
1706 !(args_info
->pingquiet_flag
);
1708 /* Do not send recovery. */
1710 (long_options
[option_index
].name
,
1711 "norecovery") == 0) {
1712 if (local_args_info
.norecovery_given
) {
1714 "%s: `--norecovery' option given more than once%s\n",
1717 additional_error
: ""));
1720 if (args_info
->norecovery_given
&& !override
)
1722 local_args_info
.norecovery_given
= 1;
1723 args_info
->norecovery_given
= 1;
1724 args_info
->norecovery_flag
=
1725 !(args_info
->norecovery_flag
);
1729 case '?': /* Invalid option. */
1730 /* `getopt_long' already printed an error message. */
1733 default: /* bug: option not considered. */
1734 fprintf(stderr
, "%s: option unknown: %c%s\n",
1735 CMDLINE_PARSER_PACKAGE
, c
,
1736 (additional_error
? additional_error
: ""));
1741 cmdline_parser_release(&local_args_info
);
1744 return (EXIT_FAILURE
);
1750 cmdline_parser_release(&local_args_info
);
1751 return (EXIT_FAILURE
);
1754 #ifndef CONFIG_FILE_LINE_SIZE
1755 #define CONFIG_FILE_LINE_SIZE 2048
1757 #define ADDITIONAL_ERROR " in configuration file "
1759 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1760 /* 3 is for "--" and "=" */
1762 char my_argv
[CONFIG_FILE_LINE_BUFFER_SIZE
+ 1];
1765 cmdline_parser_configfile(char *const filename
,
1766 struct gengetopt_args_info
*args_info
, int override
,
1767 int initialize
, int check_required
)
1770 char linebuf
[CONFIG_FILE_LINE_SIZE
];
1772 int i
, result
, equal
;
1775 size_t len
, next_token
;
1779 char *additional_error
;
1781 /* store the program name */
1783 (struct line_list
*)malloc(sizeof(struct line_list
));
1784 cmd_line_list_tmp
->next
= cmd_line_list
;
1785 cmd_line_list
= cmd_line_list_tmp
;
1786 cmd_line_list
->string_arg
= gengetopt_strdup(CMDLINE_PARSER_PACKAGE
);
1788 if ((file
= fopen(filename
, "r")) == NULL
) {
1789 fprintf(stderr
, "%s: Error opening configuration file '%s'\n",
1790 CMDLINE_PARSER_PACKAGE
, filename
);
1791 result
= EXIT_FAILURE
;
1795 while ((fgets(linebuf
, CONFIG_FILE_LINE_SIZE
, file
)) != NULL
) {
1798 len
= strlen(linebuf
);
1799 if (len
> (CONFIG_FILE_LINE_BUFFER_SIZE
- 1)) {
1801 "%s:%s:%d: Line too long in configuration file\n",
1802 CMDLINE_PARSER_PACKAGE
, filename
, line_num
);
1803 result
= EXIT_FAILURE
;
1807 /* find first non-whitespace character in the line */
1808 next_token
= strspn(linebuf
, " \t\r\n");
1809 str_index
= linebuf
+ next_token
;
1811 if (str_index
[0] == '\0' || str_index
[0] == '#')
1812 continue; /* empty line or comment line is skipped */
1816 /* truncate fopt at the end of the first non-valid character */
1817 next_token
= strcspn(fopt
, " \t\r\n=");
1819 if (fopt
[next_token
] == '\0') { /* the line is over */
1825 /* remember if equal sign is present */
1826 equal
= (fopt
[next_token
] == '=');
1827 fopt
[next_token
++] = '\0';
1829 /* advance pointers to the next token after the end of fopt */
1830 next_token
+= strspn(fopt
+ next_token
, " \t\r\n");
1831 /* check for the presence of equal sign, and if so, skip it */
1833 if ((equal
= (fopt
[next_token
] == '='))) {
1836 strspn(fopt
+ next_token
, " \t\r\n");
1838 str_index
+= next_token
;
1842 if (farg
[0] == '\"' || farg
[0] == '\'') { /* quoted argument */
1843 str_index
= strchr(++farg
, str_index
[0]); /* skip opening quote */
1847 "%s:%s:%d: unterminated string in configuration file\n",
1848 CMDLINE_PARSER_PACKAGE
, filename
,
1850 result
= EXIT_FAILURE
;
1853 } else { /* read up the remaining part up to a delimiter */
1854 next_token
= strcspn(farg
, " \t\r\n#\'\"");
1855 str_index
+= next_token
;
1858 /* truncate farg at the delimiter and store it for further check */
1859 delimiter
= *str_index
, *str_index
++ = '\0';
1861 /* everything but comment is illegal at the end of line */
1862 if (delimiter
!= '\0' && delimiter
!= '#') {
1863 str_index
+= strspn(str_index
, " \t\r\n");
1864 if (*str_index
!= '\0' && *str_index
!= '#') {
1867 "%s:%s:%d: malformed string in configuration file\n",
1868 CMDLINE_PARSER_PACKAGE
, filename
,
1870 result
= EXIT_FAILURE
;
1879 strcat(my_argv
, len
> 1 ? "--" : "-");
1880 strcat(my_argv
, fopt
);
1881 if (len
> 1 && ((farg
&& *farg
) || equal
))
1882 strcat(my_argv
, "=");
1884 strcat(my_argv
, farg
);
1887 (struct line_list
*)malloc(sizeof(struct line_list
));
1888 cmd_line_list_tmp
->next
= cmd_line_list
;
1889 cmd_line_list
= cmd_line_list_tmp
;
1890 cmd_line_list
->string_arg
= gengetopt_strdup(my_argv
);
1893 ++my_argc
; /* for program name */
1894 my_argv_arg
= (char **)malloc((my_argc
+ 1) * sizeof(char *));
1895 cmd_line_list_tmp
= cmd_line_list
;
1896 for (i
= my_argc
- 1; i
>= 0; --i
) {
1897 my_argv_arg
[i
] = cmd_line_list_tmp
->string_arg
;
1898 cmd_line_list_tmp
= cmd_line_list_tmp
->next
;
1900 my_argv_arg
[my_argc
] = 0;
1903 (char *)malloc(strlen(filename
) + strlen(ADDITIONAL_ERROR
) + 1);
1904 strcpy(additional_error
, ADDITIONAL_ERROR
);
1905 strcat(additional_error
, filename
);
1907 cmdline_parser_internal(my_argc
, my_argv_arg
, args_info
, override
,
1908 initialize
, check_required
,
1911 free(additional_error
);
1919 if (result
== EXIT_FAILURE
) {
1920 cmdline_parser_free(args_info
);