jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1 | /* |
jjako | 824cad6 | 2003-01-05 18:06:28 +0000 | [diff] [blame] | 2 | File autogenerated by gengetopt version 2.8 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 3 | generated with the following command: |
jjako | 824cad6 | 2003-01-05 18:06:28 +0000 | [diff] [blame] | 4 | gengetopt --conf-parser |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 5 | |
| 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 | |
| 33 | void |
| 34 | cmdline_parser_print_version (void) |
| 35 | { |
| 36 | printf ("%s %s\n", PACKAGE, VERSION); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | cmdline_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"); |
| 55 | printf(" -nSTRING --net=STRING Network (default='192.168.0.0')\n"); |
| 56 | printf(" --mask=STRING Network mask (default='255.255.255.0')\n"); |
| 57 | printf(" --contexts=INT Number of contexts (default='1')\n"); |
| 58 | printf(" --static Allocate static tun ifterface (default=off)\n"); |
| 59 | printf(" --timelimit=INT Exit after timelimit seconds (default='0')\n"); |
| 60 | printf(" -aSTRING --apn=STRING Access point name (default='internet')\n"); |
| 61 | printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n"); |
| 62 | printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n"); |
| 63 | printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n"); |
| 64 | printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n"); |
| 65 | printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n"); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | #ifndef HAVE_STRDUP |
| 70 | /* gengetopt_strdup(): automatically generated from strdup.c. */ |
| 71 | /* strdup.c replacement of strdup, which is not standard */ |
| 72 | static char * |
| 73 | gengetopt_strdup (const char *s) |
| 74 | { |
| 75 | char *result = (char*)malloc(strlen(s) + 1); |
| 76 | if (result == (char*)0) |
| 77 | return (char*)0; |
| 78 | strcpy(result, s); |
| 79 | return result; |
| 80 | } |
| 81 | #endif /* HAVE_STRDUP */ |
| 82 | |
| 83 | int |
| 84 | cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
| 85 | { |
| 86 | int c; /* Character of the parsed option. */ |
| 87 | int missing_required_options = 0; |
| 88 | |
| 89 | args_info->help_given = 0 ; |
| 90 | args_info->version_given = 0 ; |
| 91 | args_info->fg_given = 0 ; |
| 92 | args_info->debug_given = 0 ; |
| 93 | args_info->conf_given = 0 ; |
| 94 | args_info->pidfile_given = 0 ; |
| 95 | args_info->statedir_given = 0 ; |
| 96 | args_info->dns_given = 0 ; |
| 97 | args_info->listen_given = 0 ; |
| 98 | args_info->remote_given = 0 ; |
| 99 | args_info->net_given = 0 ; |
| 100 | args_info->mask_given = 0 ; |
| 101 | args_info->contexts_given = 0 ; |
| 102 | args_info->static_given = 0 ; |
| 103 | args_info->timelimit_given = 0 ; |
| 104 | args_info->apn_given = 0 ; |
| 105 | args_info->imsi_given = 0 ; |
| 106 | args_info->msisdn_given = 0 ; |
| 107 | args_info->qos_given = 0 ; |
| 108 | args_info->uid_given = 0 ; |
| 109 | args_info->pwd_given = 0 ; |
| 110 | #define clear_args() { \ |
| 111 | args_info->fg_flag = 0;\ |
| 112 | args_info->debug_flag = 0;\ |
| 113 | args_info->conf_arg = NULL; \ |
| 114 | args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\ |
| 115 | args_info->statedir_arg = strdup("./") ;\ |
| 116 | args_info->dns_arg = NULL; \ |
| 117 | args_info->listen_arg = NULL; \ |
| 118 | args_info->remote_arg = NULL; \ |
| 119 | args_info->net_arg = strdup("192.168.0.0") ;\ |
| 120 | args_info->mask_arg = strdup("255.255.255.0") ;\ |
| 121 | args_info->contexts_arg = 1 ;\ |
| 122 | args_info->static_flag = 0;\ |
| 123 | args_info->timelimit_arg = 0 ;\ |
| 124 | args_info->apn_arg = strdup("internet") ;\ |
| 125 | args_info->imsi_arg = strdup("240010123456789") ;\ |
| 126 | args_info->msisdn_arg = strdup("46702123456") ;\ |
| 127 | args_info->qos_arg = 0x0b921f ;\ |
| 128 | args_info->uid_arg = strdup("mig") ;\ |
| 129 | args_info->pwd_arg = strdup("hemmelig") ;\ |
| 130 | } |
| 131 | |
| 132 | clear_args(); |
| 133 | |
| 134 | optarg = 0; |
| 135 | optind = 1; |
| 136 | opterr = 1; |
| 137 | optopt = '?'; |
| 138 | |
| 139 | while (1) |
| 140 | { |
| 141 | int option_index = 0; |
| 142 | char *stop_char; |
| 143 | static struct option long_options[] = { |
| 144 | { "help", 0, NULL, 'h' }, |
| 145 | { "version", 0, NULL, 'V' }, |
| 146 | { "fg", 0, NULL, 'f' }, |
| 147 | { "debug", 0, NULL, 'd' }, |
| 148 | { "conf", 1, NULL, 'c' }, |
| 149 | { "pidfile", 1, NULL, 0 }, |
| 150 | { "statedir", 1, NULL, 0 }, |
| 151 | { "dns", 1, NULL, 0 }, |
| 152 | { "listen", 1, NULL, 'l' }, |
| 153 | { "remote", 1, NULL, 'r' }, |
| 154 | { "net", 1, NULL, 'n' }, |
| 155 | { "mask", 1, NULL, 0 }, |
| 156 | { "contexts", 1, NULL, 0 }, |
| 157 | { "static", 0, NULL, 0 }, |
| 158 | { "timelimit", 1, NULL, 0 }, |
| 159 | { "apn", 1, NULL, 'a' }, |
| 160 | { "imsi", 1, NULL, 'i' }, |
| 161 | { "msisdn", 1, NULL, 'm' }, |
| 162 | { "qos", 1, NULL, 'q' }, |
| 163 | { "uid", 1, NULL, 'u' }, |
| 164 | { "pwd", 1, NULL, 'p' }, |
| 165 | { NULL, 0, NULL, 0 } |
| 166 | }; |
| 167 | |
| 168 | c = getopt_long (argc, argv, "hVfdc:l:r:n:a:i:m:q:u:p:", long_options, &option_index); |
| 169 | |
| 170 | if (c == -1) break; /* Exit from `while (1)' loop. */ |
| 171 | |
| 172 | switch (c) |
| 173 | { |
| 174 | case 'h': /* Print help and exit. */ |
| 175 | clear_args (); |
| 176 | cmdline_parser_print_help (); |
| 177 | exit (EXIT_SUCCESS); |
| 178 | |
| 179 | case 'V': /* Print version and exit. */ |
| 180 | clear_args (); |
| 181 | cmdline_parser_print_version (); |
| 182 | exit (EXIT_SUCCESS); |
| 183 | |
| 184 | case 'f': /* Run in foreground. */ |
| 185 | if (args_info->fg_given) |
| 186 | { |
| 187 | fprintf (stderr, "%s: `--fg' (`-f') option given more than once\n", PACKAGE); |
| 188 | clear_args (); |
| 189 | exit (EXIT_FAILURE); |
| 190 | } |
| 191 | args_info->fg_given = 1; |
| 192 | args_info->fg_flag = !(args_info->fg_flag); |
| 193 | break; |
| 194 | |
| 195 | case 'd': /* Run in debug mode. */ |
| 196 | if (args_info->debug_given) |
| 197 | { |
| 198 | fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE); |
| 199 | clear_args (); |
| 200 | exit (EXIT_FAILURE); |
| 201 | } |
| 202 | args_info->debug_given = 1; |
| 203 | args_info->debug_flag = !(args_info->debug_flag); |
| 204 | break; |
| 205 | |
| 206 | case 'c': /* Read configuration file. */ |
| 207 | if (args_info->conf_given) |
| 208 | { |
| 209 | fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE); |
| 210 | clear_args (); |
| 211 | exit (EXIT_FAILURE); |
| 212 | } |
| 213 | args_info->conf_given = 1; |
| 214 | args_info->conf_arg = strdup (optarg); |
| 215 | break; |
| 216 | |
| 217 | case 'l': /* Local interface. */ |
| 218 | if (args_info->listen_given) |
| 219 | { |
| 220 | fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE); |
| 221 | clear_args (); |
| 222 | exit (EXIT_FAILURE); |
| 223 | } |
| 224 | args_info->listen_given = 1; |
| 225 | args_info->listen_arg = strdup (optarg); |
| 226 | break; |
| 227 | |
| 228 | case 'r': /* Remote host. */ |
| 229 | if (args_info->remote_given) |
| 230 | { |
| 231 | fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE); |
| 232 | clear_args (); |
| 233 | exit (EXIT_FAILURE); |
| 234 | } |
| 235 | args_info->remote_given = 1; |
| 236 | args_info->remote_arg = strdup (optarg); |
| 237 | break; |
| 238 | |
| 239 | case 'n': /* Network. */ |
| 240 | if (args_info->net_given) |
| 241 | { |
| 242 | fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE); |
| 243 | clear_args (); |
| 244 | exit (EXIT_FAILURE); |
| 245 | } |
| 246 | args_info->net_given = 1; |
| 247 | args_info->net_arg = strdup (optarg); |
| 248 | break; |
| 249 | |
| 250 | case 'a': /* Access point name. */ |
| 251 | if (args_info->apn_given) |
| 252 | { |
| 253 | fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE); |
| 254 | clear_args (); |
| 255 | exit (EXIT_FAILURE); |
| 256 | } |
| 257 | args_info->apn_given = 1; |
| 258 | args_info->apn_arg = strdup (optarg); |
| 259 | break; |
| 260 | |
| 261 | case 'i': /* IMSI. */ |
| 262 | if (args_info->imsi_given) |
| 263 | { |
| 264 | fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE); |
| 265 | clear_args (); |
| 266 | exit (EXIT_FAILURE); |
| 267 | } |
| 268 | args_info->imsi_given = 1; |
| 269 | args_info->imsi_arg = strdup (optarg); |
| 270 | break; |
| 271 | |
| 272 | case 'm': /* Mobile Station ISDN number. */ |
| 273 | if (args_info->msisdn_given) |
| 274 | { |
| 275 | fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE); |
| 276 | clear_args (); |
| 277 | exit (EXIT_FAILURE); |
| 278 | } |
| 279 | args_info->msisdn_given = 1; |
| 280 | args_info->msisdn_arg = strdup (optarg); |
| 281 | break; |
| 282 | |
| 283 | case 'q': /* Requested quality of service. */ |
| 284 | if (args_info->qos_given) |
| 285 | { |
| 286 | fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE); |
| 287 | clear_args (); |
| 288 | exit (EXIT_FAILURE); |
| 289 | } |
| 290 | args_info->qos_given = 1; |
| 291 | args_info->qos_arg = strtol (optarg,&stop_char,0); |
| 292 | break; |
| 293 | |
| 294 | case 'u': /* Login user ID. */ |
| 295 | if (args_info->uid_given) |
| 296 | { |
| 297 | fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE); |
| 298 | clear_args (); |
| 299 | exit (EXIT_FAILURE); |
| 300 | } |
| 301 | args_info->uid_given = 1; |
| 302 | args_info->uid_arg = strdup (optarg); |
| 303 | break; |
| 304 | |
| 305 | case 'p': /* Login password. */ |
| 306 | if (args_info->pwd_given) |
| 307 | { |
| 308 | fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE); |
| 309 | clear_args (); |
| 310 | exit (EXIT_FAILURE); |
| 311 | } |
| 312 | args_info->pwd_given = 1; |
| 313 | args_info->pwd_arg = strdup (optarg); |
| 314 | break; |
| 315 | |
| 316 | |
| 317 | case 0: /* Long option with no short option */ |
| 318 | /* Filename of process id file. */ |
| 319 | if (strcmp (long_options[option_index].name, "pidfile") == 0) |
| 320 | { |
| 321 | if (args_info->pidfile_given) |
| 322 | { |
| 323 | fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE); |
| 324 | clear_args (); |
| 325 | exit (EXIT_FAILURE); |
| 326 | } |
| 327 | args_info->pidfile_given = 1; |
| 328 | args_info->pidfile_arg = strdup (optarg); |
| 329 | break; |
| 330 | } |
| 331 | /* Directory of nonvolatile data. */ |
| 332 | else if (strcmp (long_options[option_index].name, "statedir") == 0) |
| 333 | { |
| 334 | if (args_info->statedir_given) |
| 335 | { |
| 336 | fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE); |
| 337 | clear_args (); |
| 338 | exit (EXIT_FAILURE); |
| 339 | } |
| 340 | args_info->statedir_given = 1; |
| 341 | args_info->statedir_arg = strdup (optarg); |
| 342 | break; |
| 343 | } |
| 344 | /* DNS Server to use. */ |
| 345 | else if (strcmp (long_options[option_index].name, "dns") == 0) |
| 346 | { |
| 347 | if (args_info->dns_given) |
| 348 | { |
| 349 | fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE); |
| 350 | clear_args (); |
| 351 | exit (EXIT_FAILURE); |
| 352 | } |
| 353 | args_info->dns_given = 1; |
| 354 | args_info->dns_arg = strdup (optarg); |
| 355 | break; |
| 356 | } |
| 357 | /* Network mask. */ |
| 358 | else if (strcmp (long_options[option_index].name, "mask") == 0) |
| 359 | { |
| 360 | if (args_info->mask_given) |
| 361 | { |
| 362 | fprintf (stderr, "%s: `--mask' option given more than once\n", PACKAGE); |
| 363 | clear_args (); |
| 364 | exit (EXIT_FAILURE); |
| 365 | } |
| 366 | args_info->mask_given = 1; |
| 367 | args_info->mask_arg = strdup (optarg); |
| 368 | break; |
| 369 | } |
| 370 | /* Number of contexts. */ |
| 371 | else if (strcmp (long_options[option_index].name, "contexts") == 0) |
| 372 | { |
| 373 | if (args_info->contexts_given) |
| 374 | { |
| 375 | fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE); |
| 376 | clear_args (); |
| 377 | exit (EXIT_FAILURE); |
| 378 | } |
| 379 | args_info->contexts_given = 1; |
| 380 | args_info->contexts_arg = strtol (optarg,&stop_char,0); |
| 381 | break; |
| 382 | } |
| 383 | /* Allocate static tun ifterface. */ |
| 384 | else if (strcmp (long_options[option_index].name, "static") == 0) |
| 385 | { |
| 386 | if (args_info->static_given) |
| 387 | { |
| 388 | fprintf (stderr, "%s: `--static' option given more than once\n", PACKAGE); |
| 389 | clear_args (); |
| 390 | exit (EXIT_FAILURE); |
| 391 | } |
| 392 | args_info->static_given = 1; |
| 393 | args_info->static_flag = !(args_info->static_flag); |
| 394 | break; |
| 395 | } |
| 396 | /* Exit after timelimit seconds. */ |
| 397 | else if (strcmp (long_options[option_index].name, "timelimit") == 0) |
| 398 | { |
| 399 | if (args_info->timelimit_given) |
| 400 | { |
| 401 | fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE); |
| 402 | clear_args (); |
| 403 | exit (EXIT_FAILURE); |
| 404 | } |
| 405 | args_info->timelimit_given = 1; |
| 406 | args_info->timelimit_arg = strtol (optarg,&stop_char,0); |
| 407 | break; |
| 408 | } |
| 409 | |
| 410 | case '?': /* Invalid option. */ |
| 411 | /* `getopt_long' already printed an error message. */ |
| 412 | exit (EXIT_FAILURE); |
| 413 | |
| 414 | default: /* bug: option not considered. */ |
| 415 | fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c); |
| 416 | abort (); |
| 417 | } /* switch */ |
| 418 | } /* while */ |
| 419 | |
| 420 | |
| 421 | if ( missing_required_options ) |
| 422 | exit (EXIT_FAILURE); |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | #define CONFIGPARSERBUFSIZE 1024 |
| 428 | |
| 429 | int |
| 430 | cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override) |
| 431 | { |
| 432 | FILE* file; |
| 433 | char linebuf[CONFIGPARSERBUFSIZE]; |
| 434 | int line_num = 0; |
| 435 | int len; |
| 436 | int fnum; |
| 437 | char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE]; |
| 438 | char *stop_char; |
| 439 | |
| 440 | if ((file = fopen(filename, "r")) == NULL) |
| 441 | { |
| 442 | fprintf (stderr, "%s: Error opening configuration file '%s'\n", |
| 443 | PACKAGE, filename); |
| 444 | exit (EXIT_FAILURE); |
| 445 | } |
| 446 | |
| 447 | while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL) |
| 448 | { |
| 449 | ++line_num; |
| 450 | len = strlen(linebuf); |
| 451 | if (len == CONFIGPARSERBUFSIZE-1) |
| 452 | { |
| 453 | fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n", |
| 454 | PACKAGE, CONFIGPARSERBUFSIZE, filename); |
| 455 | exit (EXIT_FAILURE); |
| 456 | } |
| 457 | |
| 458 | if (linebuf[0] == '#') |
| 459 | continue; /* Line was a comment */ |
| 460 | |
| 461 | /* Get the option */ |
| 462 | if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0) |
| 463 | { |
| 464 | if (!strcmp(fopt, "help")) |
| 465 | { |
| 466 | if (override || !args_info->help_given) |
| 467 | { |
| 468 | args_info->help_given = 1; |
| 469 | |
| 470 | } |
| 471 | continue; |
| 472 | } |
| 473 | if (!strcmp(fopt, "version")) |
| 474 | { |
| 475 | if (override || !args_info->version_given) |
| 476 | { |
| 477 | args_info->version_given = 1; |
| 478 | |
| 479 | } |
| 480 | continue; |
| 481 | } |
| 482 | if (!strcmp(fopt, "fg")) |
| 483 | { |
| 484 | if (override || !args_info->fg_given) |
| 485 | { |
| 486 | args_info->fg_given = 1; |
| 487 | args_info->fg_flag = !(args_info->fg_flag); |
| 488 | } |
| 489 | continue; |
| 490 | } |
| 491 | if (!strcmp(fopt, "debug")) |
| 492 | { |
| 493 | if (override || !args_info->debug_given) |
| 494 | { |
| 495 | args_info->debug_given = 1; |
| 496 | args_info->debug_flag = !(args_info->debug_flag); |
| 497 | } |
| 498 | continue; |
| 499 | } |
| 500 | if (!strcmp(fopt, "conf")) |
| 501 | { |
| 502 | if (override || !args_info->conf_given) |
| 503 | { |
| 504 | args_info->conf_given = 1; |
| 505 | if (fnum == 2) |
| 506 | args_info->conf_arg = strdup (farg); |
| 507 | else |
| 508 | { |
| 509 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 510 | filename, line_num); |
| 511 | exit (EXIT_FAILURE); |
| 512 | } |
| 513 | } |
| 514 | continue; |
| 515 | } |
| 516 | if (!strcmp(fopt, "pidfile")) |
| 517 | { |
| 518 | if (override || !args_info->pidfile_given) |
| 519 | { |
| 520 | args_info->pidfile_given = 1; |
| 521 | if (fnum == 2) |
| 522 | args_info->pidfile_arg = strdup (farg); |
| 523 | else |
| 524 | { |
| 525 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 526 | filename, line_num); |
| 527 | exit (EXIT_FAILURE); |
| 528 | } |
| 529 | } |
| 530 | continue; |
| 531 | } |
| 532 | if (!strcmp(fopt, "statedir")) |
| 533 | { |
| 534 | if (override || !args_info->statedir_given) |
| 535 | { |
| 536 | args_info->statedir_given = 1; |
| 537 | if (fnum == 2) |
| 538 | args_info->statedir_arg = strdup (farg); |
| 539 | else |
| 540 | { |
| 541 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 542 | filename, line_num); |
| 543 | exit (EXIT_FAILURE); |
| 544 | } |
| 545 | } |
| 546 | continue; |
| 547 | } |
| 548 | if (!strcmp(fopt, "dns")) |
| 549 | { |
| 550 | if (override || !args_info->dns_given) |
| 551 | { |
| 552 | args_info->dns_given = 1; |
| 553 | if (fnum == 2) |
| 554 | args_info->dns_arg = strdup (farg); |
| 555 | else |
| 556 | { |
| 557 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 558 | filename, line_num); |
| 559 | exit (EXIT_FAILURE); |
| 560 | } |
| 561 | } |
| 562 | continue; |
| 563 | } |
| 564 | if (!strcmp(fopt, "listen")) |
| 565 | { |
| 566 | if (override || !args_info->listen_given) |
| 567 | { |
| 568 | args_info->listen_given = 1; |
| 569 | if (fnum == 2) |
| 570 | args_info->listen_arg = strdup (farg); |
| 571 | else |
| 572 | { |
| 573 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 574 | filename, line_num); |
| 575 | exit (EXIT_FAILURE); |
| 576 | } |
| 577 | } |
| 578 | continue; |
| 579 | } |
| 580 | if (!strcmp(fopt, "remote")) |
| 581 | { |
| 582 | if (override || !args_info->remote_given) |
| 583 | { |
| 584 | args_info->remote_given = 1; |
| 585 | if (fnum == 2) |
| 586 | args_info->remote_arg = strdup (farg); |
| 587 | else |
| 588 | { |
| 589 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 590 | filename, line_num); |
| 591 | exit (EXIT_FAILURE); |
| 592 | } |
| 593 | } |
| 594 | continue; |
| 595 | } |
| 596 | if (!strcmp(fopt, "net")) |
| 597 | { |
| 598 | if (override || !args_info->net_given) |
| 599 | { |
| 600 | args_info->net_given = 1; |
| 601 | if (fnum == 2) |
| 602 | args_info->net_arg = strdup (farg); |
| 603 | else |
| 604 | { |
| 605 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 606 | filename, line_num); |
| 607 | exit (EXIT_FAILURE); |
| 608 | } |
| 609 | } |
| 610 | continue; |
| 611 | } |
| 612 | if (!strcmp(fopt, "mask")) |
| 613 | { |
| 614 | if (override || !args_info->mask_given) |
| 615 | { |
| 616 | args_info->mask_given = 1; |
| 617 | if (fnum == 2) |
| 618 | args_info->mask_arg = strdup (farg); |
| 619 | else |
| 620 | { |
| 621 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 622 | filename, line_num); |
| 623 | exit (EXIT_FAILURE); |
| 624 | } |
| 625 | } |
| 626 | continue; |
| 627 | } |
| 628 | if (!strcmp(fopt, "contexts")) |
| 629 | { |
| 630 | if (override || !args_info->contexts_given) |
| 631 | { |
| 632 | args_info->contexts_given = 1; |
| 633 | if (fnum == 2) |
| 634 | args_info->contexts_arg = strtol (farg,&stop_char,0); |
| 635 | else |
| 636 | { |
| 637 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 638 | filename, line_num); |
| 639 | exit (EXIT_FAILURE); |
| 640 | } |
| 641 | } |
| 642 | continue; |
| 643 | } |
| 644 | if (!strcmp(fopt, "static")) |
| 645 | { |
| 646 | if (override || !args_info->static_given) |
| 647 | { |
| 648 | args_info->static_given = 1; |
| 649 | args_info->static_flag = !(args_info->static_flag); |
| 650 | } |
| 651 | continue; |
| 652 | } |
| 653 | if (!strcmp(fopt, "timelimit")) |
| 654 | { |
| 655 | if (override || !args_info->timelimit_given) |
| 656 | { |
| 657 | args_info->timelimit_given = 1; |
| 658 | if (fnum == 2) |
| 659 | args_info->timelimit_arg = strtol (farg,&stop_char,0); |
| 660 | else |
| 661 | { |
| 662 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 663 | filename, line_num); |
| 664 | exit (EXIT_FAILURE); |
| 665 | } |
| 666 | } |
| 667 | continue; |
| 668 | } |
| 669 | if (!strcmp(fopt, "apn")) |
| 670 | { |
| 671 | if (override || !args_info->apn_given) |
| 672 | { |
| 673 | args_info->apn_given = 1; |
| 674 | if (fnum == 2) |
| 675 | args_info->apn_arg = strdup (farg); |
| 676 | else |
| 677 | { |
| 678 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 679 | filename, line_num); |
| 680 | exit (EXIT_FAILURE); |
| 681 | } |
| 682 | } |
| 683 | continue; |
| 684 | } |
| 685 | if (!strcmp(fopt, "imsi")) |
| 686 | { |
| 687 | if (override || !args_info->imsi_given) |
| 688 | { |
| 689 | args_info->imsi_given = 1; |
| 690 | if (fnum == 2) |
| 691 | args_info->imsi_arg = strdup (farg); |
| 692 | else |
| 693 | { |
| 694 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 695 | filename, line_num); |
| 696 | exit (EXIT_FAILURE); |
| 697 | } |
| 698 | } |
| 699 | continue; |
| 700 | } |
| 701 | if (!strcmp(fopt, "msisdn")) |
| 702 | { |
| 703 | if (override || !args_info->msisdn_given) |
| 704 | { |
| 705 | args_info->msisdn_given = 1; |
| 706 | if (fnum == 2) |
| 707 | args_info->msisdn_arg = strdup (farg); |
| 708 | else |
| 709 | { |
| 710 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 711 | filename, line_num); |
| 712 | exit (EXIT_FAILURE); |
| 713 | } |
| 714 | } |
| 715 | continue; |
| 716 | } |
| 717 | if (!strcmp(fopt, "qos")) |
| 718 | { |
| 719 | if (override || !args_info->qos_given) |
| 720 | { |
| 721 | args_info->qos_given = 1; |
| 722 | if (fnum == 2) |
| 723 | args_info->qos_arg = strtol (farg,&stop_char,0); |
| 724 | else |
| 725 | { |
| 726 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 727 | filename, line_num); |
| 728 | exit (EXIT_FAILURE); |
| 729 | } |
| 730 | } |
| 731 | continue; |
| 732 | } |
| 733 | if (!strcmp(fopt, "uid")) |
| 734 | { |
| 735 | if (override || !args_info->uid_given) |
| 736 | { |
| 737 | args_info->uid_given = 1; |
| 738 | if (fnum == 2) |
| 739 | args_info->uid_arg = strdup (farg); |
| 740 | else |
| 741 | { |
| 742 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 743 | filename, line_num); |
| 744 | exit (EXIT_FAILURE); |
| 745 | } |
| 746 | } |
| 747 | continue; |
| 748 | } |
| 749 | if (!strcmp(fopt, "pwd")) |
| 750 | { |
| 751 | if (override || !args_info->pwd_given) |
| 752 | { |
| 753 | args_info->pwd_given = 1; |
| 754 | if (fnum == 2) |
| 755 | args_info->pwd_arg = strdup (farg); |
| 756 | else |
| 757 | { |
| 758 | fprintf (stderr, "%s:%d: required <option_name> <option_val>\n", |
| 759 | filename, line_num); |
| 760 | exit (EXIT_FAILURE); |
| 761 | } |
| 762 | } |
| 763 | continue; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | /* Tried all known options. This one is unknown! */ |
| 768 | fprintf (stderr, "%s: Unknown option '%s' found in %s\n", |
| 769 | PACKAGE, fopt, filename); |
| 770 | exit (EXIT_FAILURE); |
| 771 | } |
| 772 | } /* while */ |
| 773 | fclose(file); /* No error checking on close */ |
| 774 | |
| 775 | return 0; |
| 776 | } |