blob: 836e1600f324f4cabc675d5a5288bfbc2dbdfc35 [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
jjako5da68452003-01-28 16:08:47 +00002 File autogenerated by gengetopt version 2.8rc
jjako52c24142002-12-16 13:33:51 +00003 generated with the following command:
jjako5da68452003-01-28 16:08:47 +00004 ../../gengetopt-2.8rc/src/gengetopt --conf-parser
jjako52c24142002-12-16 13:33:51 +00005
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.
9*/
10
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15/* If we use autoconf. */
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19/* Check for configure's getopt check result. */
20#ifndef HAVE_GETOPT_LONG
21#include "getopt.h"
22#else
23#include <getopt.h>
24#endif
25
26#ifndef HAVE_STRDUP
27#define strdup gengetopt_strdup
28#endif /* HAVE_STRDUP */
29
30#include "cmdline.h"
31
32
33void
34cmdline_parser_print_version (void)
35{
36 printf ("%s %s\n", PACKAGE, VERSION);
37}
38
39void
40cmdline_parser_print_help (void)
41{
42 cmdline_parser_print_version ();
43 printf("\n"
44 "Usage: %s [OPTIONS]...\n", PACKAGE);
45 printf(" -h --help Print help and exit\n");
46 printf(" -V --version Print version and exit\n");
47 printf(" -f --fg Run in foreground (default=off)\n");
48 printf(" -d --debug Run in debug mode (default=off)\n");
49 printf(" -cSTRING --conf=STRING Read configuration file\n");
50 printf(" --pidfile=STRING Filename of process id file (default='./sgsnemu.pid')\n");
51 printf(" --statedir=STRING Directory of nonvolatile data (default='./')\n");
52 printf(" --dns=STRING DNS Server to use\n");
53 printf(" -lSTRING --listen=STRING Local interface\n");
54 printf(" -rSTRING --remote=STRING Remote host\n");
jjako52c24142002-12-16 13:33:51 +000055 printf(" --contexts=INT Number of contexts (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000056 printf(" --timelimit=INT Exit after timelimit seconds (default='0')\n");
57 printf(" -aSTRING --apn=STRING Access point name (default='internet')\n");
58 printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n");
59 printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n");
60 printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n");
61 printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n");
62 printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n");
jjako5da68452003-01-28 16:08:47 +000063 printf(" --createif Create local network interface (default=off)\n");
64 printf(" --ipup=STRING Script to run after link-up\n");
65 printf(" --ipdown=STRING Script to run after link-down\n");
66 printf(" --defaultroute Add default route after link-up (default=off)\n");
67 printf(" --net=STRING Network (default='0.0.0.0')\n");
68 printf(" --mask=STRING Network mask (default='0.0.0.0')\n");
69 printf(" --pinghost=STRING Ping remote host\n");
70 printf(" --pingrate=INT Number of ping req per second (default='1')\n");
71 printf(" --pingsize=INT Number of ping data bytes (default='56')\n");
72 printf(" --pingcount=INT Number of ping req to send (default='0')\n");
73 printf(" --pingquiet Do not print ping packet info (default=off)\n");
jjako52c24142002-12-16 13:33:51 +000074}
75
76
77#ifndef HAVE_STRDUP
78/* gengetopt_strdup(): automatically generated from strdup.c. */
79/* strdup.c replacement of strdup, which is not standard */
80static char *
81gengetopt_strdup (const char *s)
82{
83 char *result = (char*)malloc(strlen(s) + 1);
84 if (result == (char*)0)
85 return (char*)0;
86 strcpy(result, s);
87 return result;
88}
89#endif /* HAVE_STRDUP */
90
91int
92cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
93{
94 int c; /* Character of the parsed option. */
95 int missing_required_options = 0;
96
97 args_info->help_given = 0 ;
98 args_info->version_given = 0 ;
99 args_info->fg_given = 0 ;
100 args_info->debug_given = 0 ;
101 args_info->conf_given = 0 ;
102 args_info->pidfile_given = 0 ;
103 args_info->statedir_given = 0 ;
104 args_info->dns_given = 0 ;
105 args_info->listen_given = 0 ;
106 args_info->remote_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000107 args_info->contexts_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000108 args_info->timelimit_given = 0 ;
109 args_info->apn_given = 0 ;
110 args_info->imsi_given = 0 ;
111 args_info->msisdn_given = 0 ;
112 args_info->qos_given = 0 ;
113 args_info->uid_given = 0 ;
114 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000115 args_info->createif_given = 0 ;
116 args_info->ipup_given = 0 ;
117 args_info->ipdown_given = 0 ;
118 args_info->defaultroute_given = 0 ;
119 args_info->net_given = 0 ;
120 args_info->mask_given = 0 ;
121 args_info->pinghost_given = 0 ;
122 args_info->pingrate_given = 0 ;
123 args_info->pingsize_given = 0 ;
124 args_info->pingcount_given = 0 ;
125 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000126#define clear_args() { \
127 args_info->fg_flag = 0;\
128 args_info->debug_flag = 0;\
129 args_info->conf_arg = NULL; \
130 args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
131 args_info->statedir_arg = strdup("./") ;\
132 args_info->dns_arg = NULL; \
133 args_info->listen_arg = NULL; \
134 args_info->remote_arg = NULL; \
jjako52c24142002-12-16 13:33:51 +0000135 args_info->contexts_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000136 args_info->timelimit_arg = 0 ;\
137 args_info->apn_arg = strdup("internet") ;\
138 args_info->imsi_arg = strdup("240010123456789") ;\
139 args_info->msisdn_arg = strdup("46702123456") ;\
140 args_info->qos_arg = 0x0b921f ;\
141 args_info->uid_arg = strdup("mig") ;\
142 args_info->pwd_arg = strdup("hemmelig") ;\
jjako5da68452003-01-28 16:08:47 +0000143 args_info->createif_flag = 0;\
144 args_info->ipup_arg = NULL; \
145 args_info->ipdown_arg = NULL; \
146 args_info->defaultroute_flag = 0;\
147 args_info->net_arg = strdup("0.0.0.0") ;\
148 args_info->mask_arg = strdup("0.0.0.0") ;\
149 args_info->pinghost_arg = NULL; \
150 args_info->pingrate_arg = 1 ;\
151 args_info->pingsize_arg = 56 ;\
152 args_info->pingcount_arg = 0 ;\
153 args_info->pingquiet_flag = 0;\
jjako52c24142002-12-16 13:33:51 +0000154}
155
156 clear_args();
157
158 optarg = 0;
159 optind = 1;
160 opterr = 1;
161 optopt = '?';
162
163 while (1)
164 {
165 int option_index = 0;
166 char *stop_char;
167 static struct option long_options[] = {
168 { "help", 0, NULL, 'h' },
169 { "version", 0, NULL, 'V' },
170 { "fg", 0, NULL, 'f' },
171 { "debug", 0, NULL, 'd' },
172 { "conf", 1, NULL, 'c' },
173 { "pidfile", 1, NULL, 0 },
174 { "statedir", 1, NULL, 0 },
175 { "dns", 1, NULL, 0 },
176 { "listen", 1, NULL, 'l' },
177 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000178 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000179 { "timelimit", 1, NULL, 0 },
180 { "apn", 1, NULL, 'a' },
181 { "imsi", 1, NULL, 'i' },
182 { "msisdn", 1, NULL, 'm' },
183 { "qos", 1, NULL, 'q' },
184 { "uid", 1, NULL, 'u' },
185 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000186 { "createif", 0, NULL, 0 },
187 { "ipup", 1, NULL, 0 },
188 { "ipdown", 1, NULL, 0 },
189 { "defaultroute", 0, NULL, 0 },
190 { "net", 1, NULL, 0 },
191 { "mask", 1, NULL, 0 },
192 { "pinghost", 1, NULL, 0 },
193 { "pingrate", 1, NULL, 0 },
194 { "pingsize", 1, NULL, 0 },
195 { "pingcount", 1, NULL, 0 },
196 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000197 { NULL, 0, NULL, 0 }
198 };
199
jjako5da68452003-01-28 16:08:47 +0000200 c = getopt_long (argc, argv, "hVfdc:l:r:a:i:m:q:u:p:", long_options, &option_index);
jjako52c24142002-12-16 13:33:51 +0000201
202 if (c == -1) break; /* Exit from `while (1)' loop. */
203
204 switch (c)
205 {
206 case 'h': /* Print help and exit. */
207 clear_args ();
208 cmdline_parser_print_help ();
209 exit (EXIT_SUCCESS);
210
211 case 'V': /* Print version and exit. */
212 clear_args ();
213 cmdline_parser_print_version ();
214 exit (EXIT_SUCCESS);
215
216 case 'f': /* Run in foreground. */
217 if (args_info->fg_given)
218 {
219 fprintf (stderr, "%s: `--fg' (`-f') option given more than once\n", PACKAGE);
220 clear_args ();
221 exit (EXIT_FAILURE);
222 }
223 args_info->fg_given = 1;
224 args_info->fg_flag = !(args_info->fg_flag);
225 break;
226
227 case 'd': /* Run in debug mode. */
228 if (args_info->debug_given)
229 {
230 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
231 clear_args ();
232 exit (EXIT_FAILURE);
233 }
234 args_info->debug_given = 1;
235 args_info->debug_flag = !(args_info->debug_flag);
236 break;
237
238 case 'c': /* Read configuration file. */
239 if (args_info->conf_given)
240 {
241 fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
242 clear_args ();
243 exit (EXIT_FAILURE);
244 }
245 args_info->conf_given = 1;
246 args_info->conf_arg = strdup (optarg);
247 break;
248
249 case 'l': /* Local interface. */
250 if (args_info->listen_given)
251 {
252 fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
253 clear_args ();
254 exit (EXIT_FAILURE);
255 }
256 args_info->listen_given = 1;
257 args_info->listen_arg = strdup (optarg);
258 break;
259
260 case 'r': /* Remote host. */
261 if (args_info->remote_given)
262 {
263 fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
264 clear_args ();
265 exit (EXIT_FAILURE);
266 }
267 args_info->remote_given = 1;
268 args_info->remote_arg = strdup (optarg);
269 break;
270
jjako52c24142002-12-16 13:33:51 +0000271 case 'a': /* Access point name. */
272 if (args_info->apn_given)
273 {
274 fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
275 clear_args ();
276 exit (EXIT_FAILURE);
277 }
278 args_info->apn_given = 1;
279 args_info->apn_arg = strdup (optarg);
280 break;
281
282 case 'i': /* IMSI. */
283 if (args_info->imsi_given)
284 {
285 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
286 clear_args ();
287 exit (EXIT_FAILURE);
288 }
289 args_info->imsi_given = 1;
290 args_info->imsi_arg = strdup (optarg);
291 break;
292
293 case 'm': /* Mobile Station ISDN number. */
294 if (args_info->msisdn_given)
295 {
296 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
297 clear_args ();
298 exit (EXIT_FAILURE);
299 }
300 args_info->msisdn_given = 1;
301 args_info->msisdn_arg = strdup (optarg);
302 break;
303
304 case 'q': /* Requested quality of service. */
305 if (args_info->qos_given)
306 {
307 fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
308 clear_args ();
309 exit (EXIT_FAILURE);
310 }
311 args_info->qos_given = 1;
312 args_info->qos_arg = strtol (optarg,&stop_char,0);
313 break;
314
315 case 'u': /* Login user ID. */
316 if (args_info->uid_given)
317 {
318 fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
319 clear_args ();
320 exit (EXIT_FAILURE);
321 }
322 args_info->uid_given = 1;
323 args_info->uid_arg = strdup (optarg);
324 break;
325
326 case 'p': /* Login password. */
327 if (args_info->pwd_given)
328 {
329 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
330 clear_args ();
331 exit (EXIT_FAILURE);
332 }
333 args_info->pwd_given = 1;
334 args_info->pwd_arg = strdup (optarg);
335 break;
336
337
338 case 0: /* Long option with no short option */
339 /* Filename of process id file. */
340 if (strcmp (long_options[option_index].name, "pidfile") == 0)
341 {
342 if (args_info->pidfile_given)
343 {
344 fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
345 clear_args ();
346 exit (EXIT_FAILURE);
347 }
348 args_info->pidfile_given = 1;
349 args_info->pidfile_arg = strdup (optarg);
350 break;
351 }
352 /* Directory of nonvolatile data. */
353 else if (strcmp (long_options[option_index].name, "statedir") == 0)
354 {
355 if (args_info->statedir_given)
356 {
357 fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
358 clear_args ();
359 exit (EXIT_FAILURE);
360 }
361 args_info->statedir_given = 1;
362 args_info->statedir_arg = strdup (optarg);
363 break;
364 }
365 /* DNS Server to use. */
366 else if (strcmp (long_options[option_index].name, "dns") == 0)
367 {
368 if (args_info->dns_given)
369 {
370 fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
371 clear_args ();
372 exit (EXIT_FAILURE);
373 }
374 args_info->dns_given = 1;
375 args_info->dns_arg = strdup (optarg);
376 break;
377 }
jjako52c24142002-12-16 13:33:51 +0000378 /* Number of contexts. */
379 else if (strcmp (long_options[option_index].name, "contexts") == 0)
380 {
381 if (args_info->contexts_given)
382 {
383 fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
384 clear_args ();
385 exit (EXIT_FAILURE);
386 }
387 args_info->contexts_given = 1;
388 args_info->contexts_arg = strtol (optarg,&stop_char,0);
389 break;
390 }
jjako52c24142002-12-16 13:33:51 +0000391 /* Exit after timelimit seconds. */
392 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
393 {
394 if (args_info->timelimit_given)
395 {
396 fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
397 clear_args ();
398 exit (EXIT_FAILURE);
399 }
400 args_info->timelimit_given = 1;
401 args_info->timelimit_arg = strtol (optarg,&stop_char,0);
402 break;
403 }
jjako5da68452003-01-28 16:08:47 +0000404 /* Create local network interface. */
405 else if (strcmp (long_options[option_index].name, "createif") == 0)
406 {
407 if (args_info->createif_given)
408 {
409 fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
410 clear_args ();
411 exit (EXIT_FAILURE);
412 }
413 args_info->createif_given = 1;
414 args_info->createif_flag = !(args_info->createif_flag);
415 break;
416 }
417 /* Script to run after link-up. */
418 else if (strcmp (long_options[option_index].name, "ipup") == 0)
419 {
420 if (args_info->ipup_given)
421 {
422 fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
423 clear_args ();
424 exit (EXIT_FAILURE);
425 }
426 args_info->ipup_given = 1;
427 args_info->ipup_arg = strdup (optarg);
428 break;
429 }
430 /* Script to run after link-down. */
431 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
432 {
433 if (args_info->ipdown_given)
434 {
435 fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
436 clear_args ();
437 exit (EXIT_FAILURE);
438 }
439 args_info->ipdown_given = 1;
440 args_info->ipdown_arg = strdup (optarg);
441 break;
442 }
443 /* Add default route after link-up. */
444 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
445 {
446 if (args_info->defaultroute_given)
447 {
448 fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
449 clear_args ();
450 exit (EXIT_FAILURE);
451 }
452 args_info->defaultroute_given = 1;
453 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
454 break;
455 }
456 /* Network. */
457 else if (strcmp (long_options[option_index].name, "net") == 0)
458 {
459 if (args_info->net_given)
460 {
461 fprintf (stderr, "%s: `--net' option given more than once\n", PACKAGE);
462 clear_args ();
463 exit (EXIT_FAILURE);
464 }
465 args_info->net_given = 1;
466 args_info->net_arg = strdup (optarg);
467 break;
468 }
469 /* Network mask. */
470 else if (strcmp (long_options[option_index].name, "mask") == 0)
471 {
472 if (args_info->mask_given)
473 {
474 fprintf (stderr, "%s: `--mask' option given more than once\n", PACKAGE);
475 clear_args ();
476 exit (EXIT_FAILURE);
477 }
478 args_info->mask_given = 1;
479 args_info->mask_arg = strdup (optarg);
480 break;
481 }
482 /* Ping remote host. */
483 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
484 {
485 if (args_info->pinghost_given)
486 {
487 fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
488 clear_args ();
489 exit (EXIT_FAILURE);
490 }
491 args_info->pinghost_given = 1;
492 args_info->pinghost_arg = strdup (optarg);
493 break;
494 }
495 /* Number of ping req per second. */
496 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
497 {
498 if (args_info->pingrate_given)
499 {
500 fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
501 clear_args ();
502 exit (EXIT_FAILURE);
503 }
504 args_info->pingrate_given = 1;
505 args_info->pingrate_arg = strtol (optarg,&stop_char,0);
506 break;
507 }
508 /* Number of ping data bytes. */
509 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
510 {
511 if (args_info->pingsize_given)
512 {
513 fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
514 clear_args ();
515 exit (EXIT_FAILURE);
516 }
517 args_info->pingsize_given = 1;
518 args_info->pingsize_arg = strtol (optarg,&stop_char,0);
519 break;
520 }
521 /* Number of ping req to send. */
522 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
523 {
524 if (args_info->pingcount_given)
525 {
526 fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
527 clear_args ();
528 exit (EXIT_FAILURE);
529 }
530 args_info->pingcount_given = 1;
531 args_info->pingcount_arg = strtol (optarg,&stop_char,0);
532 break;
533 }
534 /* Do not print ping packet info. */
535 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
536 {
537 if (args_info->pingquiet_given)
538 {
539 fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
540 clear_args ();
541 exit (EXIT_FAILURE);
542 }
543 args_info->pingquiet_given = 1;
544 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
545 break;
546 }
jjako52c24142002-12-16 13:33:51 +0000547
548 case '?': /* Invalid option. */
549 /* `getopt_long' already printed an error message. */
550 exit (EXIT_FAILURE);
551
552 default: /* bug: option not considered. */
553 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
554 abort ();
555 } /* switch */
556 } /* while */
557
558
559 if ( missing_required_options )
560 exit (EXIT_FAILURE);
561
562 return 0;
563}
564
565#define CONFIGPARSERBUFSIZE 1024
566
567int
568cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
569{
570 FILE* file;
571 char linebuf[CONFIGPARSERBUFSIZE];
572 int line_num = 0;
573 int len;
574 int fnum;
575 char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
576 char *stop_char;
577
578 if ((file = fopen(filename, "r")) == NULL)
579 {
580 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
581 PACKAGE, filename);
582 exit (EXIT_FAILURE);
583 }
584
585 while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
586 {
587 ++line_num;
588 len = strlen(linebuf);
589 if (len == CONFIGPARSERBUFSIZE-1)
590 {
591 fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
592 PACKAGE, CONFIGPARSERBUFSIZE, filename);
593 exit (EXIT_FAILURE);
594 }
595
596 if (linebuf[0] == '#')
597 continue; /* Line was a comment */
598
599 /* Get the option */
600 if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
601 {
602 if (!strcmp(fopt, "help"))
603 {
604 if (override || !args_info->help_given)
605 {
606 args_info->help_given = 1;
607
608 }
609 continue;
610 }
611 if (!strcmp(fopt, "version"))
612 {
613 if (override || !args_info->version_given)
614 {
615 args_info->version_given = 1;
616
617 }
618 continue;
619 }
620 if (!strcmp(fopt, "fg"))
621 {
622 if (override || !args_info->fg_given)
623 {
624 args_info->fg_given = 1;
625 args_info->fg_flag = !(args_info->fg_flag);
626 }
627 continue;
628 }
629 if (!strcmp(fopt, "debug"))
630 {
631 if (override || !args_info->debug_given)
632 {
633 args_info->debug_given = 1;
634 args_info->debug_flag = !(args_info->debug_flag);
635 }
636 continue;
637 }
638 if (!strcmp(fopt, "conf"))
639 {
640 if (override || !args_info->conf_given)
641 {
642 args_info->conf_given = 1;
643 if (fnum == 2)
644 args_info->conf_arg = strdup (farg);
645 else
646 {
647 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
648 filename, line_num);
649 exit (EXIT_FAILURE);
650 }
651 }
652 continue;
653 }
654 if (!strcmp(fopt, "pidfile"))
655 {
656 if (override || !args_info->pidfile_given)
657 {
658 args_info->pidfile_given = 1;
659 if (fnum == 2)
660 args_info->pidfile_arg = strdup (farg);
661 else
662 {
663 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
664 filename, line_num);
665 exit (EXIT_FAILURE);
666 }
667 }
668 continue;
669 }
670 if (!strcmp(fopt, "statedir"))
671 {
672 if (override || !args_info->statedir_given)
673 {
674 args_info->statedir_given = 1;
675 if (fnum == 2)
676 args_info->statedir_arg = strdup (farg);
677 else
678 {
679 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
680 filename, line_num);
681 exit (EXIT_FAILURE);
682 }
683 }
684 continue;
685 }
686 if (!strcmp(fopt, "dns"))
687 {
688 if (override || !args_info->dns_given)
689 {
690 args_info->dns_given = 1;
691 if (fnum == 2)
692 args_info->dns_arg = strdup (farg);
693 else
694 {
695 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
696 filename, line_num);
697 exit (EXIT_FAILURE);
698 }
699 }
700 continue;
701 }
702 if (!strcmp(fopt, "listen"))
703 {
704 if (override || !args_info->listen_given)
705 {
706 args_info->listen_given = 1;
707 if (fnum == 2)
708 args_info->listen_arg = strdup (farg);
709 else
710 {
711 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
712 filename, line_num);
713 exit (EXIT_FAILURE);
714 }
715 }
716 continue;
717 }
718 if (!strcmp(fopt, "remote"))
719 {
720 if (override || !args_info->remote_given)
721 {
722 args_info->remote_given = 1;
723 if (fnum == 2)
724 args_info->remote_arg = strdup (farg);
725 else
726 {
727 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
728 filename, line_num);
729 exit (EXIT_FAILURE);
730 }
731 }
732 continue;
733 }
jjako52c24142002-12-16 13:33:51 +0000734 if (!strcmp(fopt, "contexts"))
735 {
736 if (override || !args_info->contexts_given)
737 {
738 args_info->contexts_given = 1;
739 if (fnum == 2)
740 args_info->contexts_arg = strtol (farg,&stop_char,0);
741 else
742 {
743 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
744 filename, line_num);
745 exit (EXIT_FAILURE);
746 }
747 }
748 continue;
749 }
jjako52c24142002-12-16 13:33:51 +0000750 if (!strcmp(fopt, "timelimit"))
751 {
752 if (override || !args_info->timelimit_given)
753 {
754 args_info->timelimit_given = 1;
755 if (fnum == 2)
756 args_info->timelimit_arg = strtol (farg,&stop_char,0);
757 else
758 {
759 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
760 filename, line_num);
761 exit (EXIT_FAILURE);
762 }
763 }
764 continue;
765 }
766 if (!strcmp(fopt, "apn"))
767 {
768 if (override || !args_info->apn_given)
769 {
770 args_info->apn_given = 1;
771 if (fnum == 2)
772 args_info->apn_arg = strdup (farg);
773 else
774 {
775 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
776 filename, line_num);
777 exit (EXIT_FAILURE);
778 }
779 }
780 continue;
781 }
782 if (!strcmp(fopt, "imsi"))
783 {
784 if (override || !args_info->imsi_given)
785 {
786 args_info->imsi_given = 1;
787 if (fnum == 2)
788 args_info->imsi_arg = strdup (farg);
789 else
790 {
791 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
792 filename, line_num);
793 exit (EXIT_FAILURE);
794 }
795 }
796 continue;
797 }
798 if (!strcmp(fopt, "msisdn"))
799 {
800 if (override || !args_info->msisdn_given)
801 {
802 args_info->msisdn_given = 1;
803 if (fnum == 2)
804 args_info->msisdn_arg = strdup (farg);
805 else
806 {
807 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
808 filename, line_num);
809 exit (EXIT_FAILURE);
810 }
811 }
812 continue;
813 }
814 if (!strcmp(fopt, "qos"))
815 {
816 if (override || !args_info->qos_given)
817 {
818 args_info->qos_given = 1;
819 if (fnum == 2)
820 args_info->qos_arg = strtol (farg,&stop_char,0);
821 else
822 {
823 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
824 filename, line_num);
825 exit (EXIT_FAILURE);
826 }
827 }
828 continue;
829 }
830 if (!strcmp(fopt, "uid"))
831 {
832 if (override || !args_info->uid_given)
833 {
834 args_info->uid_given = 1;
835 if (fnum == 2)
836 args_info->uid_arg = strdup (farg);
837 else
838 {
839 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
840 filename, line_num);
841 exit (EXIT_FAILURE);
842 }
843 }
844 continue;
845 }
846 if (!strcmp(fopt, "pwd"))
847 {
848 if (override || !args_info->pwd_given)
849 {
850 args_info->pwd_given = 1;
851 if (fnum == 2)
852 args_info->pwd_arg = strdup (farg);
853 else
854 {
855 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
856 filename, line_num);
857 exit (EXIT_FAILURE);
858 }
859 }
860 continue;
861 }
jjako5da68452003-01-28 16:08:47 +0000862 if (!strcmp(fopt, "createif"))
863 {
864 if (override || !args_info->createif_given)
865 {
866 args_info->createif_given = 1;
867 args_info->createif_flag = !(args_info->createif_flag);
868 }
869 continue;
870 }
871 if (!strcmp(fopt, "ipup"))
872 {
873 if (override || !args_info->ipup_given)
874 {
875 args_info->ipup_given = 1;
876 if (fnum == 2)
877 args_info->ipup_arg = strdup (farg);
878 else
879 {
880 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
881 filename, line_num);
882 exit (EXIT_FAILURE);
883 }
884 }
885 continue;
886 }
887 if (!strcmp(fopt, "ipdown"))
888 {
889 if (override || !args_info->ipdown_given)
890 {
891 args_info->ipdown_given = 1;
892 if (fnum == 2)
893 args_info->ipdown_arg = strdup (farg);
894 else
895 {
896 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
897 filename, line_num);
898 exit (EXIT_FAILURE);
899 }
900 }
901 continue;
902 }
903 if (!strcmp(fopt, "defaultroute"))
904 {
905 if (override || !args_info->defaultroute_given)
906 {
907 args_info->defaultroute_given = 1;
908 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
909 }
910 continue;
911 }
912 if (!strcmp(fopt, "net"))
913 {
914 if (override || !args_info->net_given)
915 {
916 args_info->net_given = 1;
917 if (fnum == 2)
918 args_info->net_arg = strdup (farg);
919 else
920 {
921 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
922 filename, line_num);
923 exit (EXIT_FAILURE);
924 }
925 }
926 continue;
927 }
928 if (!strcmp(fopt, "mask"))
929 {
930 if (override || !args_info->mask_given)
931 {
932 args_info->mask_given = 1;
933 if (fnum == 2)
934 args_info->mask_arg = strdup (farg);
935 else
936 {
937 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
938 filename, line_num);
939 exit (EXIT_FAILURE);
940 }
941 }
942 continue;
943 }
944 if (!strcmp(fopt, "pinghost"))
945 {
946 if (override || !args_info->pinghost_given)
947 {
948 args_info->pinghost_given = 1;
949 if (fnum == 2)
950 args_info->pinghost_arg = strdup (farg);
951 else
952 {
953 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
954 filename, line_num);
955 exit (EXIT_FAILURE);
956 }
957 }
958 continue;
959 }
960 if (!strcmp(fopt, "pingrate"))
961 {
962 if (override || !args_info->pingrate_given)
963 {
964 args_info->pingrate_given = 1;
965 if (fnum == 2)
966 args_info->pingrate_arg = strtol (farg,&stop_char,0);
967 else
968 {
969 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
970 filename, line_num);
971 exit (EXIT_FAILURE);
972 }
973 }
974 continue;
975 }
976 if (!strcmp(fopt, "pingsize"))
977 {
978 if (override || !args_info->pingsize_given)
979 {
980 args_info->pingsize_given = 1;
981 if (fnum == 2)
982 args_info->pingsize_arg = strtol (farg,&stop_char,0);
983 else
984 {
985 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
986 filename, line_num);
987 exit (EXIT_FAILURE);
988 }
989 }
990 continue;
991 }
992 if (!strcmp(fopt, "pingcount"))
993 {
994 if (override || !args_info->pingcount_given)
995 {
996 args_info->pingcount_given = 1;
997 if (fnum == 2)
998 args_info->pingcount_arg = strtol (farg,&stop_char,0);
999 else
1000 {
1001 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1002 filename, line_num);
1003 exit (EXIT_FAILURE);
1004 }
1005 }
1006 continue;
1007 }
1008 if (!strcmp(fopt, "pingquiet"))
1009 {
1010 if (override || !args_info->pingquiet_given)
1011 {
1012 args_info->pingquiet_given = 1;
1013 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
1014 }
1015 continue;
1016 }
jjako52c24142002-12-16 13:33:51 +00001017
1018
1019 /* Tried all known options. This one is unknown! */
1020 fprintf (stderr, "%s: Unknown option '%s' found in %s\n",
1021 PACKAGE, fopt, filename);
1022 exit (EXIT_FAILURE);
1023 }
1024 } /* while */
1025 fclose(file); /* No error checking on close */
1026
1027 return 0;
1028}