⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmdline.c

📁 NGN-3G核心部件SGSN的代码实现
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
  File autogenerated by gengetopt version 2.8
  generated with the following command:
  gengetopt --conf-parser 

  The developers of gengetopt consider the fixed text that goes in all
  gengetopt output files to be in the public domain:
  we make no copyright claims on it.
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* If we use autoconf.  */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* Check for configure's getopt check result.  */
#ifndef HAVE_GETOPT_LONG
#include "getopt.h"
#else
#include <getopt.h>
#endif

#ifndef HAVE_STRDUP
#define strdup gengetopt_strdup
#endif /* HAVE_STRDUP */

#include "cmdline.h"


void
cmdline_parser_print_version (void)
{
  printf ("%s %s\n", PACKAGE, VERSION);
}

void
cmdline_parser_print_help (void)
{
  cmdline_parser_print_version ();
  printf("\n"
  "Usage: %s [OPTIONS]...\n", PACKAGE);
  printf("   -h         --help             Print help and exit\n");
  printf("   -V         --version          Print version and exit\n");
  printf("   -d         --debug            Run in debug mode (default=off)\n");
  printf("   -cSTRING   --conf=STRING      Read configuration file\n");
  printf("              --pidfile=STRING   Filename of process id file (default='./sgsnemu.pid')\n");
  printf("              --statedir=STRING  Directory of nonvolatile data (default='./')\n");
  printf("              --dns=STRING       DNS Server to use\n");
  printf("   -lSTRING   --listen=STRING    Local interface\n");
  printf("   -rSTRING   --remote=STRING    Remote host\n");
  printf("              --contexts=INT     Number of contexts (default='1')\n");
  printf("              --timelimit=INT    Exit after timelimit seconds (default='0')\n");
  printf("              --gtpversion=INT   GTP version to use (default='1')\n");
  printf("   -aSTRING   --apn=STRING       Access point name (default='internet')\n");
  printf("              --selmode=INT      Selection mode (default='0x01')\n");
  printf("   -iSTRING   --imsi=STRING      IMSI (default='240010123456789')\n");
  printf("              --nsapi=INT        NSAPI (default='0')\n");
  printf("   -mSTRING   --msisdn=STRING    Mobile Station ISDN number (default='46702123456')\n");
  printf("   -qINT      --qos=INT          Requested quality of service (default='0x0b921f')\n");
  printf("              --charging=INT     Charging characteristics (default='0x0800')\n");
  printf("   -uSTRING   --uid=STRING       Login user ID (default='mig')\n");
  printf("   -pSTRING   --pwd=STRING       Login password (default='hemmelig')\n");
  printf("              --createif         Create local network interface (default=off)\n");
  printf("   -nSTRING   --net=STRING       Network address for local interface\n");
  printf("              --defaultroute     Create default route (default=off)\n");
  printf("              --ipup=STRING      Script to run after link-up\n");
  printf("              --ipdown=STRING    Script to run after link-down\n");
  printf("              --pinghost=STRING  Ping remote host\n");
  printf("              --pingrate=INT     Number of ping req per second (default='1')\n");
  printf("              --pingsize=INT     Number of ping data bytes (default='56')\n");
  printf("              --pingcount=INT    Number of ping req to send (default='0')\n");
  printf("              --pingquiet        Do not print ping packet info (default=off)\n");
}


#ifndef HAVE_STRDUP
/* gengetopt_strdup(): automatically generated from strdup.c. */
/* strdup.c replacement of strdup, which is not standard */
static char *
gengetopt_strdup (const char *s)
{
  char *result = (char*)malloc(strlen(s) + 1);
  if (result == (char*)0)
    return (char*)0;
  strcpy(result, s);
  return result;
}
#endif /* HAVE_STRDUP */

int
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
{
  int c;	/* Character of the parsed option.  */
  int missing_required_options = 0;

  args_info->help_given = 0 ;
  args_info->version_given = 0 ;
  args_info->debug_given = 0 ;
  args_info->conf_given = 0 ;
  args_info->pidfile_given = 0 ;
  args_info->statedir_given = 0 ;
  args_info->dns_given = 0 ;
  args_info->listen_given = 0 ;
  args_info->remote_given = 0 ;
  args_info->contexts_given = 0 ;
  args_info->timelimit_given = 0 ;
  args_info->gtpversion_given = 0 ;
  args_info->apn_given = 0 ;
  args_info->selmode_given = 0 ;
  args_info->imsi_given = 0 ;
  args_info->nsapi_given = 0 ;
  args_info->msisdn_given = 0 ;
  args_info->qos_given = 0 ;
  args_info->charging_given = 0 ;
  args_info->uid_given = 0 ;
  args_info->pwd_given = 0 ;
  args_info->createif_given = 0 ;
  args_info->net_given = 0 ;
  args_info->defaultroute_given = 0 ;
  args_info->ipup_given = 0 ;
  args_info->ipdown_given = 0 ;
  args_info->pinghost_given = 0 ;
  args_info->pingrate_given = 0 ;
  args_info->pingsize_given = 0 ;
  args_info->pingcount_given = 0 ;
  args_info->pingquiet_given = 0 ;
#define clear_args() { \
  args_info->debug_flag = 0;\
  args_info->conf_arg = NULL; \
  args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
  args_info->statedir_arg = strdup("./") ;\
  args_info->dns_arg = NULL; \
  args_info->listen_arg = NULL; \
  args_info->remote_arg = NULL; \
  args_info->contexts_arg = 1 ;\
  args_info->timelimit_arg = 0 ;\
  args_info->gtpversion_arg = 1 ;\
  args_info->apn_arg = strdup("internet") ;\
  args_info->selmode_arg = 0x01 ;\
  args_info->imsi_arg = strdup("240010123456789") ;\
  args_info->nsapi_arg = 0 ;\
  args_info->msisdn_arg = strdup("46702123456") ;\
  args_info->qos_arg = 0x0b921f ;\
  args_info->charging_arg = 0x0800 ;\
  args_info->uid_arg = strdup("mig") ;\
  args_info->pwd_arg = strdup("hemmelig") ;\
  args_info->createif_flag = 0;\
  args_info->net_arg = NULL; \
  args_info->defaultroute_flag = 0;\
  args_info->ipup_arg = NULL; \
  args_info->ipdown_arg = NULL; \
  args_info->pinghost_arg = NULL; \
  args_info->pingrate_arg = 1 ;\
  args_info->pingsize_arg = 56 ;\
  args_info->pingcount_arg = 0 ;\
  args_info->pingquiet_flag = 0;\
}

  clear_args();

  optarg = 0;
  optind = 1;
  opterr = 1;
  optopt = '?';

  while (1)
    {
      int option_index = 0;
      char *stop_char;
      static struct option long_options[] = {
        { "help",	0, NULL, 'h' },
        { "version",	0, NULL, 'V' },
        { "debug",	0, NULL, 'd' },
        { "conf",	1, NULL, 'c' },
        { "pidfile",	1, NULL, 0 },
        { "statedir",	1, NULL, 0 },
        { "dns",	1, NULL, 0 },
        { "listen",	1, NULL, 'l' },
        { "remote",	1, NULL, 'r' },
        { "contexts",	1, NULL, 0 },
        { "timelimit",	1, NULL, 0 },
        { "gtpversion",	1, NULL, 0 },
        { "apn",	1, NULL, 'a' },
        { "selmode",	1, NULL, 0 },
        { "imsi",	1, NULL, 'i' },
        { "nsapi",	1, NULL, 0 },
        { "msisdn",	1, NULL, 'm' },
        { "qos",	1, NULL, 'q' },
        { "charging",	1, NULL, 0 },
        { "uid",	1, NULL, 'u' },
        { "pwd",	1, NULL, 'p' },
        { "createif",	0, NULL, 0 },
        { "net",	1, NULL, 'n' },
        { "defaultroute",	0, NULL, 0 },
        { "ipup",	1, NULL, 0 },
        { "ipdown",	1, NULL, 0 },
        { "pinghost",	1, NULL, 0 },
        { "pingrate",	1, NULL, 0 },
        { "pingsize",	1, NULL, 0 },
        { "pingcount",	1, NULL, 0 },
        { "pingquiet",	0, NULL, 0 },
        { NULL,	0, NULL, 0 }
      };

      c = getopt_long (argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:", long_options, &option_index);

      if (c == -1) break;	/* Exit from `while (1)' loop.  */

      switch (c)
        {
        case 'h':	/* Print help and exit.  */
          clear_args ();
          cmdline_parser_print_help ();
          exit (EXIT_SUCCESS);

        case 'V':	/* Print version and exit.  */
          clear_args ();
          cmdline_parser_print_version ();
          exit (EXIT_SUCCESS);

        case 'd':	/* Run in debug mode.  */
          if (args_info->debug_given)
            {
              fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->debug_given = 1;
          args_info->debug_flag = !(args_info->debug_flag);
          break;

        case 'c':	/* Read configuration file.  */
          if (args_info->conf_given)
            {
              fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->conf_given = 1;
          args_info->conf_arg = strdup (optarg);
          break;

        case 'l':	/* Local interface.  */
          if (args_info->listen_given)
            {
              fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->listen_given = 1;
          args_info->listen_arg = strdup (optarg);
          break;

        case 'r':	/* Remote host.  */
          if (args_info->remote_given)
            {
              fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->remote_given = 1;
          args_info->remote_arg = strdup (optarg);
          break;

        case 'a':	/* Access point name.  */
          if (args_info->apn_given)
            {
              fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->apn_given = 1;
          args_info->apn_arg = strdup (optarg);
          break;

        case 'i':	/* IMSI.  */
          if (args_info->imsi_given)
            {
              fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->imsi_given = 1;
          args_info->imsi_arg = strdup (optarg);
          break;

        case 'm':	/* Mobile Station ISDN number.  */
          if (args_info->msisdn_given)
            {
              fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->msisdn_given = 1;
          args_info->msisdn_arg = strdup (optarg);
          break;

        case 'q':	/* Requested quality of service.  */
          if (args_info->qos_given)
            {
              fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->qos_given = 1;
          args_info->qos_arg = strtol (optarg,&stop_char,0);
          break;

        case 'u':	/* Login user ID.  */
          if (args_info->uid_given)
            {
              fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->uid_given = 1;
          args_info->uid_arg = strdup (optarg);
          break;

        case 'p':	/* Login password.  */
          if (args_info->pwd_given)
            {
              fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->pwd_given = 1;
          args_info->pwd_arg = strdup (optarg);
          break;

        case 'n':	/* Network address for local interface.  */
          if (args_info->net_given)
            {
              fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE);
              clear_args ();
              exit (EXIT_FAILURE);
            }
          args_info->net_given = 1;
          args_info->net_arg = strdup (optarg);
          break;


        case 0:	/* Long option with no short option */
          /* Filename of process id file.  */
          if (strcmp (long_options[option_index].name, "pidfile") == 0)
          {
            if (args_info->pidfile_given)
              {
                fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }
            args_info->pidfile_given = 1;
            args_info->pidfile_arg = strdup (optarg);
            break;
          }
          /* Directory of nonvolatile data.  */
          else if (strcmp (long_options[option_index].name, "statedir") == 0)
          {
            if (args_info->statedir_given)
              {
                fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
                clear_args ();
                exit (EXIT_FAILURE);
              }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -