blob: 08582c9397006c2c0d2e39e14af1a15407c3a44e [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:
jjako1a51df72004-07-20 08:30:21 +00004 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");
jjako1a51df72004-07-20 08:30:21 +000058 printf(" --selmode=INT Selection mode (default='0x01')\n");
jjako52c24142002-12-16 13:33:51 +000059 printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n");
jjako7e051d32004-05-27 20:06:36 +000060 printf(" --nsapi=INT NSAPI (default='0')\n");
jjako52c24142002-12-16 13:33:51 +000061 printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n");
62 printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n");
jjako7e051d32004-05-27 20:06:36 +000063 printf(" --charging=INT Charging characteristics (default='0x0800')\n");
jjako52c24142002-12-16 13:33:51 +000064 printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n");
65 printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n");
jjako5da68452003-01-28 16:08:47 +000066 printf(" --createif Create local network interface (default=off)\n");
jjako193e8b12003-11-10 12:31:41 +000067 printf(" -nSTRING --net=STRING Network address for local interface\n");
jjakoa7cd2492003-04-11 09:40:12 +000068 printf(" --defaultroute Create default route (default=off)\n");
jjako5da68452003-01-28 16:08:47 +000069 printf(" --ipup=STRING Script to run after link-up\n");
70 printf(" --ipdown=STRING Script to run after link-down\n");
jjako5da68452003-01-28 16:08:47 +000071 printf(" --pinghost=STRING Ping remote host\n");
72 printf(" --pingrate=INT Number of ping req per second (default='1')\n");
73 printf(" --pingsize=INT Number of ping data bytes (default='56')\n");
74 printf(" --pingcount=INT Number of ping req to send (default='0')\n");
75 printf(" --pingquiet Do not print ping packet info (default=off)\n");
jjako52c24142002-12-16 13:33:51 +000076}
77
78
79#ifndef HAVE_STRDUP
80/* gengetopt_strdup(): automatically generated from strdup.c. */
81/* strdup.c replacement of strdup, which is not standard */
82static char *
83gengetopt_strdup (const char *s)
84{
85 char *result = (char*)malloc(strlen(s) + 1);
86 if (result == (char*)0)
87 return (char*)0;
88 strcpy(result, s);
89 return result;
90}
91#endif /* HAVE_STRDUP */
92
93int
94cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
95{
96 int c; /* Character of the parsed option. */
97 int missing_required_options = 0;
98
99 args_info->help_given = 0 ;
100 args_info->version_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000101 args_info->debug_given = 0 ;
102 args_info->conf_given = 0 ;
103 args_info->pidfile_given = 0 ;
104 args_info->statedir_given = 0 ;
105 args_info->dns_given = 0 ;
106 args_info->listen_given = 0 ;
107 args_info->remote_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000108 args_info->contexts_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000109 args_info->timelimit_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000110 args_info->gtpversion_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000111 args_info->apn_given = 0 ;
jjako1a51df72004-07-20 08:30:21 +0000112 args_info->selmode_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000113 args_info->imsi_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000114 args_info->nsapi_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000115 args_info->msisdn_given = 0 ;
116 args_info->qos_given = 0 ;
jjako7e051d32004-05-27 20:06:36 +0000117 args_info->charging_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000118 args_info->uid_given = 0 ;
119 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000120 args_info->createif_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000121 args_info->net_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +0000122 args_info->defaultroute_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000123 args_info->ipup_given = 0 ;
124 args_info->ipdown_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000125 args_info->pinghost_given = 0 ;
126 args_info->pingrate_given = 0 ;
127 args_info->pingsize_given = 0 ;
128 args_info->pingcount_given = 0 ;
129 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000130#define clear_args() { \
jjako52c24142002-12-16 13:33:51 +0000131 args_info->debug_flag = 0;\
132 args_info->conf_arg = NULL; \
133 args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
134 args_info->statedir_arg = strdup("./") ;\
135 args_info->dns_arg = NULL; \
136 args_info->listen_arg = NULL; \
137 args_info->remote_arg = NULL; \
jjako52c24142002-12-16 13:33:51 +0000138 args_info->contexts_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000139 args_info->timelimit_arg = 0 ;\
jjako193e8b12003-11-10 12:31:41 +0000140 args_info->gtpversion_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000141 args_info->apn_arg = strdup("internet") ;\
jjako1a51df72004-07-20 08:30:21 +0000142 args_info->selmode_arg = 0x01 ;\
jjako52c24142002-12-16 13:33:51 +0000143 args_info->imsi_arg = strdup("240010123456789") ;\
jjako7e051d32004-05-27 20:06:36 +0000144 args_info->nsapi_arg = 0 ;\
jjako52c24142002-12-16 13:33:51 +0000145 args_info->msisdn_arg = strdup("46702123456") ;\
146 args_info->qos_arg = 0x0b921f ;\
jjako7e051d32004-05-27 20:06:36 +0000147 args_info->charging_arg = 0x0800 ;\
jjako52c24142002-12-16 13:33:51 +0000148 args_info->uid_arg = strdup("mig") ;\
149 args_info->pwd_arg = strdup("hemmelig") ;\
jjako5da68452003-01-28 16:08:47 +0000150 args_info->createif_flag = 0;\
jjako193e8b12003-11-10 12:31:41 +0000151 args_info->net_arg = NULL; \
jjakoa7cd2492003-04-11 09:40:12 +0000152 args_info->defaultroute_flag = 0;\
jjako5da68452003-01-28 16:08:47 +0000153 args_info->ipup_arg = NULL; \
154 args_info->ipdown_arg = NULL; \
jjako5da68452003-01-28 16:08:47 +0000155 args_info->pinghost_arg = NULL; \
156 args_info->pingrate_arg = 1 ;\
157 args_info->pingsize_arg = 56 ;\
158 args_info->pingcount_arg = 0 ;\
159 args_info->pingquiet_flag = 0;\
jjako52c24142002-12-16 13:33:51 +0000160}
161
162 clear_args();
163
164 optarg = 0;
165 optind = 1;
166 opterr = 1;
167 optopt = '?';
168
169 while (1)
170 {
171 int option_index = 0;
172 char *stop_char;
173 static struct option long_options[] = {
174 { "help", 0, NULL, 'h' },
175 { "version", 0, NULL, 'V' },
jjako52c24142002-12-16 13:33:51 +0000176 { "debug", 0, NULL, 'd' },
177 { "conf", 1, NULL, 'c' },
178 { "pidfile", 1, NULL, 0 },
179 { "statedir", 1, NULL, 0 },
180 { "dns", 1, NULL, 0 },
181 { "listen", 1, NULL, 'l' },
182 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000183 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000184 { "timelimit", 1, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000185 { "gtpversion", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000186 { "apn", 1, NULL, 'a' },
jjako1a51df72004-07-20 08:30:21 +0000187 { "selmode", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000188 { "imsi", 1, NULL, 'i' },
jjako193e8b12003-11-10 12:31:41 +0000189 { "nsapi", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000190 { "msisdn", 1, NULL, 'm' },
191 { "qos", 1, NULL, 'q' },
jjako7e051d32004-05-27 20:06:36 +0000192 { "charging", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000193 { "uid", 1, NULL, 'u' },
194 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000195 { "createif", 0, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000196 { "net", 1, NULL, 'n' },
jjakoa7cd2492003-04-11 09:40:12 +0000197 { "defaultroute", 0, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000198 { "ipup", 1, NULL, 0 },
199 { "ipdown", 1, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000200 { "pinghost", 1, NULL, 0 },
201 { "pingrate", 1, NULL, 0 },
202 { "pingsize", 1, NULL, 0 },
203 { "pingcount", 1, NULL, 0 },
204 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000205 { NULL, 0, NULL, 0 }
206 };
207
jjako193e8b12003-11-10 12:31:41 +0000208 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 +0000209
210 if (c == -1) break; /* Exit from `while (1)' loop. */
211
212 switch (c)
213 {
214 case 'h': /* Print help and exit. */
215 clear_args ();
216 cmdline_parser_print_help ();
217 exit (EXIT_SUCCESS);
218
219 case 'V': /* Print version and exit. */
220 clear_args ();
221 cmdline_parser_print_version ();
222 exit (EXIT_SUCCESS);
223
jjako52c24142002-12-16 13:33:51 +0000224 case 'd': /* Run in debug mode. */
225 if (args_info->debug_given)
226 {
227 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
228 clear_args ();
229 exit (EXIT_FAILURE);
230 }
231 args_info->debug_given = 1;
232 args_info->debug_flag = !(args_info->debug_flag);
233 break;
234
235 case 'c': /* Read configuration file. */
236 if (args_info->conf_given)
237 {
238 fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
239 clear_args ();
240 exit (EXIT_FAILURE);
241 }
242 args_info->conf_given = 1;
243 args_info->conf_arg = strdup (optarg);
244 break;
245
246 case 'l': /* Local interface. */
247 if (args_info->listen_given)
248 {
249 fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
250 clear_args ();
251 exit (EXIT_FAILURE);
252 }
253 args_info->listen_given = 1;
254 args_info->listen_arg = strdup (optarg);
255 break;
256
257 case 'r': /* Remote host. */
258 if (args_info->remote_given)
259 {
260 fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
261 clear_args ();
262 exit (EXIT_FAILURE);
263 }
264 args_info->remote_given = 1;
265 args_info->remote_arg = strdup (optarg);
266 break;
267
jjako52c24142002-12-16 13:33:51 +0000268 case 'a': /* Access point name. */
269 if (args_info->apn_given)
270 {
271 fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
272 clear_args ();
273 exit (EXIT_FAILURE);
274 }
275 args_info->apn_given = 1;
276 args_info->apn_arg = strdup (optarg);
277 break;
278
279 case 'i': /* IMSI. */
280 if (args_info->imsi_given)
281 {
282 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
283 clear_args ();
284 exit (EXIT_FAILURE);
285 }
286 args_info->imsi_given = 1;
287 args_info->imsi_arg = strdup (optarg);
288 break;
289
290 case 'm': /* Mobile Station ISDN number. */
291 if (args_info->msisdn_given)
292 {
293 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
294 clear_args ();
295 exit (EXIT_FAILURE);
296 }
297 args_info->msisdn_given = 1;
298 args_info->msisdn_arg = strdup (optarg);
299 break;
300
301 case 'q': /* Requested quality of service. */
302 if (args_info->qos_given)
303 {
304 fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
305 clear_args ();
306 exit (EXIT_FAILURE);
307 }
308 args_info->qos_given = 1;
309 args_info->qos_arg = strtol (optarg,&stop_char,0);
310 break;
311
312 case 'u': /* Login user ID. */
313 if (args_info->uid_given)
314 {
315 fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
316 clear_args ();
317 exit (EXIT_FAILURE);
318 }
319 args_info->uid_given = 1;
320 args_info->uid_arg = strdup (optarg);
321 break;
322
323 case 'p': /* Login password. */
324 if (args_info->pwd_given)
325 {
326 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
327 clear_args ();
328 exit (EXIT_FAILURE);
329 }
330 args_info->pwd_given = 1;
331 args_info->pwd_arg = strdup (optarg);
332 break;
333
jjako193e8b12003-11-10 12:31:41 +0000334 case 'n': /* Network address for local interface. */
335 if (args_info->net_given)
336 {
337 fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE);
338 clear_args ();
339 exit (EXIT_FAILURE);
340 }
341 args_info->net_given = 1;
342 args_info->net_arg = strdup (optarg);
343 break;
344
jjako52c24142002-12-16 13:33:51 +0000345
346 case 0: /* Long option with no short option */
347 /* Filename of process id file. */
348 if (strcmp (long_options[option_index].name, "pidfile") == 0)
349 {
350 if (args_info->pidfile_given)
351 {
352 fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
353 clear_args ();
354 exit (EXIT_FAILURE);
355 }
356 args_info->pidfile_given = 1;
357 args_info->pidfile_arg = strdup (optarg);
358 break;
359 }
360 /* Directory of nonvolatile data. */
361 else if (strcmp (long_options[option_index].name, "statedir") == 0)
362 {
363 if (args_info->statedir_given)
364 {
365 fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
366 clear_args ();
367 exit (EXIT_FAILURE);
368 }
369 args_info->statedir_given = 1;
370 args_info->statedir_arg = strdup (optarg);
371 break;
372 }
373 /* DNS Server to use. */
374 else if (strcmp (long_options[option_index].name, "dns") == 0)
375 {
376 if (args_info->dns_given)
377 {
378 fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
379 clear_args ();
380 exit (EXIT_FAILURE);
381 }
382 args_info->dns_given = 1;
383 args_info->dns_arg = strdup (optarg);
384 break;
385 }
jjako52c24142002-12-16 13:33:51 +0000386 /* Number of contexts. */
387 else if (strcmp (long_options[option_index].name, "contexts") == 0)
388 {
389 if (args_info->contexts_given)
390 {
391 fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
392 clear_args ();
393 exit (EXIT_FAILURE);
394 }
395 args_info->contexts_given = 1;
396 args_info->contexts_arg = strtol (optarg,&stop_char,0);
397 break;
398 }
jjako52c24142002-12-16 13:33:51 +0000399 /* Exit after timelimit seconds. */
400 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
401 {
402 if (args_info->timelimit_given)
403 {
404 fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
405 clear_args ();
406 exit (EXIT_FAILURE);
407 }
408 args_info->timelimit_given = 1;
409 args_info->timelimit_arg = strtol (optarg,&stop_char,0);
410 break;
411 }
jjako193e8b12003-11-10 12:31:41 +0000412 /* GTP version to use. */
413 else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
414 {
415 if (args_info->gtpversion_given)
416 {
417 fprintf (stderr, "%s: `--gtpversion' option given more than once\n", PACKAGE);
418 clear_args ();
419 exit (EXIT_FAILURE);
420 }
421 args_info->gtpversion_given = 1;
422 args_info->gtpversion_arg = strtol (optarg,&stop_char,0);
423 break;
424 }
jjako1a51df72004-07-20 08:30:21 +0000425 /* Selection mode. */
426 else if (strcmp (long_options[option_index].name, "selmode") == 0)
427 {
428 if (args_info->selmode_given)
429 {
430 fprintf (stderr, "%s: `--selmode' option given more than once\n", PACKAGE);
431 clear_args ();
432 exit (EXIT_FAILURE);
433 }
434 args_info->selmode_given = 1;
435 args_info->selmode_arg = strtol (optarg,&stop_char,0);
436 break;
437 }
jjako193e8b12003-11-10 12:31:41 +0000438 /* NSAPI. */
439 else if (strcmp (long_options[option_index].name, "nsapi") == 0)
440 {
441 if (args_info->nsapi_given)
442 {
443 fprintf (stderr, "%s: `--nsapi' option given more than once\n", PACKAGE);
444 clear_args ();
445 exit (EXIT_FAILURE);
446 }
447 args_info->nsapi_given = 1;
448 args_info->nsapi_arg = strtol (optarg,&stop_char,0);
449 break;
450 }
jjako7e051d32004-05-27 20:06:36 +0000451 /* Charging characteristics. */
452 else if (strcmp (long_options[option_index].name, "charging") == 0)
453 {
454 if (args_info->charging_given)
455 {
456 fprintf (stderr, "%s: `--charging' option given more than once\n", PACKAGE);
457 clear_args ();
458 exit (EXIT_FAILURE);
459 }
460 args_info->charging_given = 1;
461 args_info->charging_arg = strtol (optarg,&stop_char,0);
462 break;
463 }
jjako5da68452003-01-28 16:08:47 +0000464 /* Create local network interface. */
465 else if (strcmp (long_options[option_index].name, "createif") == 0)
466 {
467 if (args_info->createif_given)
468 {
469 fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
470 clear_args ();
471 exit (EXIT_FAILURE);
472 }
473 args_info->createif_given = 1;
474 args_info->createif_flag = !(args_info->createif_flag);
475 break;
476 }
jjakoa7cd2492003-04-11 09:40:12 +0000477 /* Create default route. */
478 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
479 {
480 if (args_info->defaultroute_given)
481 {
482 fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
483 clear_args ();
484 exit (EXIT_FAILURE);
485 }
486 args_info->defaultroute_given = 1;
487 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
488 break;
489 }
jjako5da68452003-01-28 16:08:47 +0000490 /* Script to run after link-up. */
491 else if (strcmp (long_options[option_index].name, "ipup") == 0)
492 {
493 if (args_info->ipup_given)
494 {
495 fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
496 clear_args ();
497 exit (EXIT_FAILURE);
498 }
499 args_info->ipup_given = 1;
500 args_info->ipup_arg = strdup (optarg);
501 break;
502 }
503 /* Script to run after link-down. */
504 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
505 {
506 if (args_info->ipdown_given)
507 {
508 fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
509 clear_args ();
510 exit (EXIT_FAILURE);
511 }
512 args_info->ipdown_given = 1;
513 args_info->ipdown_arg = strdup (optarg);
514 break;
515 }
jjako5da68452003-01-28 16:08:47 +0000516 /* Ping remote host. */
517 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
518 {
519 if (args_info->pinghost_given)
520 {
521 fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
522 clear_args ();
523 exit (EXIT_FAILURE);
524 }
525 args_info->pinghost_given = 1;
526 args_info->pinghost_arg = strdup (optarg);
527 break;
528 }
529 /* Number of ping req per second. */
530 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
531 {
532 if (args_info->pingrate_given)
533 {
534 fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
535 clear_args ();
536 exit (EXIT_FAILURE);
537 }
538 args_info->pingrate_given = 1;
539 args_info->pingrate_arg = strtol (optarg,&stop_char,0);
540 break;
541 }
542 /* Number of ping data bytes. */
543 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
544 {
545 if (args_info->pingsize_given)
546 {
547 fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
548 clear_args ();
549 exit (EXIT_FAILURE);
550 }
551 args_info->pingsize_given = 1;
552 args_info->pingsize_arg = strtol (optarg,&stop_char,0);
553 break;
554 }
555 /* Number of ping req to send. */
556 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
557 {
558 if (args_info->pingcount_given)
559 {
560 fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
561 clear_args ();
562 exit (EXIT_FAILURE);
563 }
564 args_info->pingcount_given = 1;
565 args_info->pingcount_arg = strtol (optarg,&stop_char,0);
566 break;
567 }
568 /* Do not print ping packet info. */
569 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
570 {
571 if (args_info->pingquiet_given)
572 {
573 fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
574 clear_args ();
575 exit (EXIT_FAILURE);
576 }
577 args_info->pingquiet_given = 1;
578 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
579 break;
580 }
jjako52c24142002-12-16 13:33:51 +0000581
582 case '?': /* Invalid option. */
583 /* `getopt_long' already printed an error message. */
584 exit (EXIT_FAILURE);
585
586 default: /* bug: option not considered. */
587 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
588 abort ();
589 } /* switch */
590 } /* while */
591
592
593 if ( missing_required_options )
594 exit (EXIT_FAILURE);
595
596 return 0;
597}
598
599#define CONFIGPARSERBUFSIZE 1024
600
601int
602cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
603{
604 FILE* file;
605 char linebuf[CONFIGPARSERBUFSIZE];
606 int line_num = 0;
607 int len;
608 int fnum;
609 char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
610 char *stop_char;
611
612 if ((file = fopen(filename, "r")) == NULL)
613 {
614 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
615 PACKAGE, filename);
616 exit (EXIT_FAILURE);
617 }
618
619 while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
620 {
621 ++line_num;
622 len = strlen(linebuf);
623 if (len == CONFIGPARSERBUFSIZE-1)
624 {
625 fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
626 PACKAGE, CONFIGPARSERBUFSIZE, filename);
627 exit (EXIT_FAILURE);
628 }
629
630 if (linebuf[0] == '#')
631 continue; /* Line was a comment */
632
633 /* Get the option */
634 if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
635 {
636 if (!strcmp(fopt, "help"))
637 {
638 if (override || !args_info->help_given)
639 {
640 args_info->help_given = 1;
641
642 }
643 continue;
644 }
645 if (!strcmp(fopt, "version"))
646 {
647 if (override || !args_info->version_given)
648 {
649 args_info->version_given = 1;
650
651 }
652 continue;
653 }
jjako52c24142002-12-16 13:33:51 +0000654 if (!strcmp(fopt, "debug"))
655 {
656 if (override || !args_info->debug_given)
657 {
658 args_info->debug_given = 1;
659 args_info->debug_flag = !(args_info->debug_flag);
660 }
661 continue;
662 }
663 if (!strcmp(fopt, "conf"))
664 {
665 if (override || !args_info->conf_given)
666 {
667 args_info->conf_given = 1;
668 if (fnum == 2)
669 args_info->conf_arg = strdup (farg);
670 else
671 {
672 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
673 filename, line_num);
674 exit (EXIT_FAILURE);
675 }
676 }
677 continue;
678 }
679 if (!strcmp(fopt, "pidfile"))
680 {
681 if (override || !args_info->pidfile_given)
682 {
683 args_info->pidfile_given = 1;
684 if (fnum == 2)
685 args_info->pidfile_arg = strdup (farg);
686 else
687 {
688 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
689 filename, line_num);
690 exit (EXIT_FAILURE);
691 }
692 }
693 continue;
694 }
695 if (!strcmp(fopt, "statedir"))
696 {
697 if (override || !args_info->statedir_given)
698 {
699 args_info->statedir_given = 1;
700 if (fnum == 2)
701 args_info->statedir_arg = strdup (farg);
702 else
703 {
704 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
705 filename, line_num);
706 exit (EXIT_FAILURE);
707 }
708 }
709 continue;
710 }
711 if (!strcmp(fopt, "dns"))
712 {
713 if (override || !args_info->dns_given)
714 {
715 args_info->dns_given = 1;
716 if (fnum == 2)
717 args_info->dns_arg = strdup (farg);
718 else
719 {
720 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
721 filename, line_num);
722 exit (EXIT_FAILURE);
723 }
724 }
725 continue;
726 }
727 if (!strcmp(fopt, "listen"))
728 {
729 if (override || !args_info->listen_given)
730 {
731 args_info->listen_given = 1;
732 if (fnum == 2)
733 args_info->listen_arg = strdup (farg);
734 else
735 {
736 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
737 filename, line_num);
738 exit (EXIT_FAILURE);
739 }
740 }
741 continue;
742 }
743 if (!strcmp(fopt, "remote"))
744 {
745 if (override || !args_info->remote_given)
746 {
747 args_info->remote_given = 1;
748 if (fnum == 2)
749 args_info->remote_arg = strdup (farg);
750 else
751 {
752 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
753 filename, line_num);
754 exit (EXIT_FAILURE);
755 }
756 }
757 continue;
758 }
jjako52c24142002-12-16 13:33:51 +0000759 if (!strcmp(fopt, "contexts"))
760 {
761 if (override || !args_info->contexts_given)
762 {
763 args_info->contexts_given = 1;
764 if (fnum == 2)
765 args_info->contexts_arg = strtol (farg,&stop_char,0);
766 else
767 {
768 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
769 filename, line_num);
770 exit (EXIT_FAILURE);
771 }
772 }
773 continue;
774 }
jjako52c24142002-12-16 13:33:51 +0000775 if (!strcmp(fopt, "timelimit"))
776 {
777 if (override || !args_info->timelimit_given)
778 {
779 args_info->timelimit_given = 1;
780 if (fnum == 2)
781 args_info->timelimit_arg = strtol (farg,&stop_char,0);
782 else
783 {
784 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
785 filename, line_num);
786 exit (EXIT_FAILURE);
787 }
788 }
789 continue;
790 }
jjako193e8b12003-11-10 12:31:41 +0000791 if (!strcmp(fopt, "gtpversion"))
792 {
793 if (override || !args_info->gtpversion_given)
794 {
795 args_info->gtpversion_given = 1;
796 if (fnum == 2)
797 args_info->gtpversion_arg = strtol (farg,&stop_char,0);
798 else
799 {
800 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
801 filename, line_num);
802 exit (EXIT_FAILURE);
803 }
804 }
805 continue;
806 }
jjako52c24142002-12-16 13:33:51 +0000807 if (!strcmp(fopt, "apn"))
808 {
809 if (override || !args_info->apn_given)
810 {
811 args_info->apn_given = 1;
812 if (fnum == 2)
813 args_info->apn_arg = strdup (farg);
814 else
815 {
816 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
817 filename, line_num);
818 exit (EXIT_FAILURE);
819 }
820 }
821 continue;
822 }
jjako1a51df72004-07-20 08:30:21 +0000823 if (!strcmp(fopt, "selmode"))
824 {
825 if (override || !args_info->selmode_given)
826 {
827 args_info->selmode_given = 1;
828 if (fnum == 2)
829 args_info->selmode_arg = strtol (farg,&stop_char,0);
830 else
831 {
832 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
833 filename, line_num);
834 exit (EXIT_FAILURE);
835 }
836 }
837 continue;
838 }
jjako52c24142002-12-16 13:33:51 +0000839 if (!strcmp(fopt, "imsi"))
840 {
841 if (override || !args_info->imsi_given)
842 {
843 args_info->imsi_given = 1;
844 if (fnum == 2)
845 args_info->imsi_arg = strdup (farg);
846 else
847 {
848 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
849 filename, line_num);
850 exit (EXIT_FAILURE);
851 }
852 }
853 continue;
854 }
jjako193e8b12003-11-10 12:31:41 +0000855 if (!strcmp(fopt, "nsapi"))
856 {
857 if (override || !args_info->nsapi_given)
858 {
859 args_info->nsapi_given = 1;
860 if (fnum == 2)
861 args_info->nsapi_arg = strtol (farg,&stop_char,0);
862 else
863 {
864 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
865 filename, line_num);
866 exit (EXIT_FAILURE);
867 }
868 }
869 continue;
870 }
jjako52c24142002-12-16 13:33:51 +0000871 if (!strcmp(fopt, "msisdn"))
872 {
873 if (override || !args_info->msisdn_given)
874 {
875 args_info->msisdn_given = 1;
876 if (fnum == 2)
877 args_info->msisdn_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, "qos"))
888 {
889 if (override || !args_info->qos_given)
890 {
891 args_info->qos_given = 1;
892 if (fnum == 2)
893 args_info->qos_arg = strtol (farg,&stop_char,0);
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 }
jjako7e051d32004-05-27 20:06:36 +0000903 if (!strcmp(fopt, "charging"))
904 {
905 if (override || !args_info->charging_given)
906 {
907 args_info->charging_given = 1;
908 if (fnum == 2)
909 args_info->charging_arg = strtol (farg,&stop_char,0);
910 else
911 {
912 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
913 filename, line_num);
914 exit (EXIT_FAILURE);
915 }
916 }
917 continue;
918 }
jjako52c24142002-12-16 13:33:51 +0000919 if (!strcmp(fopt, "uid"))
920 {
921 if (override || !args_info->uid_given)
922 {
923 args_info->uid_given = 1;
924 if (fnum == 2)
925 args_info->uid_arg = strdup (farg);
926 else
927 {
928 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
929 filename, line_num);
930 exit (EXIT_FAILURE);
931 }
932 }
933 continue;
934 }
935 if (!strcmp(fopt, "pwd"))
936 {
937 if (override || !args_info->pwd_given)
938 {
939 args_info->pwd_given = 1;
940 if (fnum == 2)
941 args_info->pwd_arg = strdup (farg);
942 else
943 {
944 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
945 filename, line_num);
946 exit (EXIT_FAILURE);
947 }
948 }
949 continue;
950 }
jjako5da68452003-01-28 16:08:47 +0000951 if (!strcmp(fopt, "createif"))
952 {
953 if (override || !args_info->createif_given)
954 {
955 args_info->createif_given = 1;
956 args_info->createif_flag = !(args_info->createif_flag);
957 }
958 continue;
959 }
jjako193e8b12003-11-10 12:31:41 +0000960 if (!strcmp(fopt, "net"))
961 {
962 if (override || !args_info->net_given)
963 {
964 args_info->net_given = 1;
965 if (fnum == 2)
966 args_info->net_arg = strdup (farg);
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 }
jjakoa7cd2492003-04-11 09:40:12 +0000976 if (!strcmp(fopt, "defaultroute"))
977 {
978 if (override || !args_info->defaultroute_given)
979 {
980 args_info->defaultroute_given = 1;
981 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
982 }
983 continue;
984 }
jjako5da68452003-01-28 16:08:47 +0000985 if (!strcmp(fopt, "ipup"))
986 {
987 if (override || !args_info->ipup_given)
988 {
989 args_info->ipup_given = 1;
990 if (fnum == 2)
991 args_info->ipup_arg = strdup (farg);
992 else
993 {
994 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
995 filename, line_num);
996 exit (EXIT_FAILURE);
997 }
998 }
999 continue;
1000 }
1001 if (!strcmp(fopt, "ipdown"))
1002 {
1003 if (override || !args_info->ipdown_given)
1004 {
1005 args_info->ipdown_given = 1;
1006 if (fnum == 2)
1007 args_info->ipdown_arg = strdup (farg);
1008 else
1009 {
1010 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1011 filename, line_num);
1012 exit (EXIT_FAILURE);
1013 }
1014 }
1015 continue;
1016 }
jjako5da68452003-01-28 16:08:47 +00001017 if (!strcmp(fopt, "pinghost"))
1018 {
1019 if (override || !args_info->pinghost_given)
1020 {
1021 args_info->pinghost_given = 1;
1022 if (fnum == 2)
1023 args_info->pinghost_arg = strdup (farg);
1024 else
1025 {
1026 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1027 filename, line_num);
1028 exit (EXIT_FAILURE);
1029 }
1030 }
1031 continue;
1032 }
1033 if (!strcmp(fopt, "pingrate"))
1034 {
1035 if (override || !args_info->pingrate_given)
1036 {
1037 args_info->pingrate_given = 1;
1038 if (fnum == 2)
1039 args_info->pingrate_arg = strtol (farg,&stop_char,0);
1040 else
1041 {
1042 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1043 filename, line_num);
1044 exit (EXIT_FAILURE);
1045 }
1046 }
1047 continue;
1048 }
1049 if (!strcmp(fopt, "pingsize"))
1050 {
1051 if (override || !args_info->pingsize_given)
1052 {
1053 args_info->pingsize_given = 1;
1054 if (fnum == 2)
1055 args_info->pingsize_arg = strtol (farg,&stop_char,0);
1056 else
1057 {
1058 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1059 filename, line_num);
1060 exit (EXIT_FAILURE);
1061 }
1062 }
1063 continue;
1064 }
1065 if (!strcmp(fopt, "pingcount"))
1066 {
1067 if (override || !args_info->pingcount_given)
1068 {
1069 args_info->pingcount_given = 1;
1070 if (fnum == 2)
1071 args_info->pingcount_arg = strtol (farg,&stop_char,0);
1072 else
1073 {
1074 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1075 filename, line_num);
1076 exit (EXIT_FAILURE);
1077 }
1078 }
1079 continue;
1080 }
1081 if (!strcmp(fopt, "pingquiet"))
1082 {
1083 if (override || !args_info->pingquiet_given)
1084 {
1085 args_info->pingquiet_given = 1;
1086 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
1087 }
1088 continue;
1089 }
jjako52c24142002-12-16 13:33:51 +00001090
1091
1092 /* Tried all known options. This one is unknown! */
1093 fprintf (stderr, "%s: Unknown option '%s' found in %s\n",
1094 PACKAGE, fopt, filename);
1095 exit (EXIT_FAILURE);
1096 }
1097 } /* while */
1098 fclose(file); /* No error checking on close */
1099
1100 return 0;
1101}