blob: fa7ad7f684efff6b0bf0bf48897c9de907fc8e19 [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
jjakoa7cd2492003-04-11 09:40:12 +00002 File autogenerated by gengetopt version 2.8
jjako52c24142002-12-16 13:33:51 +00003 generated with the following command:
jjako7e051d32004-05-27 20:06:36 +00004 /mnt/hda5/bin/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");
jjako52c24142002-12-16 13:33:51 +000047 printf(" -d --debug Run in debug mode (default=off)\n");
48 printf(" -cSTRING --conf=STRING Read configuration file\n");
49 printf(" --pidfile=STRING Filename of process id file (default='./sgsnemu.pid')\n");
50 printf(" --statedir=STRING Directory of nonvolatile data (default='./')\n");
51 printf(" --dns=STRING DNS Server to use\n");
52 printf(" -lSTRING --listen=STRING Local interface\n");
53 printf(" -rSTRING --remote=STRING Remote host\n");
jjako52c24142002-12-16 13:33:51 +000054 printf(" --contexts=INT Number of contexts (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000055 printf(" --timelimit=INT Exit after timelimit seconds (default='0')\n");
jjako193e8b12003-11-10 12:31:41 +000056 printf(" --gtpversion=INT GTP version to use (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000057 printf(" -aSTRING --apn=STRING Access point name (default='internet')\n");
58 printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n");
jjako7e051d32004-05-27 20:06:36 +000059 printf(" --nsapi=INT NSAPI (default='0')\n");
jjako52c24142002-12-16 13:33:51 +000060 printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n");
61 printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n");
jjako7e051d32004-05-27 20:06:36 +000062 printf(" --charging=INT Charging characteristics (default='0x0800')\n");
jjako52c24142002-12-16 13:33:51 +000063 printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n");
64 printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n");
jjako5da68452003-01-28 16:08:47 +000065 printf(" --createif Create local network interface (default=off)\n");
jjako193e8b12003-11-10 12:31:41 +000066 printf(" -nSTRING --net=STRING Network address for local interface\n");
jjakoa7cd2492003-04-11 09:40:12 +000067 printf(" --defaultroute Create default route (default=off)\n");
jjako5da68452003-01-28 16:08:47 +000068 printf(" --ipup=STRING Script to run after link-up\n");
69 printf(" --ipdown=STRING Script to run after link-down\n");
jjako5da68452003-01-28 16:08:47 +000070 printf(" --pinghost=STRING Ping remote host\n");
71 printf(" --pingrate=INT Number of ping req per second (default='1')\n");
72 printf(" --pingsize=INT Number of ping data bytes (default='56')\n");
73 printf(" --pingcount=INT Number of ping req to send (default='0')\n");
74 printf(" --pingquiet Do not print ping packet info (default=off)\n");
jjako52c24142002-12-16 13:33:51 +000075}
76
77
78#ifndef HAVE_STRDUP
79/* gengetopt_strdup(): automatically generated from strdup.c. */
80/* strdup.c replacement of strdup, which is not standard */
81static char *
82gengetopt_strdup (const char *s)
83{
84 char *result = (char*)malloc(strlen(s) + 1);
85 if (result == (char*)0)
86 return (char*)0;
87 strcpy(result, s);
88 return result;
89}
90#endif /* HAVE_STRDUP */
91
92int
93cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
94{
95 int c; /* Character of the parsed option. */
96 int missing_required_options = 0;
97
98 args_info->help_given = 0 ;
99 args_info->version_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000100 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 ;
jjako193e8b12003-11-10 12:31:41 +0000109 args_info->gtpversion_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000110 args_info->apn_given = 0 ;
111 args_info->imsi_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000112 args_info->nsapi_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000113 args_info->msisdn_given = 0 ;
114 args_info->qos_given = 0 ;
jjako7e051d32004-05-27 20:06:36 +0000115 args_info->charging_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000116 args_info->uid_given = 0 ;
117 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000118 args_info->createif_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000119 args_info->net_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +0000120 args_info->defaultroute_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000121 args_info->ipup_given = 0 ;
122 args_info->ipdown_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000123 args_info->pinghost_given = 0 ;
124 args_info->pingrate_given = 0 ;
125 args_info->pingsize_given = 0 ;
126 args_info->pingcount_given = 0 ;
127 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000128#define clear_args() { \
jjako52c24142002-12-16 13:33:51 +0000129 args_info->debug_flag = 0;\
130 args_info->conf_arg = NULL; \
131 args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
132 args_info->statedir_arg = strdup("./") ;\
133 args_info->dns_arg = NULL; \
134 args_info->listen_arg = NULL; \
135 args_info->remote_arg = NULL; \
jjako52c24142002-12-16 13:33:51 +0000136 args_info->contexts_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000137 args_info->timelimit_arg = 0 ;\
jjako193e8b12003-11-10 12:31:41 +0000138 args_info->gtpversion_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000139 args_info->apn_arg = strdup("internet") ;\
140 args_info->imsi_arg = strdup("240010123456789") ;\
jjako7e051d32004-05-27 20:06:36 +0000141 args_info->nsapi_arg = 0 ;\
jjako52c24142002-12-16 13:33:51 +0000142 args_info->msisdn_arg = strdup("46702123456") ;\
143 args_info->qos_arg = 0x0b921f ;\
jjako7e051d32004-05-27 20:06:36 +0000144 args_info->charging_arg = 0x0800 ;\
jjako52c24142002-12-16 13:33:51 +0000145 args_info->uid_arg = strdup("mig") ;\
146 args_info->pwd_arg = strdup("hemmelig") ;\
jjako5da68452003-01-28 16:08:47 +0000147 args_info->createif_flag = 0;\
jjako193e8b12003-11-10 12:31:41 +0000148 args_info->net_arg = NULL; \
jjakoa7cd2492003-04-11 09:40:12 +0000149 args_info->defaultroute_flag = 0;\
jjako5da68452003-01-28 16:08:47 +0000150 args_info->ipup_arg = NULL; \
151 args_info->ipdown_arg = NULL; \
jjako5da68452003-01-28 16:08:47 +0000152 args_info->pinghost_arg = NULL; \
153 args_info->pingrate_arg = 1 ;\
154 args_info->pingsize_arg = 56 ;\
155 args_info->pingcount_arg = 0 ;\
156 args_info->pingquiet_flag = 0;\
jjako52c24142002-12-16 13:33:51 +0000157}
158
159 clear_args();
160
161 optarg = 0;
162 optind = 1;
163 opterr = 1;
164 optopt = '?';
165
166 while (1)
167 {
168 int option_index = 0;
169 char *stop_char;
170 static struct option long_options[] = {
171 { "help", 0, NULL, 'h' },
172 { "version", 0, NULL, 'V' },
jjako52c24142002-12-16 13:33:51 +0000173 { "debug", 0, NULL, 'd' },
174 { "conf", 1, NULL, 'c' },
175 { "pidfile", 1, NULL, 0 },
176 { "statedir", 1, NULL, 0 },
177 { "dns", 1, NULL, 0 },
178 { "listen", 1, NULL, 'l' },
179 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000180 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000181 { "timelimit", 1, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000182 { "gtpversion", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000183 { "apn", 1, NULL, 'a' },
184 { "imsi", 1, NULL, 'i' },
jjako193e8b12003-11-10 12:31:41 +0000185 { "nsapi", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000186 { "msisdn", 1, NULL, 'm' },
187 { "qos", 1, NULL, 'q' },
jjako7e051d32004-05-27 20:06:36 +0000188 { "charging", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000189 { "uid", 1, NULL, 'u' },
190 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000191 { "createif", 0, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000192 { "net", 1, NULL, 'n' },
jjakoa7cd2492003-04-11 09:40:12 +0000193 { "defaultroute", 0, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000194 { "ipup", 1, NULL, 0 },
195 { "ipdown", 1, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000196 { "pinghost", 1, NULL, 0 },
197 { "pingrate", 1, NULL, 0 },
198 { "pingsize", 1, NULL, 0 },
199 { "pingcount", 1, NULL, 0 },
200 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000201 { NULL, 0, NULL, 0 }
202 };
203
jjako193e8b12003-11-10 12:31:41 +0000204 c = getopt_long (argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:", long_options, &option_index);
jjako52c24142002-12-16 13:33:51 +0000205
206 if (c == -1) break; /* Exit from `while (1)' loop. */
207
208 switch (c)
209 {
210 case 'h': /* Print help and exit. */
211 clear_args ();
212 cmdline_parser_print_help ();
213 exit (EXIT_SUCCESS);
214
215 case 'V': /* Print version and exit. */
216 clear_args ();
217 cmdline_parser_print_version ();
218 exit (EXIT_SUCCESS);
219
jjako52c24142002-12-16 13:33:51 +0000220 case 'd': /* Run in debug mode. */
221 if (args_info->debug_given)
222 {
223 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
224 clear_args ();
225 exit (EXIT_FAILURE);
226 }
227 args_info->debug_given = 1;
228 args_info->debug_flag = !(args_info->debug_flag);
229 break;
230
231 case 'c': /* Read configuration file. */
232 if (args_info->conf_given)
233 {
234 fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
235 clear_args ();
236 exit (EXIT_FAILURE);
237 }
238 args_info->conf_given = 1;
239 args_info->conf_arg = strdup (optarg);
240 break;
241
242 case 'l': /* Local interface. */
243 if (args_info->listen_given)
244 {
245 fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
246 clear_args ();
247 exit (EXIT_FAILURE);
248 }
249 args_info->listen_given = 1;
250 args_info->listen_arg = strdup (optarg);
251 break;
252
253 case 'r': /* Remote host. */
254 if (args_info->remote_given)
255 {
256 fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
257 clear_args ();
258 exit (EXIT_FAILURE);
259 }
260 args_info->remote_given = 1;
261 args_info->remote_arg = strdup (optarg);
262 break;
263
jjako52c24142002-12-16 13:33:51 +0000264 case 'a': /* Access point name. */
265 if (args_info->apn_given)
266 {
267 fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
268 clear_args ();
269 exit (EXIT_FAILURE);
270 }
271 args_info->apn_given = 1;
272 args_info->apn_arg = strdup (optarg);
273 break;
274
275 case 'i': /* IMSI. */
276 if (args_info->imsi_given)
277 {
278 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
279 clear_args ();
280 exit (EXIT_FAILURE);
281 }
282 args_info->imsi_given = 1;
283 args_info->imsi_arg = strdup (optarg);
284 break;
285
286 case 'm': /* Mobile Station ISDN number. */
287 if (args_info->msisdn_given)
288 {
289 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
290 clear_args ();
291 exit (EXIT_FAILURE);
292 }
293 args_info->msisdn_given = 1;
294 args_info->msisdn_arg = strdup (optarg);
295 break;
296
297 case 'q': /* Requested quality of service. */
298 if (args_info->qos_given)
299 {
300 fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
301 clear_args ();
302 exit (EXIT_FAILURE);
303 }
304 args_info->qos_given = 1;
305 args_info->qos_arg = strtol (optarg,&stop_char,0);
306 break;
307
308 case 'u': /* Login user ID. */
309 if (args_info->uid_given)
310 {
311 fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
312 clear_args ();
313 exit (EXIT_FAILURE);
314 }
315 args_info->uid_given = 1;
316 args_info->uid_arg = strdup (optarg);
317 break;
318
319 case 'p': /* Login password. */
320 if (args_info->pwd_given)
321 {
322 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
323 clear_args ();
324 exit (EXIT_FAILURE);
325 }
326 args_info->pwd_given = 1;
327 args_info->pwd_arg = strdup (optarg);
328 break;
329
jjako193e8b12003-11-10 12:31:41 +0000330 case 'n': /* Network address for local interface. */
331 if (args_info->net_given)
332 {
333 fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE);
334 clear_args ();
335 exit (EXIT_FAILURE);
336 }
337 args_info->net_given = 1;
338 args_info->net_arg = strdup (optarg);
339 break;
340
jjako52c24142002-12-16 13:33:51 +0000341
342 case 0: /* Long option with no short option */
343 /* Filename of process id file. */
344 if (strcmp (long_options[option_index].name, "pidfile") == 0)
345 {
346 if (args_info->pidfile_given)
347 {
348 fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
349 clear_args ();
350 exit (EXIT_FAILURE);
351 }
352 args_info->pidfile_given = 1;
353 args_info->pidfile_arg = strdup (optarg);
354 break;
355 }
356 /* Directory of nonvolatile data. */
357 else if (strcmp (long_options[option_index].name, "statedir") == 0)
358 {
359 if (args_info->statedir_given)
360 {
361 fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
362 clear_args ();
363 exit (EXIT_FAILURE);
364 }
365 args_info->statedir_given = 1;
366 args_info->statedir_arg = strdup (optarg);
367 break;
368 }
369 /* DNS Server to use. */
370 else if (strcmp (long_options[option_index].name, "dns") == 0)
371 {
372 if (args_info->dns_given)
373 {
374 fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
375 clear_args ();
376 exit (EXIT_FAILURE);
377 }
378 args_info->dns_given = 1;
379 args_info->dns_arg = strdup (optarg);
380 break;
381 }
jjako52c24142002-12-16 13:33:51 +0000382 /* Number of contexts. */
383 else if (strcmp (long_options[option_index].name, "contexts") == 0)
384 {
385 if (args_info->contexts_given)
386 {
387 fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
388 clear_args ();
389 exit (EXIT_FAILURE);
390 }
391 args_info->contexts_given = 1;
392 args_info->contexts_arg = strtol (optarg,&stop_char,0);
393 break;
394 }
jjako52c24142002-12-16 13:33:51 +0000395 /* Exit after timelimit seconds. */
396 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
397 {
398 if (args_info->timelimit_given)
399 {
400 fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
401 clear_args ();
402 exit (EXIT_FAILURE);
403 }
404 args_info->timelimit_given = 1;
405 args_info->timelimit_arg = strtol (optarg,&stop_char,0);
406 break;
407 }
jjako193e8b12003-11-10 12:31:41 +0000408 /* GTP version to use. */
409 else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
410 {
411 if (args_info->gtpversion_given)
412 {
413 fprintf (stderr, "%s: `--gtpversion' option given more than once\n", PACKAGE);
414 clear_args ();
415 exit (EXIT_FAILURE);
416 }
417 args_info->gtpversion_given = 1;
418 args_info->gtpversion_arg = strtol (optarg,&stop_char,0);
419 break;
420 }
421 /* NSAPI. */
422 else if (strcmp (long_options[option_index].name, "nsapi") == 0)
423 {
424 if (args_info->nsapi_given)
425 {
426 fprintf (stderr, "%s: `--nsapi' option given more than once\n", PACKAGE);
427 clear_args ();
428 exit (EXIT_FAILURE);
429 }
430 args_info->nsapi_given = 1;
431 args_info->nsapi_arg = strtol (optarg,&stop_char,0);
432 break;
433 }
jjako7e051d32004-05-27 20:06:36 +0000434 /* Charging characteristics. */
435 else if (strcmp (long_options[option_index].name, "charging") == 0)
436 {
437 if (args_info->charging_given)
438 {
439 fprintf (stderr, "%s: `--charging' option given more than once\n", PACKAGE);
440 clear_args ();
441 exit (EXIT_FAILURE);
442 }
443 args_info->charging_given = 1;
444 args_info->charging_arg = strtol (optarg,&stop_char,0);
445 break;
446 }
jjako5da68452003-01-28 16:08:47 +0000447 /* Create local network interface. */
448 else if (strcmp (long_options[option_index].name, "createif") == 0)
449 {
450 if (args_info->createif_given)
451 {
452 fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
453 clear_args ();
454 exit (EXIT_FAILURE);
455 }
456 args_info->createif_given = 1;
457 args_info->createif_flag = !(args_info->createif_flag);
458 break;
459 }
jjakoa7cd2492003-04-11 09:40:12 +0000460 /* Create default route. */
461 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
462 {
463 if (args_info->defaultroute_given)
464 {
465 fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
466 clear_args ();
467 exit (EXIT_FAILURE);
468 }
469 args_info->defaultroute_given = 1;
470 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
471 break;
472 }
jjako5da68452003-01-28 16:08:47 +0000473 /* Script to run after link-up. */
474 else if (strcmp (long_options[option_index].name, "ipup") == 0)
475 {
476 if (args_info->ipup_given)
477 {
478 fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
479 clear_args ();
480 exit (EXIT_FAILURE);
481 }
482 args_info->ipup_given = 1;
483 args_info->ipup_arg = strdup (optarg);
484 break;
485 }
486 /* Script to run after link-down. */
487 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
488 {
489 if (args_info->ipdown_given)
490 {
491 fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
492 clear_args ();
493 exit (EXIT_FAILURE);
494 }
495 args_info->ipdown_given = 1;
496 args_info->ipdown_arg = strdup (optarg);
497 break;
498 }
jjako5da68452003-01-28 16:08:47 +0000499 /* Ping remote host. */
500 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
501 {
502 if (args_info->pinghost_given)
503 {
504 fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
505 clear_args ();
506 exit (EXIT_FAILURE);
507 }
508 args_info->pinghost_given = 1;
509 args_info->pinghost_arg = strdup (optarg);
510 break;
511 }
512 /* Number of ping req per second. */
513 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
514 {
515 if (args_info->pingrate_given)
516 {
517 fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
518 clear_args ();
519 exit (EXIT_FAILURE);
520 }
521 args_info->pingrate_given = 1;
522 args_info->pingrate_arg = strtol (optarg,&stop_char,0);
523 break;
524 }
525 /* Number of ping data bytes. */
526 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
527 {
528 if (args_info->pingsize_given)
529 {
530 fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
531 clear_args ();
532 exit (EXIT_FAILURE);
533 }
534 args_info->pingsize_given = 1;
535 args_info->pingsize_arg = strtol (optarg,&stop_char,0);
536 break;
537 }
538 /* Number of ping req to send. */
539 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
540 {
541 if (args_info->pingcount_given)
542 {
543 fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
544 clear_args ();
545 exit (EXIT_FAILURE);
546 }
547 args_info->pingcount_given = 1;
548 args_info->pingcount_arg = strtol (optarg,&stop_char,0);
549 break;
550 }
551 /* Do not print ping packet info. */
552 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
553 {
554 if (args_info->pingquiet_given)
555 {
556 fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
557 clear_args ();
558 exit (EXIT_FAILURE);
559 }
560 args_info->pingquiet_given = 1;
561 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
562 break;
563 }
jjako52c24142002-12-16 13:33:51 +0000564
565 case '?': /* Invalid option. */
566 /* `getopt_long' already printed an error message. */
567 exit (EXIT_FAILURE);
568
569 default: /* bug: option not considered. */
570 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
571 abort ();
572 } /* switch */
573 } /* while */
574
575
576 if ( missing_required_options )
577 exit (EXIT_FAILURE);
578
579 return 0;
580}
581
582#define CONFIGPARSERBUFSIZE 1024
583
584int
585cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
586{
587 FILE* file;
588 char linebuf[CONFIGPARSERBUFSIZE];
589 int line_num = 0;
590 int len;
591 int fnum;
592 char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
593 char *stop_char;
594
595 if ((file = fopen(filename, "r")) == NULL)
596 {
597 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
598 PACKAGE, filename);
599 exit (EXIT_FAILURE);
600 }
601
602 while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
603 {
604 ++line_num;
605 len = strlen(linebuf);
606 if (len == CONFIGPARSERBUFSIZE-1)
607 {
608 fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
609 PACKAGE, CONFIGPARSERBUFSIZE, filename);
610 exit (EXIT_FAILURE);
611 }
612
613 if (linebuf[0] == '#')
614 continue; /* Line was a comment */
615
616 /* Get the option */
617 if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
618 {
619 if (!strcmp(fopt, "help"))
620 {
621 if (override || !args_info->help_given)
622 {
623 args_info->help_given = 1;
624
625 }
626 continue;
627 }
628 if (!strcmp(fopt, "version"))
629 {
630 if (override || !args_info->version_given)
631 {
632 args_info->version_given = 1;
633
634 }
635 continue;
636 }
jjako52c24142002-12-16 13:33:51 +0000637 if (!strcmp(fopt, "debug"))
638 {
639 if (override || !args_info->debug_given)
640 {
641 args_info->debug_given = 1;
642 args_info->debug_flag = !(args_info->debug_flag);
643 }
644 continue;
645 }
646 if (!strcmp(fopt, "conf"))
647 {
648 if (override || !args_info->conf_given)
649 {
650 args_info->conf_given = 1;
651 if (fnum == 2)
652 args_info->conf_arg = strdup (farg);
653 else
654 {
655 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
656 filename, line_num);
657 exit (EXIT_FAILURE);
658 }
659 }
660 continue;
661 }
662 if (!strcmp(fopt, "pidfile"))
663 {
664 if (override || !args_info->pidfile_given)
665 {
666 args_info->pidfile_given = 1;
667 if (fnum == 2)
668 args_info->pidfile_arg = strdup (farg);
669 else
670 {
671 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
672 filename, line_num);
673 exit (EXIT_FAILURE);
674 }
675 }
676 continue;
677 }
678 if (!strcmp(fopt, "statedir"))
679 {
680 if (override || !args_info->statedir_given)
681 {
682 args_info->statedir_given = 1;
683 if (fnum == 2)
684 args_info->statedir_arg = strdup (farg);
685 else
686 {
687 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
688 filename, line_num);
689 exit (EXIT_FAILURE);
690 }
691 }
692 continue;
693 }
694 if (!strcmp(fopt, "dns"))
695 {
696 if (override || !args_info->dns_given)
697 {
698 args_info->dns_given = 1;
699 if (fnum == 2)
700 args_info->dns_arg = strdup (farg);
701 else
702 {
703 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
704 filename, line_num);
705 exit (EXIT_FAILURE);
706 }
707 }
708 continue;
709 }
710 if (!strcmp(fopt, "listen"))
711 {
712 if (override || !args_info->listen_given)
713 {
714 args_info->listen_given = 1;
715 if (fnum == 2)
716 args_info->listen_arg = strdup (farg);
717 else
718 {
719 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
720 filename, line_num);
721 exit (EXIT_FAILURE);
722 }
723 }
724 continue;
725 }
726 if (!strcmp(fopt, "remote"))
727 {
728 if (override || !args_info->remote_given)
729 {
730 args_info->remote_given = 1;
731 if (fnum == 2)
732 args_info->remote_arg = strdup (farg);
733 else
734 {
735 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
736 filename, line_num);
737 exit (EXIT_FAILURE);
738 }
739 }
740 continue;
741 }
jjako52c24142002-12-16 13:33:51 +0000742 if (!strcmp(fopt, "contexts"))
743 {
744 if (override || !args_info->contexts_given)
745 {
746 args_info->contexts_given = 1;
747 if (fnum == 2)
748 args_info->contexts_arg = strtol (farg,&stop_char,0);
749 else
750 {
751 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
752 filename, line_num);
753 exit (EXIT_FAILURE);
754 }
755 }
756 continue;
757 }
jjako52c24142002-12-16 13:33:51 +0000758 if (!strcmp(fopt, "timelimit"))
759 {
760 if (override || !args_info->timelimit_given)
761 {
762 args_info->timelimit_given = 1;
763 if (fnum == 2)
764 args_info->timelimit_arg = strtol (farg,&stop_char,0);
765 else
766 {
767 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
768 filename, line_num);
769 exit (EXIT_FAILURE);
770 }
771 }
772 continue;
773 }
jjako193e8b12003-11-10 12:31:41 +0000774 if (!strcmp(fopt, "gtpversion"))
775 {
776 if (override || !args_info->gtpversion_given)
777 {
778 args_info->gtpversion_given = 1;
779 if (fnum == 2)
780 args_info->gtpversion_arg = strtol (farg,&stop_char,0);
781 else
782 {
783 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
784 filename, line_num);
785 exit (EXIT_FAILURE);
786 }
787 }
788 continue;
789 }
jjako52c24142002-12-16 13:33:51 +0000790 if (!strcmp(fopt, "apn"))
791 {
792 if (override || !args_info->apn_given)
793 {
794 args_info->apn_given = 1;
795 if (fnum == 2)
796 args_info->apn_arg = strdup (farg);
797 else
798 {
799 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
800 filename, line_num);
801 exit (EXIT_FAILURE);
802 }
803 }
804 continue;
805 }
806 if (!strcmp(fopt, "imsi"))
807 {
808 if (override || !args_info->imsi_given)
809 {
810 args_info->imsi_given = 1;
811 if (fnum == 2)
812 args_info->imsi_arg = strdup (farg);
813 else
814 {
815 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
816 filename, line_num);
817 exit (EXIT_FAILURE);
818 }
819 }
820 continue;
821 }
jjako193e8b12003-11-10 12:31:41 +0000822 if (!strcmp(fopt, "nsapi"))
823 {
824 if (override || !args_info->nsapi_given)
825 {
826 args_info->nsapi_given = 1;
827 if (fnum == 2)
828 args_info->nsapi_arg = strtol (farg,&stop_char,0);
829 else
830 {
831 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
832 filename, line_num);
833 exit (EXIT_FAILURE);
834 }
835 }
836 continue;
837 }
jjako52c24142002-12-16 13:33:51 +0000838 if (!strcmp(fopt, "msisdn"))
839 {
840 if (override || !args_info->msisdn_given)
841 {
842 args_info->msisdn_given = 1;
843 if (fnum == 2)
844 args_info->msisdn_arg = strdup (farg);
845 else
846 {
847 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
848 filename, line_num);
849 exit (EXIT_FAILURE);
850 }
851 }
852 continue;
853 }
854 if (!strcmp(fopt, "qos"))
855 {
856 if (override || !args_info->qos_given)
857 {
858 args_info->qos_given = 1;
859 if (fnum == 2)
860 args_info->qos_arg = strtol (farg,&stop_char,0);
861 else
862 {
863 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
864 filename, line_num);
865 exit (EXIT_FAILURE);
866 }
867 }
868 continue;
869 }
jjako7e051d32004-05-27 20:06:36 +0000870 if (!strcmp(fopt, "charging"))
871 {
872 if (override || !args_info->charging_given)
873 {
874 args_info->charging_given = 1;
875 if (fnum == 2)
876 args_info->charging_arg = strtol (farg,&stop_char,0);
877 else
878 {
879 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
880 filename, line_num);
881 exit (EXIT_FAILURE);
882 }
883 }
884 continue;
885 }
jjako52c24142002-12-16 13:33:51 +0000886 if (!strcmp(fopt, "uid"))
887 {
888 if (override || !args_info->uid_given)
889 {
890 args_info->uid_given = 1;
891 if (fnum == 2)
892 args_info->uid_arg = strdup (farg);
893 else
894 {
895 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
896 filename, line_num);
897 exit (EXIT_FAILURE);
898 }
899 }
900 continue;
901 }
902 if (!strcmp(fopt, "pwd"))
903 {
904 if (override || !args_info->pwd_given)
905 {
906 args_info->pwd_given = 1;
907 if (fnum == 2)
908 args_info->pwd_arg = strdup (farg);
909 else
910 {
911 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
912 filename, line_num);
913 exit (EXIT_FAILURE);
914 }
915 }
916 continue;
917 }
jjako5da68452003-01-28 16:08:47 +0000918 if (!strcmp(fopt, "createif"))
919 {
920 if (override || !args_info->createif_given)
921 {
922 args_info->createif_given = 1;
923 args_info->createif_flag = !(args_info->createif_flag);
924 }
925 continue;
926 }
jjako193e8b12003-11-10 12:31:41 +0000927 if (!strcmp(fopt, "net"))
928 {
929 if (override || !args_info->net_given)
930 {
931 args_info->net_given = 1;
932 if (fnum == 2)
933 args_info->net_arg = strdup (farg);
934 else
935 {
936 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
937 filename, line_num);
938 exit (EXIT_FAILURE);
939 }
940 }
941 continue;
942 }
jjakoa7cd2492003-04-11 09:40:12 +0000943 if (!strcmp(fopt, "defaultroute"))
944 {
945 if (override || !args_info->defaultroute_given)
946 {
947 args_info->defaultroute_given = 1;
948 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
949 }
950 continue;
951 }
jjako5da68452003-01-28 16:08:47 +0000952 if (!strcmp(fopt, "ipup"))
953 {
954 if (override || !args_info->ipup_given)
955 {
956 args_info->ipup_given = 1;
957 if (fnum == 2)
958 args_info->ipup_arg = strdup (farg);
959 else
960 {
961 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
962 filename, line_num);
963 exit (EXIT_FAILURE);
964 }
965 }
966 continue;
967 }
968 if (!strcmp(fopt, "ipdown"))
969 {
970 if (override || !args_info->ipdown_given)
971 {
972 args_info->ipdown_given = 1;
973 if (fnum == 2)
974 args_info->ipdown_arg = strdup (farg);
975 else
976 {
977 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
978 filename, line_num);
979 exit (EXIT_FAILURE);
980 }
981 }
982 continue;
983 }
jjako5da68452003-01-28 16:08:47 +0000984 if (!strcmp(fopt, "pinghost"))
985 {
986 if (override || !args_info->pinghost_given)
987 {
988 args_info->pinghost_given = 1;
989 if (fnum == 2)
990 args_info->pinghost_arg = strdup (farg);
991 else
992 {
993 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
994 filename, line_num);
995 exit (EXIT_FAILURE);
996 }
997 }
998 continue;
999 }
1000 if (!strcmp(fopt, "pingrate"))
1001 {
1002 if (override || !args_info->pingrate_given)
1003 {
1004 args_info->pingrate_given = 1;
1005 if (fnum == 2)
1006 args_info->pingrate_arg = strtol (farg,&stop_char,0);
1007 else
1008 {
1009 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1010 filename, line_num);
1011 exit (EXIT_FAILURE);
1012 }
1013 }
1014 continue;
1015 }
1016 if (!strcmp(fopt, "pingsize"))
1017 {
1018 if (override || !args_info->pingsize_given)
1019 {
1020 args_info->pingsize_given = 1;
1021 if (fnum == 2)
1022 args_info->pingsize_arg = strtol (farg,&stop_char,0);
1023 else
1024 {
1025 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1026 filename, line_num);
1027 exit (EXIT_FAILURE);
1028 }
1029 }
1030 continue;
1031 }
1032 if (!strcmp(fopt, "pingcount"))
1033 {
1034 if (override || !args_info->pingcount_given)
1035 {
1036 args_info->pingcount_given = 1;
1037 if (fnum == 2)
1038 args_info->pingcount_arg = strtol (farg,&stop_char,0);
1039 else
1040 {
1041 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1042 filename, line_num);
1043 exit (EXIT_FAILURE);
1044 }
1045 }
1046 continue;
1047 }
1048 if (!strcmp(fopt, "pingquiet"))
1049 {
1050 if (override || !args_info->pingquiet_given)
1051 {
1052 args_info->pingquiet_given = 1;
1053 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
1054 }
1055 continue;
1056 }
jjako52c24142002-12-16 13:33:51 +00001057
1058
1059 /* Tried all known options. This one is unknown! */
1060 fprintf (stderr, "%s: Unknown option '%s' found in %s\n",
1061 PACKAGE, fopt, filename);
1062 exit (EXIT_FAILURE);
1063 }
1064 } /* while */
1065 fclose(file); /* No error checking on close */
1066
1067 return 0;
1068}