aboutsummaryrefslogtreecommitdiffstats
path: root/sgsnemu
diff options
context:
space:
mode:
Diffstat (limited to 'sgsnemu')
-rw-r--r--sgsnemu/cmdline.c3449
-rw-r--r--sgsnemu/cmdline.h369
-rw-r--r--sgsnemu/sgsnemu.c3006
3 files changed, 3532 insertions, 3292 deletions
diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c
index 1c4c041..1ff1a59 100644
--- a/sgsnemu/cmdline.c
+++ b/sgsnemu/cmdline.c
@@ -23,1560 +23,1732 @@
const char *gengetopt_args_info_purpose = "";
-const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
+const char *gengetopt_args_info_usage =
+ "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
const char *gengetopt_args_info_help[] = {
- " -h, --help Print help and exit",
- " -V, --version Print version and exit",
- " -d, --debug Run in debug mode (default=off)",
- " -c, --conf=STRING Read configuration file",
- " --pidfile=STRING Filename of process id file (default=`./sgsnemu.pid')",
- " --statedir=STRING Directory of nonvolatile data (default=`./')",
- " --dns=STRING DNS Server to use",
- " -l, --listen=STRING Local interface",
- " -r, --remote=STRING Remote host",
- " --contexts=INT Number of contexts (default=`1')",
- " --timelimit=INT Exit after timelimit seconds (default=`0')",
- " --gtpversion=INT GTP version to use (default=`1')",
- " -a, --apn=STRING Access point name (default=`internet')",
- " --selmode=INT Selection mode (default=`0x01')",
- " --rattype=INT Radio Access Technology Type (optional-1to5)",
- " --userloc=STRING User Location Information (optional-type.MCC.MNC.LAC.CIorSACorRAC)",
- " --rai=STRING Routing Area Information (optional-MCC.MNC.LAC.RAC)",
- " --mstz=STRING MS Time Zone (optional- sign.NbQuartersOfAnHour.DSTAdjustment)",
- " --imeisv=STRING IMEI(SV) International Mobile Equipment Identity (and Software Version) (optional,16 digits)",
- " -i, --imsi=STRING IMSI (default=`240010123456789')",
- " --nsapi=INT NSAPI (default=`0')",
- " -m, --msisdn=STRING Mobile Station ISDN number (default=`46702123456')",
- " -q, --qos=INT Requested quality of service (default=`0x000b921f')",
- " --qose1=INT Requested quality of service Extension 1 (example=`0x9396404074f9ffff')",
- " --qose2=INT Requested quality of service Extension 2 (example=`0x11')",
- " --qose3=INT Requested quality of service Extension 3 (example=`0x0101')",
- " --qose4=INT Requested quality of service Extension 4 (example=`0x4040')",
- " --charging=INT Charging characteristics (default=`0x0800')",
- " -u, --uid=STRING Login user ID (default=`mig')",
- " -p, --pwd=STRING Login password (default=`hemmelig')",
- " --createif Create local network interface (default=off)",
- " -n, --net=STRING Network address for local interface",
- " --defaultroute Create default route (default=off)",
- " --ipup=STRING Script to run after link-up",
- " --ipdown=STRING Script to run after link-down",
- " --pinghost=STRING Ping remote host",
- " --pingrate=INT Number of ping req per second (default=`1')",
- " --pingsize=INT Number of ping data bytes (default=`56')",
- " --pingcount=INT Number of ping req to send (default=`0')",
- " --pingquiet Do not print ping packet info (default=off)",
- " --norecovery Do not send recovery (default=off)",
- 0
+ " -h, --help Print help and exit",
+ " -V, --version Print version and exit",
+ " -d, --debug Run in debug mode (default=off)",
+ " -c, --conf=STRING Read configuration file",
+ " --pidfile=STRING Filename of process id file (default=`./sgsnemu.pid')",
+ " --statedir=STRING Directory of nonvolatile data (default=`./')",
+ " --dns=STRING DNS Server to use",
+ " -l, --listen=STRING Local interface",
+ " -r, --remote=STRING Remote host",
+ " --contexts=INT Number of contexts (default=`1')",
+ " --timelimit=INT Exit after timelimit seconds (default=`0')",
+ " --gtpversion=INT GTP version to use (default=`1')",
+ " -a, --apn=STRING Access point name (default=`internet')",
+ " --selmode=INT Selection mode (default=`0x01')",
+ " --rattype=INT Radio Access Technology Type (optional-1to5)",
+ " --userloc=STRING User Location Information (optional-type.MCC.MNC.LAC.CIorSACorRAC)",
+ " --rai=STRING Routing Area Information (optional-MCC.MNC.LAC.RAC)",
+ " --mstz=STRING MS Time Zone (optional- sign.NbQuartersOfAnHour.DSTAdjustment)",
+ " --imeisv=STRING IMEI(SV) International Mobile Equipment Identity (and Software Version) (optional,16 digits)",
+ " -i, --imsi=STRING IMSI (default=`240010123456789')",
+ " --nsapi=INT NSAPI (default=`0')",
+ " -m, --msisdn=STRING Mobile Station ISDN number (default=`46702123456')",
+ " -q, --qos=INT Requested quality of service (default=`0x000b921f')",
+ " --qose1=INT Requested quality of service Extension 1 (example=`0x9396404074f9ffff')",
+ " --qose2=INT Requested quality of service Extension 2 (example=`0x11')",
+ " --qose3=INT Requested quality of service Extension 3 (example=`0x0101')",
+ " --qose4=INT Requested quality of service Extension 4 (example=`0x4040')",
+ " --charging=INT Charging characteristics (default=`0x0800')",
+ " -u, --uid=STRING Login user ID (default=`mig')",
+ " -p, --pwd=STRING Login password (default=`hemmelig')",
+ " --createif Create local network interface (default=off)",
+ " -n, --net=STRING Network address for local interface",
+ " --defaultroute Create default route (default=off)",
+ " --ipup=STRING Script to run after link-up",
+ " --ipdown=STRING Script to run after link-down",
+ " --pinghost=STRING Ping remote host",
+ " --pingrate=INT Number of ping req per second (default=`1')",
+ " --pingsize=INT Number of ping data bytes (default=`56')",
+ " --pingcount=INT Number of ping req to send (default=`0')",
+ " --pingquiet Do not print ping packet info (default=off)",
+ " --norecovery Do not send recovery (default=off)",
+ 0
};
static
-void clear_given (struct gengetopt_args_info *args_info);
+void clear_given(struct gengetopt_args_info *args_info);
static
-void clear_args (struct gengetopt_args_info *args_info);
+void clear_args(struct gengetopt_args_info *args_info);
static int
-cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
-
-struct line_list
-{
- char * string_arg;
- struct line_list * next;
+cmdline_parser_internal(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info, int override,
+ int initialize, int check_required,
+ const char *additional_error);
+
+struct line_list {
+ char *string_arg;
+ struct line_list *next;
};
static struct line_list *cmd_line_list = 0;
static struct line_list *cmd_line_list_tmp = 0;
-static void
-free_cmd_list(void)
+static void free_cmd_list(void)
{
- /* free the list of a previous call */
- if (cmd_line_list)
- {
- while (cmd_line_list) {
- cmd_line_list_tmp = cmd_line_list;
- cmd_line_list = cmd_line_list->next;
- free (cmd_line_list_tmp->string_arg);
- free (cmd_line_list_tmp);
- }
- }
+ /* free the list of a previous call */
+ if (cmd_line_list) {
+ while (cmd_line_list) {
+ cmd_line_list_tmp = cmd_line_list;
+ cmd_line_list = cmd_line_list->next;
+ free(cmd_line_list_tmp->string_arg);
+ free(cmd_line_list_tmp);
+ }
+ }
}
-
-static char *
-gengetopt_strdup (const char *s);
+static char *gengetopt_strdup(const char *s);
static
-void clear_given (struct gengetopt_args_info *args_info)
+void clear_given(struct gengetopt_args_info *args_info)
{
- 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->rattype_given = 0 ;
- args_info->userloc_given = 0 ;
- args_info->rai_given = 0 ;
- args_info->mstz_given = 0 ;
- args_info->imeisv_given = 0 ;
- args_info->imsi_given = 0 ;
- args_info->nsapi_given = 0 ;
- args_info->msisdn_given = 0 ;
- args_info->qos_given = 0 ;
- args_info->qose1_given = 0 ;
- args_info->qose2_given = 0 ;
- args_info->qose3_given = 0 ;
- args_info->qose4_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 ;
- args_info->norecovery_given = 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->rattype_given = 0;
+ args_info->userloc_given = 0;
+ args_info->rai_given = 0;
+ args_info->mstz_given = 0;
+ args_info->imeisv_given = 0;
+ args_info->imsi_given = 0;
+ args_info->nsapi_given = 0;
+ args_info->msisdn_given = 0;
+ args_info->qos_given = 0;
+ args_info->qose1_given = 0;
+ args_info->qose2_given = 0;
+ args_info->qose3_given = 0;
+ args_info->qose4_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;
+ args_info->norecovery_given = 0;
}
static
-void clear_args (struct gengetopt_args_info *args_info)
+void clear_args(struct gengetopt_args_info *args_info)
{
- args_info->debug_flag = 0;
- args_info->conf_arg = NULL;
- args_info->conf_orig = NULL;
- args_info->pidfile_arg = gengetopt_strdup ("./sgsnemu.pid");
- args_info->pidfile_orig = NULL;
- args_info->statedir_arg = gengetopt_strdup ("./");
- args_info->statedir_orig = NULL;
- args_info->dns_arg = NULL;
- args_info->dns_orig = NULL;
- args_info->listen_arg = NULL;
- args_info->listen_orig = NULL;
- args_info->remote_arg = NULL;
- args_info->remote_orig = NULL;
- args_info->contexts_arg = 1;
- args_info->contexts_orig = NULL;
- args_info->timelimit_arg = 0;
- args_info->timelimit_orig = NULL;
- args_info->gtpversion_arg = 1;
- args_info->gtpversion_orig = NULL;
- args_info->apn_arg = gengetopt_strdup ("internet");
- args_info->apn_orig = NULL;
- args_info->selmode_arg = 0x01;
- args_info->selmode_orig = NULL;
- args_info->rattype_arg = "1";
- args_info->rattype_orig = NULL;
- args_info->userloc_arg = strdup("02509946241207");
- args_info->userloc_orig = NULL;
- args_info->rai_arg = strdup("02509946241207");
- args_info->rai_orig = NULL;
- args_info->mstz_arg = strdup("0");
- args_info->mstz_orig = NULL;
- args_info->imeisv_arg = strdup("2143658709214365");
- args_info->imeisv_orig = NULL;
- args_info->imsi_arg = gengetopt_strdup ("240010123456789");
- args_info->imsi_orig = NULL;
- args_info->nsapi_arg = 0;
- args_info->nsapi_orig = NULL;
- args_info->msisdn_arg = gengetopt_strdup ("46702123456");
- args_info->msisdn_orig = NULL;
- args_info->qos_arg = 0x000b921f;
- args_info->qos_orig = NULL;
- args_info->qose1_arg = 0x9396404074f9ffff;
- args_info->qose1_orig = NULL;
- args_info->qose2_arg = 0x11;
- args_info->qose2_orig = NULL;
- args_info->qose3_arg = 0x0101;
- args_info->qose3_orig = NULL;
- args_info->qose4_arg = 0x4040;
- args_info->qose4_orig = NULL;
- args_info->charging_arg = 0x0800;
- args_info->charging_orig = NULL;
- args_info->uid_arg = gengetopt_strdup ("mig");
- args_info->uid_orig = NULL;
- args_info->pwd_arg = gengetopt_strdup ("hemmelig");
- args_info->pwd_orig = NULL;
- args_info->createif_flag = 0;
- args_info->net_arg = NULL;
- args_info->net_orig = NULL;
- args_info->defaultroute_flag = 0;
- args_info->ipup_arg = NULL;
- args_info->ipup_orig = NULL;
- args_info->ipdown_arg = NULL;
- args_info->ipdown_orig = NULL;
- args_info->pinghost_arg = NULL;
- args_info->pinghost_orig = NULL;
- args_info->pingrate_arg = 1;
- args_info->pingrate_orig = NULL;
- args_info->pingsize_arg = 56;
- args_info->pingsize_orig = NULL;
- args_info->pingcount_arg = 0;
- args_info->pingcount_orig = NULL;
- args_info->pingquiet_flag = 0;
- args_info->norecovery_flag = 0;
-
+ args_info->debug_flag = 0;
+ args_info->conf_arg = NULL;
+ args_info->conf_orig = NULL;
+ args_info->pidfile_arg = gengetopt_strdup("./sgsnemu.pid");
+ args_info->pidfile_orig = NULL;
+ args_info->statedir_arg = gengetopt_strdup("./");
+ args_info->statedir_orig = NULL;
+ args_info->dns_arg = NULL;
+ args_info->dns_orig = NULL;
+ args_info->listen_arg = NULL;
+ args_info->listen_orig = NULL;
+ args_info->remote_arg = NULL;
+ args_info->remote_orig = NULL;
+ args_info->contexts_arg = 1;
+ args_info->contexts_orig = NULL;
+ args_info->timelimit_arg = 0;
+ args_info->timelimit_orig = NULL;
+ args_info->gtpversion_arg = 1;
+ args_info->gtpversion_orig = NULL;
+ args_info->apn_arg = gengetopt_strdup("internet");
+ args_info->apn_orig = NULL;
+ args_info->selmode_arg = 0x01;
+ args_info->selmode_orig = NULL;
+ args_info->rattype_arg = "1";
+ args_info->rattype_orig = NULL;
+ args_info->userloc_arg = strdup("02509946241207");
+ args_info->userloc_orig = NULL;
+ args_info->rai_arg = strdup("02509946241207");
+ args_info->rai_orig = NULL;
+ args_info->mstz_arg = strdup("0");
+ args_info->mstz_orig = NULL;
+ args_info->imeisv_arg = strdup("2143658709214365");
+ args_info->imeisv_orig = NULL;
+ args_info->imsi_arg = gengetopt_strdup("240010123456789");
+ args_info->imsi_orig = NULL;
+ args_info->nsapi_arg = 0;
+ args_info->nsapi_orig = NULL;
+ args_info->msisdn_arg = gengetopt_strdup("46702123456");
+ args_info->msisdn_orig = NULL;
+ args_info->qos_arg = 0x000b921f;
+ args_info->qos_orig = NULL;
+ args_info->qose1_arg = 0x9396404074f9ffff;
+ args_info->qose1_orig = NULL;
+ args_info->qose2_arg = 0x11;
+ args_info->qose2_orig = NULL;
+ args_info->qose3_arg = 0x0101;
+ args_info->qose3_orig = NULL;
+ args_info->qose4_arg = 0x4040;
+ args_info->qose4_orig = NULL;
+ args_info->charging_arg = 0x0800;
+ args_info->charging_orig = NULL;
+ args_info->uid_arg = gengetopt_strdup("mig");
+ args_info->uid_orig = NULL;
+ args_info->pwd_arg = gengetopt_strdup("hemmelig");
+ args_info->pwd_orig = NULL;
+ args_info->createif_flag = 0;
+ args_info->net_arg = NULL;
+ args_info->net_orig = NULL;
+ args_info->defaultroute_flag = 0;
+ args_info->ipup_arg = NULL;
+ args_info->ipup_orig = NULL;
+ args_info->ipdown_arg = NULL;
+ args_info->ipdown_orig = NULL;
+ args_info->pinghost_arg = NULL;
+ args_info->pinghost_orig = NULL;
+ args_info->pingrate_arg = 1;
+ args_info->pingrate_orig = NULL;
+ args_info->pingsize_arg = 56;
+ args_info->pingsize_orig = NULL;
+ args_info->pingcount_arg = 0;
+ args_info->pingcount_orig = NULL;
+ args_info->pingquiet_flag = 0;
+ args_info->norecovery_flag = 0;
+
}
static
void init_args_info(struct gengetopt_args_info *args_info)
{
- args_info->help_help = gengetopt_args_info_help[0] ;
- args_info->version_help = gengetopt_args_info_help[1] ;
- args_info->debug_help = gengetopt_args_info_help[2] ;
- args_info->conf_help = gengetopt_args_info_help[3] ;
- args_info->pidfile_help = gengetopt_args_info_help[4] ;
- args_info->statedir_help = gengetopt_args_info_help[5] ;
- args_info->dns_help = gengetopt_args_info_help[6] ;
- args_info->listen_help = gengetopt_args_info_help[7] ;
- args_info->remote_help = gengetopt_args_info_help[8] ;
- args_info->contexts_help = gengetopt_args_info_help[9] ;
- args_info->timelimit_help = gengetopt_args_info_help[10] ;
- args_info->gtpversion_help = gengetopt_args_info_help[11] ;
- args_info->apn_help = gengetopt_args_info_help[12] ;
- args_info->selmode_help = gengetopt_args_info_help[13] ;
- args_info->imsi_help = gengetopt_args_info_help[14] ;
- args_info->nsapi_help = gengetopt_args_info_help[15] ;
- args_info->msisdn_help = gengetopt_args_info_help[16] ;
- args_info->qos_help = gengetopt_args_info_help[17] ;
- args_info->charging_help = gengetopt_args_info_help[18] ;
- args_info->uid_help = gengetopt_args_info_help[19] ;
- args_info->pwd_help = gengetopt_args_info_help[20] ;
- args_info->createif_help = gengetopt_args_info_help[21] ;
- args_info->net_help = gengetopt_args_info_help[22] ;
- args_info->defaultroute_help = gengetopt_args_info_help[23] ;
- args_info->ipup_help = gengetopt_args_info_help[24] ;
- args_info->ipdown_help = gengetopt_args_info_help[25] ;
- args_info->pinghost_help = gengetopt_args_info_help[26] ;
- args_info->pingrate_help = gengetopt_args_info_help[27] ;
- args_info->pingsize_help = gengetopt_args_info_help[28] ;
- args_info->pingcount_help = gengetopt_args_info_help[29] ;
- args_info->pingquiet_help = gengetopt_args_info_help[30] ;
- args_info->norecovery_help = gengetopt_args_info_help[31] ;
-
+ args_info->help_help = gengetopt_args_info_help[0];
+ args_info->version_help = gengetopt_args_info_help[1];
+ args_info->debug_help = gengetopt_args_info_help[2];
+ args_info->conf_help = gengetopt_args_info_help[3];
+ args_info->pidfile_help = gengetopt_args_info_help[4];
+ args_info->statedir_help = gengetopt_args_info_help[5];
+ args_info->dns_help = gengetopt_args_info_help[6];
+ args_info->listen_help = gengetopt_args_info_help[7];
+ args_info->remote_help = gengetopt_args_info_help[8];
+ args_info->contexts_help = gengetopt_args_info_help[9];
+ args_info->timelimit_help = gengetopt_args_info_help[10];
+ args_info->gtpversion_help = gengetopt_args_info_help[11];
+ args_info->apn_help = gengetopt_args_info_help[12];
+ args_info->selmode_help = gengetopt_args_info_help[13];
+ args_info->imsi_help = gengetopt_args_info_help[14];
+ args_info->nsapi_help = gengetopt_args_info_help[15];
+ args_info->msisdn_help = gengetopt_args_info_help[16];
+ args_info->qos_help = gengetopt_args_info_help[17];
+ args_info->charging_help = gengetopt_args_info_help[18];
+ args_info->uid_help = gengetopt_args_info_help[19];
+ args_info->pwd_help = gengetopt_args_info_help[20];
+ args_info->createif_help = gengetopt_args_info_help[21];
+ args_info->net_help = gengetopt_args_info_help[22];
+ args_info->defaultroute_help = gengetopt_args_info_help[23];
+ args_info->ipup_help = gengetopt_args_info_help[24];
+ args_info->ipdown_help = gengetopt_args_info_help[25];
+ args_info->pinghost_help = gengetopt_args_info_help[26];
+ args_info->pingrate_help = gengetopt_args_info_help[27];
+ args_info->pingsize_help = gengetopt_args_info_help[28];
+ args_info->pingcount_help = gengetopt_args_info_help[29];
+ args_info->pingquiet_help = gengetopt_args_info_help[30];
+ args_info->norecovery_help = gengetopt_args_info_help[31];
+
}
-void
-cmdline_parser_print_version (void)
+void cmdline_parser_print_version(void)
{
- printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
+ printf("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
}
-void
-cmdline_parser_print_help (void)
+void cmdline_parser_print_help(void)
{
- int i = 0;
- cmdline_parser_print_version ();
+ int i = 0;
+ cmdline_parser_print_version();
- if (strlen(gengetopt_args_info_purpose) > 0)
- printf("\n%s\n", gengetopt_args_info_purpose);
+ if (strlen(gengetopt_args_info_purpose) > 0)
+ printf("\n%s\n", gengetopt_args_info_purpose);
- printf("\n%s\n\n", gengetopt_args_info_usage);
- while (gengetopt_args_info_help[i])
- printf("%s\n", gengetopt_args_info_help[i++]);
+ printf("\n%s\n\n", gengetopt_args_info_usage);
+ while (gengetopt_args_info_help[i])
+ printf("%s\n", gengetopt_args_info_help[i++]);
}
-void
-cmdline_parser_init (struct gengetopt_args_info *args_info)
+void cmdline_parser_init(struct gengetopt_args_info *args_info)
{
- clear_given (args_info);
- clear_args (args_info);
- init_args_info (args_info);
+ clear_given(args_info);
+ clear_args(args_info);
+ init_args_info(args_info);
}
-static void
-cmdline_parser_release (struct gengetopt_args_info *args_info)
+static void cmdline_parser_release(struct gengetopt_args_info *args_info)
{
-
- if (args_info->conf_arg)
- {
- free (args_info->conf_arg); /* free previous argument */
- args_info->conf_arg = 0;
- }
- if (args_info->conf_orig)
- {
- free (args_info->conf_orig); /* free previous argument */
- args_info->conf_orig = 0;
- }
- if (args_info->pidfile_arg)
- {
- free (args_info->pidfile_arg); /* free previous argument */
- args_info->pidfile_arg = 0;
- }
- if (args_info->pidfile_orig)
- {
- free (args_info->pidfile_orig); /* free previous argument */
- args_info->pidfile_orig = 0;
- }
- if (args_info->statedir_arg)
- {
- free (args_info->statedir_arg); /* free previous argument */
- args_info->statedir_arg = 0;
- }
- if (args_info->statedir_orig)
- {
- free (args_info->statedir_orig); /* free previous argument */
- args_info->statedir_orig = 0;
- }
- if (args_info->dns_arg)
- {
- free (args_info->dns_arg); /* free previous argument */
- args_info->dns_arg = 0;
- }
- if (args_info->dns_orig)
- {
- free (args_info->dns_orig); /* free previous argument */
- args_info->dns_orig = 0;
- }
- if (args_info->listen_arg)
- {
- free (args_info->listen_arg); /* free previous argument */
- args_info->listen_arg = 0;
- }
- if (args_info->listen_orig)
- {
- free (args_info->listen_orig); /* free previous argument */
- args_info->listen_orig = 0;
- }
- if (args_info->remote_arg)
- {
- free (args_info->remote_arg); /* free previous argument */
- args_info->remote_arg = 0;
- }
- if (args_info->remote_orig)
- {
- free (args_info->remote_orig); /* free previous argument */
- args_info->remote_orig = 0;
- }
- if (args_info->contexts_orig)
- {
- free (args_info->contexts_orig); /* free previous argument */
- args_info->contexts_orig = 0;
- }
- if (args_info->timelimit_orig)
- {
- free (args_info->timelimit_orig); /* free previous argument */
- args_info->timelimit_orig = 0;
- }
- if (args_info->gtpversion_orig)
- {
- free (args_info->gtpversion_orig); /* free previous argument */
- args_info->gtpversion_orig = 0;
- }
- if (args_info->apn_arg)
- {
- free (args_info->apn_arg); /* free previous argument */
- args_info->apn_arg = 0;
- }
- if (args_info->apn_orig)
- {
- free (args_info->apn_orig); /* free previous argument */
- args_info->apn_orig = 0;
- }
- if (args_info->selmode_orig)
- {
- free (args_info->selmode_orig); /* free previous argument */
- args_info->selmode_orig = 0;
- }
- if (args_info->imsi_arg)
- {
- free (args_info->imsi_arg); /* free previous argument */
- args_info->imsi_arg = 0;
- }
- if (args_info->imsi_orig)
- {
- free (args_info->imsi_orig); /* free previous argument */
- args_info->imsi_orig = 0;
- }
- if (args_info->nsapi_orig)
- {
- free (args_info->nsapi_orig); /* free previous argument */
- args_info->nsapi_orig = 0;
- }
- if (args_info->msisdn_arg)
- {
- free (args_info->msisdn_arg); /* free previous argument */
- args_info->msisdn_arg = 0;
- }
- if (args_info->msisdn_orig)
- {
- free (args_info->msisdn_orig); /* free previous argument */
- args_info->msisdn_orig = 0;
- }
- if (args_info->qos_orig)
- {
- free (args_info->qos_orig); /* free previous argument */
- args_info->qos_orig = 0;
- }
- if (args_info->charging_orig)
- {
- free (args_info->charging_orig); /* free previous argument */
- args_info->charging_orig = 0;
- }
- if (args_info->uid_arg)
- {
- free (args_info->uid_arg); /* free previous argument */
- args_info->uid_arg = 0;
- }
- if (args_info->uid_orig)
- {
- free (args_info->uid_orig); /* free previous argument */
- args_info->uid_orig = 0;
- }
- if (args_info->pwd_arg)
- {
- free (args_info->pwd_arg); /* free previous argument */
- args_info->pwd_arg = 0;
- }
- if (args_info->pwd_orig)
- {
- free (args_info->pwd_orig); /* free previous argument */
- args_info->pwd_orig = 0;
- }
- if (args_info->net_arg)
- {
- free (args_info->net_arg); /* free previous argument */
- args_info->net_arg = 0;
- }
- if (args_info->net_orig)
- {
- free (args_info->net_orig); /* free previous argument */
- args_info->net_orig = 0;
- }
- if (args_info->ipup_arg)
- {
- free (args_info->ipup_arg); /* free previous argument */
- args_info->ipup_arg = 0;
- }
- if (args_info->ipup_orig)
- {
- free (args_info->ipup_orig); /* free previous argument */
- args_info->ipup_orig = 0;
- }
- if (args_info->ipdown_arg)
- {
- free (args_info->ipdown_arg); /* free previous argument */
- args_info->ipdown_arg = 0;
- }
- if (args_info->ipdown_orig)
- {
- free (args_info->ipdown_orig); /* free previous argument */
- args_info->ipdown_orig = 0;
- }
- if (args_info->pinghost_arg)
- {
- free (args_info->pinghost_arg); /* free previous argument */
- args_info->pinghost_arg = 0;
- }
- if (args_info->pinghost_orig)
- {
- free (args_info->pinghost_orig); /* free previous argument */
- args_info->pinghost_orig = 0;
- }
- if (args_info->pingrate_orig)
- {
- free (args_info->pingrate_orig); /* free previous argument */
- args_info->pingrate_orig = 0;
- }
- if (args_info->pingsize_orig)
- {
- free (args_info->pingsize_orig); /* free previous argument */
- args_info->pingsize_orig = 0;
- }
- if (args_info->pingcount_orig)
- {
- free (args_info->pingcount_orig); /* free previous argument */
- args_info->pingcount_orig = 0;
- }
-
- clear_given (args_info);
+
+ if (args_info->conf_arg) {
+ free(args_info->conf_arg); /* free previous argument */
+ args_info->conf_arg = 0;
+ }
+ if (args_info->conf_orig) {
+ free(args_info->conf_orig); /* free previous argument */
+ args_info->conf_orig = 0;
+ }
+ if (args_info->pidfile_arg) {
+ free(args_info->pidfile_arg); /* free previous argument */
+ args_info->pidfile_arg = 0;
+ }
+ if (args_info->pidfile_orig) {
+ free(args_info->pidfile_orig); /* free previous argument */
+ args_info->pidfile_orig = 0;
+ }
+ if (args_info->statedir_arg) {
+ free(args_info->statedir_arg); /* free previous argument */
+ args_info->statedir_arg = 0;
+ }
+ if (args_info->statedir_orig) {
+ free(args_info->statedir_orig); /* free previous argument */
+ args_info->statedir_orig = 0;
+ }
+ if (args_info->dns_arg) {
+ free(args_info->dns_arg); /* free previous argument */
+ args_info->dns_arg = 0;
+ }
+ if (args_info->dns_orig) {
+ free(args_info->dns_orig); /* free previous argument */
+ args_info->dns_orig = 0;
+ }
+ if (args_info->listen_arg) {
+ free(args_info->listen_arg); /* free previous argument */
+ args_info->listen_arg = 0;
+ }
+ if (args_info->listen_orig) {
+ free(args_info->listen_orig); /* free previous argument */
+ args_info->listen_orig = 0;
+ }
+ if (args_info->remote_arg) {
+ free(args_info->remote_arg); /* free previous argument */
+ args_info->remote_arg = 0;
+ }
+ if (args_info->remote_orig) {
+ free(args_info->remote_orig); /* free previous argument */
+ args_info->remote_orig = 0;
+ }
+ if (args_info->contexts_orig) {
+ free(args_info->contexts_orig); /* free previous argument */
+ args_info->contexts_orig = 0;
+ }
+ if (args_info->timelimit_orig) {
+ free(args_info->timelimit_orig); /* free previous argument */
+ args_info->timelimit_orig = 0;
+ }
+ if (args_info->gtpversion_orig) {
+ free(args_info->gtpversion_orig); /* free previous argument */
+ args_info->gtpversion_orig = 0;
+ }
+ if (args_info->apn_arg) {
+ free(args_info->apn_arg); /* free previous argument */
+ args_info->apn_arg = 0;
+ }
+ if (args_info->apn_orig) {
+ free(args_info->apn_orig); /* free previous argument */
+ args_info->apn_orig = 0;
+ }
+ if (args_info->selmode_orig) {
+ free(args_info->selmode_orig); /* free previous argument */
+ args_info->selmode_orig = 0;
+ }
+ if (args_info->imsi_arg) {
+ free(args_info->imsi_arg); /* free previous argument */
+ args_info->imsi_arg = 0;
+ }
+ if (args_info->imsi_orig) {
+ free(args_info->imsi_orig); /* free previous argument */
+ args_info->imsi_orig = 0;
+ }
+ if (args_info->nsapi_orig) {
+ free(args_info->nsapi_orig); /* free previous argument */
+ args_info->nsapi_orig = 0;
+ }
+ if (args_info->msisdn_arg) {
+ free(args_info->msisdn_arg); /* free previous argument */
+ args_info->msisdn_arg = 0;
+ }
+ if (args_info->msisdn_orig) {
+ free(args_info->msisdn_orig); /* free previous argument */
+ args_info->msisdn_orig = 0;
+ }
+ if (args_info->qos_orig) {
+ free(args_info->qos_orig); /* free previous argument */
+ args_info->qos_orig = 0;
+ }
+ if (args_info->charging_orig) {
+ free(args_info->charging_orig); /* free previous argument */
+ args_info->charging_orig = 0;
+ }
+ if (args_info->uid_arg) {
+ free(args_info->uid_arg); /* free previous argument */
+ args_info->uid_arg = 0;
+ }
+ if (args_info->uid_orig) {
+ free(args_info->uid_orig); /* free previous argument */
+ args_info->uid_orig = 0;
+ }
+ if (args_info->pwd_arg) {
+ free(args_info->pwd_arg); /* free previous argument */
+ args_info->pwd_arg = 0;
+ }
+ if (args_info->pwd_orig) {
+ free(args_info->pwd_orig); /* free previous argument */
+ args_info->pwd_orig = 0;
+ }
+ if (args_info->net_arg) {
+ free(args_info->net_arg); /* free previous argument */
+ args_info->net_arg = 0;
+ }
+ if (args_info->net_orig) {
+ free(args_info->net_orig); /* free previous argument */
+ args_info->net_orig = 0;
+ }
+ if (args_info->ipup_arg) {
+ free(args_info->ipup_arg); /* free previous argument */
+ args_info->ipup_arg = 0;
+ }
+ if (args_info->ipup_orig) {
+ free(args_info->ipup_orig); /* free previous argument */
+ args_info->ipup_orig = 0;
+ }
+ if (args_info->ipdown_arg) {
+ free(args_info->ipdown_arg); /* free previous argument */
+ args_info->ipdown_arg = 0;
+ }
+ if (args_info->ipdown_orig) {
+ free(args_info->ipdown_orig); /* free previous argument */
+ args_info->ipdown_orig = 0;
+ }
+ if (args_info->pinghost_arg) {
+ free(args_info->pinghost_arg); /* free previous argument */
+ args_info->pinghost_arg = 0;
+ }
+ if (args_info->pinghost_orig) {
+ free(args_info->pinghost_orig); /* free previous argument */
+ args_info->pinghost_orig = 0;
+ }
+ if (args_info->pingrate_orig) {
+ free(args_info->pingrate_orig); /* free previous argument */
+ args_info->pingrate_orig = 0;
+ }
+ if (args_info->pingsize_orig) {
+ free(args_info->pingsize_orig); /* free previous argument */
+ args_info->pingsize_orig = 0;
+ }
+ if (args_info->pingcount_orig) {
+ free(args_info->pingcount_orig); /* free previous argument */
+ args_info->pingcount_orig = 0;
+ }
+
+ clear_given(args_info);
}
int
-cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
+cmdline_parser_file_save(const char *filename,
+ struct gengetopt_args_info *args_info)
{
- FILE *outfile;
- int i = 0;
-
- outfile = fopen(filename, "w");
-
- if (!outfile)
- {
- fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
- return EXIT_FAILURE;
- }
-
- if (args_info->help_given) {
- fprintf(outfile, "%s\n", "help");
- }
- if (args_info->version_given) {
- fprintf(outfile, "%s\n", "version");
- }
- if (args_info->debug_given) {
- fprintf(outfile, "%s\n", "debug");
- }
- if (args_info->conf_given) {
- if (args_info->conf_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "conf", args_info->conf_orig);
- } else {
- fprintf(outfile, "%s\n", "conf");
- }
- }
- if (args_info->pidfile_given) {
- if (args_info->pidfile_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pidfile", args_info->pidfile_orig);
- } else {
- fprintf(outfile, "%s\n", "pidfile");
- }
- }
- if (args_info->statedir_given) {
- if (args_info->statedir_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "statedir", args_info->statedir_orig);
- } else {
- fprintf(outfile, "%s\n", "statedir");
- }
- }
- if (args_info->dns_given) {
- if (args_info->dns_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "dns", args_info->dns_orig);
- } else {
- fprintf(outfile, "%s\n", "dns");
- }
- }
- if (args_info->listen_given) {
- if (args_info->listen_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "listen", args_info->listen_orig);
- } else {
- fprintf(outfile, "%s\n", "listen");
- }
- }
- if (args_info->remote_given) {
- if (args_info->remote_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "remote", args_info->remote_orig);
- } else {
- fprintf(outfile, "%s\n", "remote");
- }
- }
- if (args_info->contexts_given) {
- if (args_info->contexts_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "contexts", args_info->contexts_orig);
- } else {
- fprintf(outfile, "%s\n", "contexts");
- }
- }
- if (args_info->timelimit_given) {
- if (args_info->timelimit_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "timelimit", args_info->timelimit_orig);
- } else {
- fprintf(outfile, "%s\n", "timelimit");
- }
- }
- if (args_info->gtpversion_given) {
- if (args_info->gtpversion_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "gtpversion", args_info->gtpversion_orig);
- } else {
- fprintf(outfile, "%s\n", "gtpversion");
- }
- }
- if (args_info->apn_given) {
- if (args_info->apn_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "apn", args_info->apn_orig);
- } else {
- fprintf(outfile, "%s\n", "apn");
- }
- }
- if (args_info->selmode_given) {
- if (args_info->selmode_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "selmode", args_info->selmode_orig);
- } else {
- fprintf(outfile, "%s\n", "selmode");
- }
- }
- if (args_info->imsi_given) {
- if (args_info->imsi_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "imsi", args_info->imsi_orig);
- } else {
- fprintf(outfile, "%s\n", "imsi");
- }
- }
- if (args_info->nsapi_given) {
- if (args_info->nsapi_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "nsapi", args_info->nsapi_orig);
- } else {
- fprintf(outfile, "%s\n", "nsapi");
- }
- }
- if (args_info->msisdn_given) {
- if (args_info->msisdn_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "msisdn", args_info->msisdn_orig);
- } else {
- fprintf(outfile, "%s\n", "msisdn");
- }
- }
- if (args_info->qos_given) {
- if (args_info->qos_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "qos", args_info->qos_orig);
- } else {
- fprintf(outfile, "%s\n", "qos");
- }
- }
- if (args_info->charging_given) {
- if (args_info->charging_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "charging", args_info->charging_orig);
- } else {
- fprintf(outfile, "%s\n", "charging");
- }
- }
- if (args_info->uid_given) {
- if (args_info->uid_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "uid", args_info->uid_orig);
- } else {
- fprintf(outfile, "%s\n", "uid");
- }
- }
- if (args_info->pwd_given) {
- if (args_info->pwd_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pwd", args_info->pwd_orig);
- } else {
- fprintf(outfile, "%s\n", "pwd");
- }
- }
- if (args_info->createif_given) {
- fprintf(outfile, "%s\n", "createif");
- }
- if (args_info->net_given) {
- if (args_info->net_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "net", args_info->net_orig);
- } else {
- fprintf(outfile, "%s\n", "net");
- }
- }
- if (args_info->defaultroute_given) {
- fprintf(outfile, "%s\n", "defaultroute");
- }
- if (args_info->ipup_given) {
- if (args_info->ipup_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "ipup", args_info->ipup_orig);
- } else {
- fprintf(outfile, "%s\n", "ipup");
- }
- }
- if (args_info->ipdown_given) {
- if (args_info->ipdown_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "ipdown", args_info->ipdown_orig);
- } else {
- fprintf(outfile, "%s\n", "ipdown");
- }
- }
- if (args_info->pinghost_given) {
- if (args_info->pinghost_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pinghost", args_info->pinghost_orig);
- } else {
- fprintf(outfile, "%s\n", "pinghost");
- }
- }
- if (args_info->pingrate_given) {
- if (args_info->pingrate_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pingrate", args_info->pingrate_orig);
- } else {
- fprintf(outfile, "%s\n", "pingrate");
- }
- }
- if (args_info->pingsize_given) {
- if (args_info->pingsize_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pingsize", args_info->pingsize_orig);
- } else {
- fprintf(outfile, "%s\n", "pingsize");
- }
- }
- if (args_info->pingcount_given) {
- if (args_info->pingcount_orig) {
- fprintf(outfile, "%s=\"%s\"\n", "pingcount", args_info->pingcount_orig);
- } else {
- fprintf(outfile, "%s\n", "pingcount");
- }
- }
- if (args_info->pingquiet_given) {
- fprintf(outfile, "%s\n", "pingquiet");
- }
- if (args_info->norecovery_given) {
- fprintf(outfile, "%s\n", "norecovery");
- }
-
- fclose (outfile);
-
- i = EXIT_SUCCESS;
- return i;
+ FILE *outfile;
+ int i = 0;
+
+ outfile = fopen(filename, "w");
+
+ if (!outfile) {
+ fprintf(stderr, "%s: cannot open file for writing: %s\n",
+ CMDLINE_PARSER_PACKAGE, filename);
+ return EXIT_FAILURE;
+ }
+
+ if (args_info->help_given) {
+ fprintf(outfile, "%s\n", "help");
+ }
+ if (args_info->version_given) {
+ fprintf(outfile, "%s\n", "version");
+ }
+ if (args_info->debug_given) {
+ fprintf(outfile, "%s\n", "debug");
+ }
+ if (args_info->conf_given) {
+ if (args_info->conf_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "conf",
+ args_info->conf_orig);
+ } else {
+ fprintf(outfile, "%s\n", "conf");
+ }
+ }
+ if (args_info->pidfile_given) {
+ if (args_info->pidfile_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pidfile",
+ args_info->pidfile_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pidfile");
+ }
+ }
+ if (args_info->statedir_given) {
+ if (args_info->statedir_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "statedir",
+ args_info->statedir_orig);
+ } else {
+ fprintf(outfile, "%s\n", "statedir");
+ }
+ }
+ if (args_info->dns_given) {
+ if (args_info->dns_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "dns",
+ args_info->dns_orig);
+ } else {
+ fprintf(outfile, "%s\n", "dns");
+ }
+ }
+ if (args_info->listen_given) {
+ if (args_info->listen_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "listen",
+ args_info->listen_orig);
+ } else {
+ fprintf(outfile, "%s\n", "listen");
+ }
+ }
+ if (args_info->remote_given) {
+ if (args_info->remote_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "remote",
+ args_info->remote_orig);
+ } else {
+ fprintf(outfile, "%s\n", "remote");
+ }
+ }
+ if (args_info->contexts_given) {
+ if (args_info->contexts_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "contexts",
+ args_info->contexts_orig);
+ } else {
+ fprintf(outfile, "%s\n", "contexts");
+ }
+ }
+ if (args_info->timelimit_given) {
+ if (args_info->timelimit_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "timelimit",
+ args_info->timelimit_orig);
+ } else {
+ fprintf(outfile, "%s\n", "timelimit");
+ }
+ }
+ if (args_info->gtpversion_given) {
+ if (args_info->gtpversion_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "gtpversion",
+ args_info->gtpversion_orig);
+ } else {
+ fprintf(outfile, "%s\n", "gtpversion");
+ }
+ }
+ if (args_info->apn_given) {
+ if (args_info->apn_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "apn",
+ args_info->apn_orig);
+ } else {
+ fprintf(outfile, "%s\n", "apn");
+ }
+ }
+ if (args_info->selmode_given) {
+ if (args_info->selmode_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "selmode",
+ args_info->selmode_orig);
+ } else {
+ fprintf(outfile, "%s\n", "selmode");
+ }
+ }
+ if (args_info->imsi_given) {
+ if (args_info->imsi_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "imsi",
+ args_info->imsi_orig);
+ } else {
+ fprintf(outfile, "%s\n", "imsi");
+ }
+ }
+ if (args_info->nsapi_given) {
+ if (args_info->nsapi_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "nsapi",
+ args_info->nsapi_orig);
+ } else {
+ fprintf(outfile, "%s\n", "nsapi");
+ }
+ }
+ if (args_info->msisdn_given) {
+ if (args_info->msisdn_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "msisdn",
+ args_info->msisdn_orig);
+ } else {
+ fprintf(outfile, "%s\n", "msisdn");
+ }
+ }
+ if (args_info->qos_given) {
+ if (args_info->qos_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "qos",
+ args_info->qos_orig);
+ } else {
+ fprintf(outfile, "%s\n", "qos");
+ }
+ }
+ if (args_info->charging_given) {
+ if (args_info->charging_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "charging",
+ args_info->charging_orig);
+ } else {
+ fprintf(outfile, "%s\n", "charging");
+ }
+ }
+ if (args_info->uid_given) {
+ if (args_info->uid_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "uid",
+ args_info->uid_orig);
+ } else {
+ fprintf(outfile, "%s\n", "uid");
+ }
+ }
+ if (args_info->pwd_given) {
+ if (args_info->pwd_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pwd",
+ args_info->pwd_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pwd");
+ }
+ }
+ if (args_info->createif_given) {
+ fprintf(outfile, "%s\n", "createif");
+ }
+ if (args_info->net_given) {
+ if (args_info->net_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "net",
+ args_info->net_orig);
+ } else {
+ fprintf(outfile, "%s\n", "net");
+ }
+ }
+ if (args_info->defaultroute_given) {
+ fprintf(outfile, "%s\n", "defaultroute");
+ }
+ if (args_info->ipup_given) {
+ if (args_info->ipup_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "ipup",
+ args_info->ipup_orig);
+ } else {
+ fprintf(outfile, "%s\n", "ipup");
+ }
+ }
+ if (args_info->ipdown_given) {
+ if (args_info->ipdown_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "ipdown",
+ args_info->ipdown_orig);
+ } else {
+ fprintf(outfile, "%s\n", "ipdown");
+ }
+ }
+ if (args_info->pinghost_given) {
+ if (args_info->pinghost_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pinghost",
+ args_info->pinghost_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pinghost");
+ }
+ }
+ if (args_info->pingrate_given) {
+ if (args_info->pingrate_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pingrate",
+ args_info->pingrate_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pingrate");
+ }
+ }
+ if (args_info->pingsize_given) {
+ if (args_info->pingsize_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pingsize",
+ args_info->pingsize_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pingsize");
+ }
+ }
+ if (args_info->pingcount_given) {
+ if (args_info->pingcount_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "pingcount",
+ args_info->pingcount_orig);
+ } else {
+ fprintf(outfile, "%s\n", "pingcount");
+ }
+ }
+ if (args_info->pingquiet_given) {
+ fprintf(outfile, "%s\n", "pingquiet");
+ }
+ if (args_info->norecovery_given) {
+ fprintf(outfile, "%s\n", "norecovery");
+ }
+
+ fclose(outfile);
+
+ i = EXIT_SUCCESS;
+ return i;
}
-void
-cmdline_parser_free (struct gengetopt_args_info *args_info)
+void cmdline_parser_free(struct gengetopt_args_info *args_info)
{
- cmdline_parser_release (args_info);
+ cmdline_parser_release(args_info);
}
-
/* gengetopt_strdup() */
/* strdup.c replacement of strdup, which is not standard */
-char *
-gengetopt_strdup (const char *s)
+char *gengetopt_strdup(const char *s)
{
- char *result = NULL;
- if (!s)
- return result;
-
- result = (char*)malloc(strlen(s) + 1);
- if (result == (char*)0)
- return (char*)0;
- strcpy(result, s);
- return result;
+ char *result = NULL;
+ if (!s)
+ return result;
+
+ result = (char *)malloc(strlen(s) + 1);
+ if (result == (char *)0)
+ return (char *)0;
+ strcpy(result, s);
+ return result;
}
int
-cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
+cmdline_parser(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info)
{
- return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
+ return cmdline_parser2(argc, argv, args_info, 0, 1, 1);
}
int
-cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+cmdline_parser2(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info, int override,
+ int initialize, int check_required)
{
- int result;
+ int result;
+
+ result =
+ cmdline_parser_internal(argc, argv, args_info, override, initialize,
+ check_required, NULL);
- result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
+ if (result == EXIT_FAILURE) {
+ cmdline_parser_free(args_info);
+ exit(EXIT_FAILURE);
+ }
- if (result == EXIT_FAILURE)
- {
- cmdline_parser_free (args_info);
- exit (EXIT_FAILURE);
- }
-
- return result;
+ return result;
}
int
-cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
+cmdline_parser_required(struct gengetopt_args_info *args_info,
+ const char *prog_name)
{
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
int
-cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
+cmdline_parser_internal(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info, int override,
+ int initialize, int check_required,
+ const char *additional_error)
{
- int c; /* Character of the parsed option. */
-
- int error = 0;
- struct gengetopt_args_info local_args_info;
-
- if (initialize)
- cmdline_parser_init (args_info);
-
- cmdline_parser_init (&local_args_info);
-
- optarg = 0;
- optind = 0;
- 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 },
- { "rattype", 1, NULL, 0},
- { "userloc", 1, NULL, 0},
- { "rai", 1, NULL, 0},
- { "mstz", 1, NULL, 0},
- { "imeisv", 1, NULL, 0},
- { "imsi", 1, NULL, 'i' },
- { "nsapi", 1, NULL, 0 },
- { "msisdn", 1, NULL, 'm' },
- { "qos", 1, NULL, 'q' },
- { "qose1", 1, NULL, 0 },
- { "qose2", 1, NULL, 0 },
- { "qose3", 1, NULL, 0 },
- { "qose4", 1, NULL, 0 },
- { "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 },
- { "norecovery", 0, NULL, 0 },
- { NULL, 0, NULL, 0 }
- };
-
- stop_char = 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. */
- cmdline_parser_print_help ();
- cmdline_parser_free (&local_args_info);
- exit (EXIT_SUCCESS);
-
- case 'V': /* Print version and exit. */
- cmdline_parser_print_version ();
- cmdline_parser_free (&local_args_info);
- exit (EXIT_SUCCESS);
-
- case 'd': /* Run in debug mode. */
- if (local_args_info.debug_given)
- {
- fprintf (stderr, "%s: `--debug' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->debug_given && ! override)
- continue;
- local_args_info.debug_given = 1;
- args_info->debug_given = 1;
- args_info->debug_flag = !(args_info->debug_flag);
- break;
-
- case 'c': /* Read configuration file. */
- if (local_args_info.conf_given)
- {
- fprintf (stderr, "%s: `--conf' (`-c') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->conf_given && ! override)
- continue;
- local_args_info.conf_given = 1;
- args_info->conf_given = 1;
- if (args_info->conf_arg)
- free (args_info->conf_arg); /* free previous string */
- args_info->conf_arg = gengetopt_strdup (optarg);
- if (args_info->conf_orig)
- free (args_info->conf_orig); /* free previous string */
- args_info->conf_orig = gengetopt_strdup (optarg);
- break;
-
- case 'l': /* Local interface. */
- if (local_args_info.listen_given)
- {
- fprintf (stderr, "%s: `--listen' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->listen_given && ! override)
- continue;
- local_args_info.listen_given = 1;
- args_info->listen_given = 1;
- if (args_info->listen_arg)
- free (args_info->listen_arg); /* free previous string */
- args_info->listen_arg = gengetopt_strdup (optarg);
- if (args_info->listen_orig)
- free (args_info->listen_orig); /* free previous string */
- args_info->listen_orig = gengetopt_strdup (optarg);
- break;
-
- case 'r': /* Remote host. */
- if (local_args_info.remote_given)
- {
- fprintf (stderr, "%s: `--remote' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->remote_given && ! override)
- continue;
- local_args_info.remote_given = 1;
- args_info->remote_given = 1;
- if (args_info->remote_arg)
- free (args_info->remote_arg); /* free previous string */
- args_info->remote_arg = gengetopt_strdup (optarg);
- if (args_info->remote_orig)
- free (args_info->remote_orig); /* free previous string */
- args_info->remote_orig = gengetopt_strdup (optarg);
- break;
-
- case 'a': /* Access point name. */
- if (local_args_info.apn_given)
- {
- fprintf (stderr, "%s: `--apn' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->apn_given && ! override)
- continue;
- local_args_info.apn_given = 1;
- args_info->apn_given = 1;
- if (args_info->apn_arg)
- free (args_info->apn_arg); /* free previous string */
- args_info->apn_arg = gengetopt_strdup (optarg);
- if (args_info->apn_orig)
- free (args_info->apn_orig); /* free previous string */
- args_info->apn_orig = gengetopt_strdup (optarg);
- break;
-
- case 'i': /* IMSI. */
- if (local_args_info.imsi_given)
- {
- fprintf (stderr, "%s: `--imsi' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->imsi_given && ! override)
- continue;
- local_args_info.imsi_given = 1;
- args_info->imsi_given = 1;
- if (args_info->imsi_arg)
- free (args_info->imsi_arg); /* free previous string */
- args_info->imsi_arg = gengetopt_strdup (optarg);
- if (args_info->imsi_orig)
- free (args_info->imsi_orig); /* free previous string */
- args_info->imsi_orig = gengetopt_strdup (optarg);
- break;
-
- case 'm': /* Mobile Station ISDN number. */
- if (local_args_info.msisdn_given)
- {
- fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->msisdn_given && ! override)
- continue;
- local_args_info.msisdn_given = 1;
- args_info->msisdn_given = 1;
- if (args_info->msisdn_arg)
- free (args_info->msisdn_arg); /* free previous string */
- args_info->msisdn_arg = gengetopt_strdup (optarg);
- if (args_info->msisdn_orig)
- free (args_info->msisdn_orig); /* free previous string */
- args_info->msisdn_orig = gengetopt_strdup (optarg);
- break;
-
- case 'q': /* Requested quality of service. */
- if (local_args_info.qos_given)
- {
- fprintf (stderr, "%s: `--qos' (`-q') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->qos_given && ! override)
- continue;
- local_args_info.qos_given = 1;
- args_info->qos_given = 1;
- args_info->qos_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->qos_orig)
- free (args_info->qos_orig); /* free previous string */
- args_info->qos_orig = gengetopt_strdup (optarg);
- break;
-
- case 'u': /* Login user ID. */
- if (local_args_info.uid_given)
- {
- fprintf (stderr, "%s: `--uid' (`-u') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->uid_given && ! override)
- continue;
- local_args_info.uid_given = 1;
- args_info->uid_given = 1;
- if (args_info->uid_arg)
- free (args_info->uid_arg); /* free previous string */
- args_info->uid_arg = gengetopt_strdup (optarg);
- if (args_info->uid_orig)
- free (args_info->uid_orig); /* free previous string */
- args_info->uid_orig = gengetopt_strdup (optarg);
- break;
-
- case 'p': /* Login password. */
- if (local_args_info.pwd_given)
- {
- fprintf (stderr, "%s: `--pwd' (`-p') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pwd_given && ! override)
- continue;
- local_args_info.pwd_given = 1;
- args_info->pwd_given = 1;
- if (args_info->pwd_arg)
- free (args_info->pwd_arg); /* free previous string */
- args_info->pwd_arg = gengetopt_strdup (optarg);
- if (args_info->pwd_orig)
- free (args_info->pwd_orig); /* free previous string */
- args_info->pwd_orig = gengetopt_strdup (optarg);
- break;
-
- case 'n': /* Network address for local interface. */
- if (local_args_info.net_given)
- {
- fprintf (stderr, "%s: `--net' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->net_given && ! override)
- continue;
- local_args_info.net_given = 1;
- args_info->net_given = 1;
- if (args_info->net_arg)
- free (args_info->net_arg); /* free previous string */
- args_info->net_arg = gengetopt_strdup (optarg);
- if (args_info->net_orig)
- free (args_info->net_orig); /* free previous string */
- args_info->net_orig = gengetopt_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 (local_args_info.pidfile_given)
- {
- fprintf (stderr, "%s: `--pidfile' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pidfile_given && ! override)
- continue;
- local_args_info.pidfile_given = 1;
- args_info->pidfile_given = 1;
- if (args_info->pidfile_arg)
- free (args_info->pidfile_arg); /* free previous string */
- args_info->pidfile_arg = gengetopt_strdup (optarg);
- if (args_info->pidfile_orig)
- free (args_info->pidfile_orig); /* free previous string */
- args_info->pidfile_orig = gengetopt_strdup (optarg);
- }
- /* Directory of nonvolatile data. */
- else if (strcmp (long_options[option_index].name, "statedir") == 0)
- {
- if (local_args_info.statedir_given)
- {
- fprintf (stderr, "%s: `--statedir' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->statedir_given && ! override)
- continue;
- local_args_info.statedir_given = 1;
- args_info->statedir_given = 1;
- if (args_info->statedir_arg)
- free (args_info->statedir_arg); /* free previous string */
- args_info->statedir_arg = gengetopt_strdup (optarg);
- if (args_info->statedir_orig)
- free (args_info->statedir_orig); /* free previous string */
- args_info->statedir_orig = gengetopt_strdup (optarg);
- }
- /* DNS Server to use. */
- else if (strcmp (long_options[option_index].name, "dns") == 0)
- {
- if (local_args_info.dns_given)
- {
- fprintf (stderr, "%s: `--dns' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->dns_given && ! override)
- continue;
- local_args_info.dns_given = 1;
- args_info->dns_given = 1;
- if (args_info->dns_arg)
- free (args_info->dns_arg); /* free previous string */
- args_info->dns_arg = gengetopt_strdup (optarg);
- if (args_info->dns_orig)
- free (args_info->dns_orig); /* free previous string */
- args_info->dns_orig = gengetopt_strdup (optarg);
- }
- /* Number of contexts. */
- else if (strcmp (long_options[option_index].name, "contexts") == 0)
- {
- if (local_args_info.contexts_given)
- {
- fprintf (stderr, "%s: `--contexts' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->contexts_given && ! override)
- continue;
- local_args_info.contexts_given = 1;
- args_info->contexts_given = 1;
- args_info->contexts_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->contexts_orig)
- free (args_info->contexts_orig); /* free previous string */
- args_info->contexts_orig = gengetopt_strdup (optarg);
- }
- /* Exit after timelimit seconds. */
- else if (strcmp (long_options[option_index].name, "timelimit") == 0)
- {
- if (local_args_info.timelimit_given)
- {
- fprintf (stderr, "%s: `--timelimit' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->timelimit_given && ! override)
- continue;
- local_args_info.timelimit_given = 1;
- args_info->timelimit_given = 1;
- args_info->timelimit_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->timelimit_orig)
- free (args_info->timelimit_orig); /* free previous string */
- args_info->timelimit_orig = gengetopt_strdup (optarg);
- }
- /* GTP version to use. */
- else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
- {
- if (local_args_info.gtpversion_given)
- {
- fprintf (stderr, "%s: `--gtpversion' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->gtpversion_given && ! override)
- continue;
- local_args_info.gtpversion_given = 1;
- args_info->gtpversion_given = 1;
- args_info->gtpversion_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->gtpversion_orig)
- free (args_info->gtpversion_orig); /* free previous string */
- args_info->gtpversion_orig = gengetopt_strdup (optarg);
- }
- /* Selection mode. */
- else if (strcmp (long_options[option_index].name, "selmode") == 0)
- {
- if (local_args_info.selmode_given)
- {
- fprintf (stderr, "%s: `--selmode' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->selmode_given && ! override)
- continue;
- local_args_info.selmode_given = 1;
- args_info->selmode_given = 1;
- args_info->selmode_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->selmode_orig)
- free (args_info->selmode_orig); /* free previous string */
- args_info->selmode_orig = gengetopt_strdup (optarg);
- }
- /* QoS Extension 1. */
- else if (strcmp (long_options[option_index].name, "qose1") == 0)
- {
- if (args_info->qose1_given)
- {
- fprintf (stderr, "%s: `--qose1' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->qose1_given = 1;
- args_info->qose1_arg = strtoull (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->qose1_orig)
- free (args_info->qose1_orig); /* free previous string */
- args_info->qose1_orig = gengetopt_strdup (optarg);
- break;
- }
- /* QoS Extension 2. */
- else if (strcmp (long_options[option_index].name, "qose2") == 0)
- {
- if (args_info->qose2_given)
- {
- fprintf (stderr, "%s: `--qose2' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->qose2_given = 1;
- args_info->qose2_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->qose2_orig)
- free (args_info->qose2_orig); /* free previous string */
- args_info->qose2_orig = gengetopt_strdup (optarg);
- break;
- }
- /* QoS Extension 3. */
- else if (strcmp (long_options[option_index].name, "qose3") == 0)
- {
- if (args_info->qose3_given)
- {
- fprintf (stderr, "%s: `--qose3' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->qose3_given = 1;
- args_info->qose3_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->qose3_orig)
- free (args_info->qose3_orig); /* free previous string */
- args_info->qose3_orig = gengetopt_strdup (optarg);
- break;
- }
- /* QoS Extension 4. */
- else if (strcmp (long_options[option_index].name, "qose4") == 0)
- {
- if (args_info->qose4_given)
- {
- fprintf (stderr, "%s: `--qose4' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->qose4_given = 1;
- args_info->qose4_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->qose4_orig)
- free (args_info->qose4_orig); /* free previous string */
- args_info->qose4_orig = gengetopt_strdup (optarg);
- break;
- }
- /* Radio Access Technology Type. */
- else if (strcmp (long_options[option_index].name, "rattype") == 0)
- {
- if (args_info->rattype_given)
- {
- fprintf (stderr, "%s: `--rattype' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->rattype_given = 1;
- /* args_info->rattype_arg = strtol (optarg,&stop_char,0); */
- args_info->rattype_arg = strdup (optarg);
- break;
- }
- /* User Location Information. */
- else if (strcmp (long_options[option_index].name, "userloc") == 0)
- {
- if (args_info->userloc_given)
- {
- fprintf (stderr, "%s: `--userloc' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->userloc_given = 1;
- args_info->userloc_arg = strdup (optarg);
- break;
- }
- /* Routing Area Information. */
- else if (strcmp (long_options[option_index].name, "rai") == 0)
- {
- if (args_info->rai_given)
- {
- fprintf (stderr, "%s: `--rai' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->rai_given = 1;
- args_info->rai_arg = strdup (optarg);
- break;
- }
- /* MS Time Zone */
- else if (strcmp (long_options[option_index].name, "mstz") == 0)
- {
- if (args_info->mstz_given)
- {
- fprintf (stderr, "%s: `--mstz' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->mstz_given = 1;
- args_info->mstz_arg = strdup (optarg);
- break;
- }
- /* IMEI(SV) */
- else if (strcmp (long_options[option_index].name, "imeisv") == 0)
- {
- if (args_info->imeisv_given)
- {
- fprintf (stderr, "%s: `--imeisv' option given more than once\n", PACKAGE);
- exit (EXIT_FAILURE);
- }
- args_info->imeisv_given = 1;
- args_info->imeisv_arg = strdup (optarg);
- break;
- }
- /* NSAPI. */
- else if (strcmp (long_options[option_index].name, "nsapi") == 0)
- {
- if (local_args_info.nsapi_given)
- {
- fprintf (stderr, "%s: `--nsapi' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->nsapi_given && ! override)
- continue;
- local_args_info.nsapi_given = 1;
- args_info->nsapi_given = 1;
- args_info->nsapi_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->nsapi_orig)
- free (args_info->nsapi_orig); /* free previous string */
- args_info->nsapi_orig = gengetopt_strdup (optarg);
- }
- /* Charging characteristics. */
- else if (strcmp (long_options[option_index].name, "charging") == 0)
- {
- if (local_args_info.charging_given)
- {
- fprintf (stderr, "%s: `--charging' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->charging_given && ! override)
- continue;
- local_args_info.charging_given = 1;
- args_info->charging_given = 1;
- args_info->charging_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->charging_orig)
- free (args_info->charging_orig); /* free previous string */
- args_info->charging_orig = gengetopt_strdup (optarg);
- }
- /* Create local network interface. */
- else if (strcmp (long_options[option_index].name, "createif") == 0)
- {
- if (local_args_info.createif_given)
- {
- fprintf (stderr, "%s: `--createif' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->createif_given && ! override)
- continue;
- local_args_info.createif_given = 1;
- args_info->createif_given = 1;
- args_info->createif_flag = !(args_info->createif_flag);
- }
- /* Create default route. */
- else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
- {
- if (local_args_info.defaultroute_given)
- {
- fprintf (stderr, "%s: `--defaultroute' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->defaultroute_given && ! override)
- continue;
- local_args_info.defaultroute_given = 1;
- args_info->defaultroute_given = 1;
- args_info->defaultroute_flag = !(args_info->defaultroute_flag);
- }
- /* Script to run after link-up. */
- else if (strcmp (long_options[option_index].name, "ipup") == 0)
- {
- if (local_args_info.ipup_given)
- {
- fprintf (stderr, "%s: `--ipup' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->ipup_given && ! override)
- continue;
- local_args_info.ipup_given = 1;
- args_info->ipup_given = 1;
- if (args_info->ipup_arg)
- free (args_info->ipup_arg); /* free previous string */
- args_info->ipup_arg = gengetopt_strdup (optarg);
- if (args_info->ipup_orig)
- free (args_info->ipup_orig); /* free previous string */
- args_info->ipup_orig = gengetopt_strdup (optarg);
- }
- /* Script to run after link-down. */
- else if (strcmp (long_options[option_index].name, "ipdown") == 0)
- {
- if (local_args_info.ipdown_given)
- {
- fprintf (stderr, "%s: `--ipdown' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->ipdown_given && ! override)
- continue;
- local_args_info.ipdown_given = 1;
- args_info->ipdown_given = 1;
- if (args_info->ipdown_arg)
- free (args_info->ipdown_arg); /* free previous string */
- args_info->ipdown_arg = gengetopt_strdup (optarg);
- if (args_info->ipdown_orig)
- free (args_info->ipdown_orig); /* free previous string */
- args_info->ipdown_orig = gengetopt_strdup (optarg);
- }
- /* Ping remote host. */
- else if (strcmp (long_options[option_index].name, "pinghost") == 0)
- {
- if (local_args_info.pinghost_given)
- {
- fprintf (stderr, "%s: `--pinghost' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pinghost_given && ! override)
- continue;
- local_args_info.pinghost_given = 1;
- args_info->pinghost_given = 1;
- if (args_info->pinghost_arg)
- free (args_info->pinghost_arg); /* free previous string */
- args_info->pinghost_arg = gengetopt_strdup (optarg);
- if (args_info->pinghost_orig)
- free (args_info->pinghost_orig); /* free previous string */
- args_info->pinghost_orig = gengetopt_strdup (optarg);
- }
- /* Number of ping req per second. */
- else if (strcmp (long_options[option_index].name, "pingrate") == 0)
- {
- if (local_args_info.pingrate_given)
- {
- fprintf (stderr, "%s: `--pingrate' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pingrate_given && ! override)
- continue;
- local_args_info.pingrate_given = 1;
- args_info->pingrate_given = 1;
- args_info->pingrate_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->pingrate_orig)
- free (args_info->pingrate_orig); /* free previous string */
- args_info->pingrate_orig = gengetopt_strdup (optarg);
- }
- /* Number of ping data bytes. */
- else if (strcmp (long_options[option_index].name, "pingsize") == 0)
- {
- if (local_args_info.pingsize_given)
- {
- fprintf (stderr, "%s: `--pingsize' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pingsize_given && ! override)
- continue;
- local_args_info.pingsize_given = 1;
- args_info->pingsize_given = 1;
- args_info->pingsize_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->pingsize_orig)
- free (args_info->pingsize_orig); /* free previous string */
- args_info->pingsize_orig = gengetopt_strdup (optarg);
- }
- /* Number of ping req to send. */
- else if (strcmp (long_options[option_index].name, "pingcount") == 0)
- {
- if (local_args_info.pingcount_given)
- {
- fprintf (stderr, "%s: `--pingcount' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pingcount_given && ! override)
- continue;
- local_args_info.pingcount_given = 1;
- args_info->pingcount_given = 1;
- args_info->pingcount_arg = strtol (optarg, &stop_char, 0);
- if (!(stop_char && *stop_char == '\0')) {
- fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
- goto failure;
- }
- if (args_info->pingcount_orig)
- free (args_info->pingcount_orig); /* free previous string */
- args_info->pingcount_orig = gengetopt_strdup (optarg);
- }
- /* Do not print ping packet info. */
- else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
- {
- if (local_args_info.pingquiet_given)
- {
- fprintf (stderr, "%s: `--pingquiet' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->pingquiet_given && ! override)
- continue;
- local_args_info.pingquiet_given = 1;
- args_info->pingquiet_given = 1;
- args_info->pingquiet_flag = !(args_info->pingquiet_flag);
- }
- /* Do not send recovery. */
- else if (strcmp (long_options[option_index].name, "norecovery") == 0)
- {
- if (local_args_info.norecovery_given)
- {
- fprintf (stderr, "%s: `--norecovery' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
- goto failure;
- }
- if (args_info->norecovery_given && ! override)
- continue;
- local_args_info.norecovery_given = 1;
- args_info->norecovery_given = 1;
- args_info->norecovery_flag = !(args_info->norecovery_flag);
- }
-
- break;
- case '?': /* Invalid option. */
- /* `getopt_long' already printed an error message. */
- goto failure;
-
- default: /* bug: option not considered. */
- fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
- abort ();
- } /* switch */
- } /* while */
-
-
-
-
- cmdline_parser_release (&local_args_info);
-
- if ( error )
- return (EXIT_FAILURE);
-
- return 0;
+ int c; /* Character of the parsed option. */
+
+ int error = 0;
+ struct gengetopt_args_info local_args_info;
+
+ if (initialize)
+ cmdline_parser_init(args_info);
+
+ cmdline_parser_init(&local_args_info);
+
+ optarg = 0;
+ optind = 0;
+ 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},
+ {"rattype", 1, NULL, 0},
+ {"userloc", 1, NULL, 0},
+ {"rai", 1, NULL, 0},
+ {"mstz", 1, NULL, 0},
+ {"imeisv", 1, NULL, 0},
+ {"imsi", 1, NULL, 'i'},
+ {"nsapi", 1, NULL, 0},
+ {"msisdn", 1, NULL, 'm'},
+ {"qos", 1, NULL, 'q'},
+ {"qose1", 1, NULL, 0},
+ {"qose2", 1, NULL, 0},
+ {"qose3", 1, NULL, 0},
+ {"qose4", 1, NULL, 0},
+ {"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},
+ {"norecovery", 0, NULL, 0},
+ {NULL, 0, NULL, 0}
+ };
+
+ stop_char = 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. */
+ cmdline_parser_print_help();
+ cmdline_parser_free(&local_args_info);
+ exit(EXIT_SUCCESS);
+
+ case 'V': /* Print version and exit. */
+ cmdline_parser_print_version();
+ cmdline_parser_free(&local_args_info);
+ exit(EXIT_SUCCESS);
+
+ case 'd': /* Run in debug mode. */
+ if (local_args_info.debug_given) {
+ fprintf(stderr,
+ "%s: `--debug' (`-d') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->debug_given && !override)
+ continue;
+ local_args_info.debug_given = 1;
+ args_info->debug_given = 1;
+ args_info->debug_flag = !(args_info->debug_flag);
+ break;
+
+ case 'c': /* Read configuration file. */
+ if (local_args_info.conf_given) {
+ fprintf(stderr,
+ "%s: `--conf' (`-c') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->conf_given && !override)
+ continue;
+ local_args_info.conf_given = 1;
+ args_info->conf_given = 1;
+ if (args_info->conf_arg)
+ free(args_info->conf_arg); /* free previous string */
+ args_info->conf_arg = gengetopt_strdup(optarg);
+ if (args_info->conf_orig)
+ free(args_info->conf_orig); /* free previous string */
+ args_info->conf_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'l': /* Local interface. */
+ if (local_args_info.listen_given) {
+ fprintf(stderr,
+ "%s: `--listen' (`-l') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->listen_given && !override)
+ continue;
+ local_args_info.listen_given = 1;
+ args_info->listen_given = 1;
+ if (args_info->listen_arg)
+ free(args_info->listen_arg); /* free previous string */
+ args_info->listen_arg = gengetopt_strdup(optarg);
+ if (args_info->listen_orig)
+ free(args_info->listen_orig); /* free previous string */
+ args_info->listen_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'r': /* Remote host. */
+ if (local_args_info.remote_given) {
+ fprintf(stderr,
+ "%s: `--remote' (`-r') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->remote_given && !override)
+ continue;
+ local_args_info.remote_given = 1;
+ args_info->remote_given = 1;
+ if (args_info->remote_arg)
+ free(args_info->remote_arg); /* free previous string */
+ args_info->remote_arg = gengetopt_strdup(optarg);
+ if (args_info->remote_orig)
+ free(args_info->remote_orig); /* free previous string */
+ args_info->remote_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'a': /* Access point name. */
+ if (local_args_info.apn_given) {
+ fprintf(stderr,
+ "%s: `--apn' (`-a') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->apn_given && !override)
+ continue;
+ local_args_info.apn_given = 1;
+ args_info->apn_given = 1;
+ if (args_info->apn_arg)
+ free(args_info->apn_arg); /* free previous string */
+ args_info->apn_arg = gengetopt_strdup(optarg);
+ if (args_info->apn_orig)
+ free(args_info->apn_orig); /* free previous string */
+ args_info->apn_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'i': /* IMSI. */
+ if (local_args_info.imsi_given) {
+ fprintf(stderr,
+ "%s: `--imsi' (`-i') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->imsi_given && !override)
+ continue;
+ local_args_info.imsi_given = 1;
+ args_info->imsi_given = 1;
+ if (args_info->imsi_arg)
+ free(args_info->imsi_arg); /* free previous string */
+ args_info->imsi_arg = gengetopt_strdup(optarg);
+ if (args_info->imsi_orig)
+ free(args_info->imsi_orig); /* free previous string */
+ args_info->imsi_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'm': /* Mobile Station ISDN number. */
+ if (local_args_info.msisdn_given) {
+ fprintf(stderr,
+ "%s: `--msisdn' (`-m') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->msisdn_given && !override)
+ continue;
+ local_args_info.msisdn_given = 1;
+ args_info->msisdn_given = 1;
+ if (args_info->msisdn_arg)
+ free(args_info->msisdn_arg); /* free previous string */
+ args_info->msisdn_arg = gengetopt_strdup(optarg);
+ if (args_info->msisdn_orig)
+ free(args_info->msisdn_orig); /* free previous string */
+ args_info->msisdn_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'q': /* Requested quality of service. */
+ if (local_args_info.qos_given) {
+ fprintf(stderr,
+ "%s: `--qos' (`-q') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->qos_given && !override)
+ continue;
+ local_args_info.qos_given = 1;
+ args_info->qos_given = 1;
+ args_info->qos_arg = strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->qos_orig)
+ free(args_info->qos_orig); /* free previous string */
+ args_info->qos_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'u': /* Login user ID. */
+ if (local_args_info.uid_given) {
+ fprintf(stderr,
+ "%s: `--uid' (`-u') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->uid_given && !override)
+ continue;
+ local_args_info.uid_given = 1;
+ args_info->uid_given = 1;
+ if (args_info->uid_arg)
+ free(args_info->uid_arg); /* free previous string */
+ args_info->uid_arg = gengetopt_strdup(optarg);
+ if (args_info->uid_orig)
+ free(args_info->uid_orig); /* free previous string */
+ args_info->uid_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'p': /* Login password. */
+ if (local_args_info.pwd_given) {
+ fprintf(stderr,
+ "%s: `--pwd' (`-p') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->pwd_given && !override)
+ continue;
+ local_args_info.pwd_given = 1;
+ args_info->pwd_given = 1;
+ if (args_info->pwd_arg)
+ free(args_info->pwd_arg); /* free previous string */
+ args_info->pwd_arg = gengetopt_strdup(optarg);
+ if (args_info->pwd_orig)
+ free(args_info->pwd_orig); /* free previous string */
+ args_info->pwd_orig = gengetopt_strdup(optarg);
+ break;
+
+ case 'n': /* Network address for local interface. */
+ if (local_args_info.net_given) {
+ fprintf(stderr,
+ "%s: `--net' (`-n') option given more than once%s\n",
+ argv[0],
+ (additional_error ? additional_error :
+ ""));
+ goto failure;
+ }
+ if (args_info->net_given && !override)
+ continue;
+ local_args_info.net_given = 1;
+ args_info->net_given = 1;
+ if (args_info->net_arg)
+ free(args_info->net_arg); /* free previous string */
+ args_info->net_arg = gengetopt_strdup(optarg);
+ if (args_info->net_orig)
+ free(args_info->net_orig); /* free previous string */
+ args_info->net_orig = gengetopt_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 (local_args_info.pidfile_given) {
+ fprintf(stderr,
+ "%s: `--pidfile' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pidfile_given && !override)
+ continue;
+ local_args_info.pidfile_given = 1;
+ args_info->pidfile_given = 1;
+ if (args_info->pidfile_arg)
+ free(args_info->pidfile_arg); /* free previous string */
+ args_info->pidfile_arg =
+ gengetopt_strdup(optarg);
+ if (args_info->pidfile_orig)
+ free(args_info->pidfile_orig); /* free previous string */
+ args_info->pidfile_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Directory of nonvolatile data. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "statedir") == 0) {
+ if (local_args_info.statedir_given) {
+ fprintf(stderr,
+ "%s: `--statedir' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->statedir_given && !override)
+ continue;
+ local_args_info.statedir_given = 1;
+ args_info->statedir_given = 1;
+ if (args_info->statedir_arg)
+ free(args_info->statedir_arg); /* free previous string */
+ args_info->statedir_arg =
+ gengetopt_strdup(optarg);
+ if (args_info->statedir_orig)
+ free(args_info->statedir_orig); /* free previous string */
+ args_info->statedir_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* DNS Server to use. */
+ else if (strcmp(long_options[option_index].name, "dns")
+ == 0) {
+ if (local_args_info.dns_given) {
+ fprintf(stderr,
+ "%s: `--dns' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->dns_given && !override)
+ continue;
+ local_args_info.dns_given = 1;
+ args_info->dns_given = 1;
+ if (args_info->dns_arg)
+ free(args_info->dns_arg); /* free previous string */
+ args_info->dns_arg = gengetopt_strdup(optarg);
+ if (args_info->dns_orig)
+ free(args_info->dns_orig); /* free previous string */
+ args_info->dns_orig = gengetopt_strdup(optarg);
+ }
+ /* Number of contexts. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "contexts") == 0) {
+ if (local_args_info.contexts_given) {
+ fprintf(stderr,
+ "%s: `--contexts' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->contexts_given && !override)
+ continue;
+ local_args_info.contexts_given = 1;
+ args_info->contexts_given = 1;
+ args_info->contexts_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->contexts_orig)
+ free(args_info->contexts_orig); /* free previous string */
+ args_info->contexts_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Exit after timelimit seconds. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "timelimit") == 0) {
+ if (local_args_info.timelimit_given) {
+ fprintf(stderr,
+ "%s: `--timelimit' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->timelimit_given && !override)
+ continue;
+ local_args_info.timelimit_given = 1;
+ args_info->timelimit_given = 1;
+ args_info->timelimit_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->timelimit_orig)
+ free(args_info->timelimit_orig); /* free previous string */
+ args_info->timelimit_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* GTP version to use. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "gtpversion") == 0) {
+ if (local_args_info.gtpversion_given) {
+ fprintf(stderr,
+ "%s: `--gtpversion' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->gtpversion_given && !override)
+ continue;
+ local_args_info.gtpversion_given = 1;
+ args_info->gtpversion_given = 1;
+ args_info->gtpversion_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->gtpversion_orig)
+ free(args_info->gtpversion_orig); /* free previous string */
+ args_info->gtpversion_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Selection mode. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "selmode") == 0) {
+ if (local_args_info.selmode_given) {
+ fprintf(stderr,
+ "%s: `--selmode' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->selmode_given && !override)
+ continue;
+ local_args_info.selmode_given = 1;
+ args_info->selmode_given = 1;
+ args_info->selmode_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->selmode_orig)
+ free(args_info->selmode_orig); /* free previous string */
+ args_info->selmode_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* QoS Extension 1. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "qose1") == 0) {
+ if (args_info->qose1_given) {
+ fprintf(stderr,
+ "%s: `--qose1' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->qose1_given = 1;
+ args_info->qose1_arg =
+ strtoull(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->qose1_orig)
+ free(args_info->qose1_orig); /* free previous string */
+ args_info->qose1_orig =
+ gengetopt_strdup(optarg);
+ break;
+ }
+ /* QoS Extension 2. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "qose2") == 0) {
+ if (args_info->qose2_given) {
+ fprintf(stderr,
+ "%s: `--qose2' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->qose2_given = 1;
+ args_info->qose2_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->qose2_orig)
+ free(args_info->qose2_orig); /* free previous string */
+ args_info->qose2_orig =
+ gengetopt_strdup(optarg);
+ break;
+ }
+ /* QoS Extension 3. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "qose3") == 0) {
+ if (args_info->qose3_given) {
+ fprintf(stderr,
+ "%s: `--qose3' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->qose3_given = 1;
+ args_info->qose3_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->qose3_orig)
+ free(args_info->qose3_orig); /* free previous string */
+ args_info->qose3_orig =
+ gengetopt_strdup(optarg);
+ break;
+ }
+ /* QoS Extension 4. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "qose4") == 0) {
+ if (args_info->qose4_given) {
+ fprintf(stderr,
+ "%s: `--qose4' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->qose4_given = 1;
+ args_info->qose4_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->qose4_orig)
+ free(args_info->qose4_orig); /* free previous string */
+ args_info->qose4_orig =
+ gengetopt_strdup(optarg);
+ break;
+ }
+ /* Radio Access Technology Type. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "rattype") == 0) {
+ if (args_info->rattype_given) {
+ fprintf(stderr,
+ "%s: `--rattype' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->rattype_given = 1;
+ /* args_info->rattype_arg = strtol (optarg,&stop_char,0); */
+ args_info->rattype_arg = strdup(optarg);
+ break;
+ }
+ /* User Location Information. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "userloc") == 0) {
+ if (args_info->userloc_given) {
+ fprintf(stderr,
+ "%s: `--userloc' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->userloc_given = 1;
+ args_info->userloc_arg = strdup(optarg);
+ break;
+ }
+ /* Routing Area Information. */
+ else if (strcmp(long_options[option_index].name, "rai")
+ == 0) {
+ if (args_info->rai_given) {
+ fprintf(stderr,
+ "%s: `--rai' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->rai_given = 1;
+ args_info->rai_arg = strdup(optarg);
+ break;
+ }
+ /* MS Time Zone */
+ else if (strcmp(long_options[option_index].name, "mstz")
+ == 0) {
+ if (args_info->mstz_given) {
+ fprintf(stderr,
+ "%s: `--mstz' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->mstz_given = 1;
+ args_info->mstz_arg = strdup(optarg);
+ break;
+ }
+ /* IMEI(SV) */
+ else if (strcmp
+ (long_options[option_index].name,
+ "imeisv") == 0) {
+ if (args_info->imeisv_given) {
+ fprintf(stderr,
+ "%s: `--imeisv' option given more than once\n",
+ PACKAGE);
+ exit(EXIT_FAILURE);
+ }
+ args_info->imeisv_given = 1;
+ args_info->imeisv_arg = strdup(optarg);
+ break;
+ }
+ /* NSAPI. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "nsapi") == 0) {
+ if (local_args_info.nsapi_given) {
+ fprintf(stderr,
+ "%s: `--nsapi' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->nsapi_given && !override)
+ continue;
+ local_args_info.nsapi_given = 1;
+ args_info->nsapi_given = 1;
+ args_info->nsapi_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->nsapi_orig)
+ free(args_info->nsapi_orig); /* free previous string */
+ args_info->nsapi_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Charging characteristics. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "charging") == 0) {
+ if (local_args_info.charging_given) {
+ fprintf(stderr,
+ "%s: `--charging' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->charging_given && !override)
+ continue;
+ local_args_info.charging_given = 1;
+ args_info->charging_given = 1;
+ args_info->charging_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->charging_orig)
+ free(args_info->charging_orig); /* free previous string */
+ args_info->charging_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Create local network interface. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "createif") == 0) {
+ if (local_args_info.createif_given) {
+ fprintf(stderr,
+ "%s: `--createif' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->createif_given && !override)
+ continue;
+ local_args_info.createif_given = 1;
+ args_info->createif_given = 1;
+ args_info->createif_flag =
+ !(args_info->createif_flag);
+ }
+ /* Create default route. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "defaultroute") == 0) {
+ if (local_args_info.defaultroute_given) {
+ fprintf(stderr,
+ "%s: `--defaultroute' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->defaultroute_given && !override)
+ continue;
+ local_args_info.defaultroute_given = 1;
+ args_info->defaultroute_given = 1;
+ args_info->defaultroute_flag =
+ !(args_info->defaultroute_flag);
+ }
+ /* Script to run after link-up. */
+ else if (strcmp(long_options[option_index].name, "ipup")
+ == 0) {
+ if (local_args_info.ipup_given) {
+ fprintf(stderr,
+ "%s: `--ipup' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->ipup_given && !override)
+ continue;
+ local_args_info.ipup_given = 1;
+ args_info->ipup_given = 1;
+ if (args_info->ipup_arg)
+ free(args_info->ipup_arg); /* free previous string */
+ args_info->ipup_arg = gengetopt_strdup(optarg);
+ if (args_info->ipup_orig)
+ free(args_info->ipup_orig); /* free previous string */
+ args_info->ipup_orig = gengetopt_strdup(optarg);
+ }
+ /* Script to run after link-down. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "ipdown") == 0) {
+ if (local_args_info.ipdown_given) {
+ fprintf(stderr,
+ "%s: `--ipdown' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->ipdown_given && !override)
+ continue;
+ local_args_info.ipdown_given = 1;
+ args_info->ipdown_given = 1;
+ if (args_info->ipdown_arg)
+ free(args_info->ipdown_arg); /* free previous string */
+ args_info->ipdown_arg =
+ gengetopt_strdup(optarg);
+ if (args_info->ipdown_orig)
+ free(args_info->ipdown_orig); /* free previous string */
+ args_info->ipdown_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Ping remote host. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "pinghost") == 0) {
+ if (local_args_info.pinghost_given) {
+ fprintf(stderr,
+ "%s: `--pinghost' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pinghost_given && !override)
+ continue;
+ local_args_info.pinghost_given = 1;
+ args_info->pinghost_given = 1;
+ if (args_info->pinghost_arg)
+ free(args_info->pinghost_arg); /* free previous string */
+ args_info->pinghost_arg =
+ gengetopt_strdup(optarg);
+ if (args_info->pinghost_orig)
+ free(args_info->pinghost_orig); /* free previous string */
+ args_info->pinghost_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Number of ping req per second. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "pingrate") == 0) {
+ if (local_args_info.pingrate_given) {
+ fprintf(stderr,
+ "%s: `--pingrate' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pingrate_given && !override)
+ continue;
+ local_args_info.pingrate_given = 1;
+ args_info->pingrate_given = 1;
+ args_info->pingrate_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->pingrate_orig)
+ free(args_info->pingrate_orig); /* free previous string */
+ args_info->pingrate_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Number of ping data bytes. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "pingsize") == 0) {
+ if (local_args_info.pingsize_given) {
+ fprintf(stderr,
+ "%s: `--pingsize' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pingsize_given && !override)
+ continue;
+ local_args_info.pingsize_given = 1;
+ args_info->pingsize_given = 1;
+ args_info->pingsize_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->pingsize_orig)
+ free(args_info->pingsize_orig); /* free previous string */
+ args_info->pingsize_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Number of ping req to send. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "pingcount") == 0) {
+ if (local_args_info.pingcount_given) {
+ fprintf(stderr,
+ "%s: `--pingcount' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pingcount_given && !override)
+ continue;
+ local_args_info.pingcount_given = 1;
+ args_info->pingcount_given = 1;
+ args_info->pingcount_arg =
+ strtol(optarg, &stop_char, 0);
+ if (!(stop_char && *stop_char == '\0')) {
+ fprintf(stderr,
+ "%s: invalid numeric value: %s\n",
+ argv[0], optarg);
+ goto failure;
+ }
+ if (args_info->pingcount_orig)
+ free(args_info->pingcount_orig); /* free previous string */
+ args_info->pingcount_orig =
+ gengetopt_strdup(optarg);
+ }
+ /* Do not print ping packet info. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "pingquiet") == 0) {
+ if (local_args_info.pingquiet_given) {
+ fprintf(stderr,
+ "%s: `--pingquiet' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->pingquiet_given && !override)
+ continue;
+ local_args_info.pingquiet_given = 1;
+ args_info->pingquiet_given = 1;
+ args_info->pingquiet_flag =
+ !(args_info->pingquiet_flag);
+ }
+ /* Do not send recovery. */
+ else if (strcmp
+ (long_options[option_index].name,
+ "norecovery") == 0) {
+ if (local_args_info.norecovery_given) {
+ fprintf(stderr,
+ "%s: `--norecovery' option given more than once%s\n",
+ argv[0],
+ (additional_error ?
+ additional_error : ""));
+ goto failure;
+ }
+ if (args_info->norecovery_given && !override)
+ continue;
+ local_args_info.norecovery_given = 1;
+ args_info->norecovery_given = 1;
+ args_info->norecovery_flag =
+ !(args_info->norecovery_flag);
+ }
+
+ break;
+ case '?': /* Invalid option. */
+ /* `getopt_long' already printed an error message. */
+ goto failure;
+
+ default: /* bug: option not considered. */
+ fprintf(stderr, "%s: option unknown: %c%s\n",
+ CMDLINE_PARSER_PACKAGE, c,
+ (additional_error ? additional_error : ""));
+ abort();
+ } /* switch */
+ } /* while */
+
+ cmdline_parser_release(&local_args_info);
+
+ if (error)
+ return (EXIT_FAILURE);
+
+ return 0;
failure:
-
- cmdline_parser_release (&local_args_info);
- return (EXIT_FAILURE);
+
+ cmdline_parser_release(&local_args_info);
+ return (EXIT_FAILURE);
}
#ifndef CONFIG_FILE_LINE_SIZE
@@ -1587,168 +1759,167 @@ failure:
#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
/* 3 is for "--" and "=" */
-char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
+char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE + 1];
int
-cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+cmdline_parser_configfile(char *const filename,
+ struct gengetopt_args_info *args_info, int override,
+ int initialize, int check_required)
{
- FILE* file;
- char linebuf[CONFIG_FILE_LINE_SIZE];
- int line_num = 0;
- int i, result, equal;
- char *fopt, *farg;
- char *str_index;
- size_t len, next_token;
- char delimiter;
- int my_argc = 0;
- char **my_argv_arg;
- char *additional_error;
-
- /* store the program name */
- cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
- cmd_line_list_tmp->next = cmd_line_list;
- cmd_line_list = cmd_line_list_tmp;
- cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE);
-
- if ((file = fopen(filename, "r")) == NULL)
- {
- fprintf (stderr, "%s: Error opening configuration file '%s'\n",
- CMDLINE_PARSER_PACKAGE, filename);
- result = EXIT_FAILURE;
- goto conf_failure;
- }
-
- while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
- {
- ++line_num;
- my_argv[0] = '\0';
- len = strlen(linebuf);
- if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
- {
- fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
- CMDLINE_PARSER_PACKAGE, filename, line_num);
- result = EXIT_FAILURE;
- goto conf_failure;
- }
-
- /* find first non-whitespace character in the line */
- next_token = strspn ( linebuf, " \t\r\n");
- str_index = linebuf + next_token;
-
- if ( str_index[0] == '\0' || str_index[0] == '#')
- continue; /* empty line or comment line is skipped */
-
- fopt = str_index;
-
- /* truncate fopt at the end of the first non-valid character */
- next_token = strcspn (fopt, " \t\r\n=");
-
- if (fopt[next_token] == '\0') /* the line is over */
- {
- farg = NULL;
- equal = 0;
- goto noarg;
- }
-
- /* remember if equal sign is present */
- equal = (fopt[next_token] == '=');
- fopt[next_token++] = '\0';
-
- /* advance pointers to the next token after the end of fopt */
- next_token += strspn (fopt + next_token, " \t\r\n");
- /* check for the presence of equal sign, and if so, skip it */
- if ( !equal )
- if ((equal = (fopt[next_token] == '=')))
- {
- next_token++;
- next_token += strspn (fopt + next_token, " \t\r\n");
- }
- str_index += next_token;
-
- /* find argument */
- farg = str_index;
- if ( farg[0] == '\"' || farg[0] == '\'' )
- { /* quoted argument */
- str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
- if (! str_index)
- {
- fprintf
- (stderr,
- "%s:%s:%d: unterminated string in configuration file\n",
- CMDLINE_PARSER_PACKAGE, filename, line_num);
- result = EXIT_FAILURE;
- goto conf_failure;
- }
- }
- else
- { /* read up the remaining part up to a delimiter */
- next_token = strcspn (farg, " \t\r\n#\'\"");
- str_index += next_token;
- }
-
- /* truncate farg at the delimiter and store it for further check */
- delimiter = *str_index, *str_index++ = '\0';
-
- /* everything but comment is illegal at the end of line */
- if (delimiter != '\0' && delimiter != '#')
- {
- str_index += strspn(str_index, " \t\r\n");
- if (*str_index != '\0' && *str_index != '#')
- {
- fprintf
- (stderr,
- "%s:%s:%d: malformed string in configuration file\n",
- CMDLINE_PARSER_PACKAGE, filename, line_num);
- result = EXIT_FAILURE;
- goto conf_failure;
- }
- }
-
- noarg:
- ++my_argc;
- len = strlen(fopt);
-
- strcat (my_argv, len > 1 ? "--" : "-");
- strcat (my_argv, fopt);
- if (len > 1 && ((farg &&*farg) || equal))
- strcat (my_argv, "=");
- if (farg && *farg)
- strcat (my_argv, farg);
-
- cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
- cmd_line_list_tmp->next = cmd_line_list;
- cmd_line_list = cmd_line_list_tmp;
- cmd_line_list->string_arg = gengetopt_strdup(my_argv);
- } /* while */
-
- ++my_argc; /* for program name */
- my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
- cmd_line_list_tmp = cmd_line_list;
- for (i = my_argc - 1; i >= 0; --i) {
- my_argv_arg[i] = cmd_line_list_tmp->string_arg;
- cmd_line_list_tmp = cmd_line_list_tmp->next;
- }
- my_argv_arg[my_argc] = 0;
-
- additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
- strcpy (additional_error, ADDITIONAL_ERROR);
- strcat (additional_error, filename);
- result =
- cmdline_parser_internal (my_argc, my_argv_arg, args_info, override, initialize, check_required, additional_error);
-
- free (additional_error);
- free (my_argv_arg);
+ FILE *file;
+ char linebuf[CONFIG_FILE_LINE_SIZE];
+ int line_num = 0;
+ int i, result, equal;
+ char *fopt, *farg;
+ char *str_index;
+ size_t len, next_token;
+ char delimiter;
+ int my_argc = 0;
+ char **my_argv_arg;
+ char *additional_error;
+
+ /* store the program name */
+ cmd_line_list_tmp =
+ (struct line_list *)malloc(sizeof(struct line_list));
+ cmd_line_list_tmp->next = cmd_line_list;
+ cmd_line_list = cmd_line_list_tmp;
+ cmd_line_list->string_arg = gengetopt_strdup(CMDLINE_PARSER_PACKAGE);
+
+ if ((file = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "%s: Error opening configuration file '%s'\n",
+ CMDLINE_PARSER_PACKAGE, filename);
+ result = EXIT_FAILURE;
+ goto conf_failure;
+ }
+
+ while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) {
+ ++line_num;
+ my_argv[0] = '\0';
+ len = strlen(linebuf);
+ if (len > (CONFIG_FILE_LINE_BUFFER_SIZE - 1)) {
+ fprintf(stderr,
+ "%s:%s:%d: Line too long in configuration file\n",
+ CMDLINE_PARSER_PACKAGE, filename, line_num);
+ result = EXIT_FAILURE;
+ goto conf_failure;
+ }
+
+ /* find first non-whitespace character in the line */
+ next_token = strspn(linebuf, " \t\r\n");
+ str_index = linebuf + next_token;
+
+ if (str_index[0] == '\0' || str_index[0] == '#')
+ continue; /* empty line or comment line is skipped */
+
+ fopt = str_index;
+
+ /* truncate fopt at the end of the first non-valid character */
+ next_token = strcspn(fopt, " \t\r\n=");
+
+ if (fopt[next_token] == '\0') { /* the line is over */
+ farg = NULL;
+ equal = 0;
+ goto noarg;
+ }
+
+ /* remember if equal sign is present */
+ equal = (fopt[next_token] == '=');
+ fopt[next_token++] = '\0';
+
+ /* advance pointers to the next token after the end of fopt */
+ next_token += strspn(fopt + next_token, " \t\r\n");
+ /* check for the presence of equal sign, and if so, skip it */
+ if (!equal)
+ if ((equal = (fopt[next_token] == '='))) {
+ next_token++;
+ next_token +=
+ strspn(fopt + next_token, " \t\r\n");
+ }
+ str_index += next_token;
+
+ /* find argument */
+ farg = str_index;
+ if (farg[0] == '\"' || farg[0] == '\'') { /* quoted argument */
+ str_index = strchr(++farg, str_index[0]); /* skip opening quote */
+ if (!str_index) {
+ fprintf
+ (stderr,
+ "%s:%s:%d: unterminated string in configuration file\n",
+ CMDLINE_PARSER_PACKAGE, filename,
+ line_num);
+ result = EXIT_FAILURE;
+ goto conf_failure;
+ }
+ } else { /* read up the remaining part up to a delimiter */
+ next_token = strcspn(farg, " \t\r\n#\'\"");
+ str_index += next_token;
+ }
+
+ /* truncate farg at the delimiter and store it for further check */
+ delimiter = *str_index, *str_index++ = '\0';
+
+ /* everything but comment is illegal at the end of line */
+ if (delimiter != '\0' && delimiter != '#') {
+ str_index += strspn(str_index, " \t\r\n");
+ if (*str_index != '\0' && *str_index != '#') {
+ fprintf
+ (stderr,
+ "%s:%s:%d: malformed string in configuration file\n",
+ CMDLINE_PARSER_PACKAGE, filename,
+ line_num);
+ result = EXIT_FAILURE;
+ goto conf_failure;
+ }
+ }
+
+noarg:
+ ++my_argc;
+ len = strlen(fopt);
+
+ strcat(my_argv, len > 1 ? "--" : "-");
+ strcat(my_argv, fopt);
+ if (len > 1 && ((farg && *farg) || equal))
+ strcat(my_argv, "=");
+ if (farg && *farg)
+ strcat(my_argv, farg);
+
+ cmd_line_list_tmp =
+ (struct line_list *)malloc(sizeof(struct line_list));
+ cmd_line_list_tmp->next = cmd_line_list;
+ cmd_line_list = cmd_line_list_tmp;
+ cmd_line_list->string_arg = gengetopt_strdup(my_argv);
+ } /* while */
+
+ ++my_argc; /* for program name */
+ my_argv_arg = (char **)malloc((my_argc + 1) * sizeof(char *));
+ cmd_line_list_tmp = cmd_line_list;
+ for (i = my_argc - 1; i >= 0; --i) {
+ my_argv_arg[i] = cmd_line_list_tmp->string_arg;
+ cmd_line_list_tmp = cmd_line_list_tmp->next;
+ }
+ my_argv_arg[my_argc] = 0;
+
+ additional_error =
+ (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
+ strcpy(additional_error, ADDITIONAL_ERROR);
+ strcat(additional_error, filename);
+ result =
+ cmdline_parser_internal(my_argc, my_argv_arg, args_info, override,
+ initialize, check_required,
+ additional_error);
+
+ free(additional_error);
+ free(my_argv_arg);
conf_failure:
- if (file)
- fclose(file);
-
- free_cmd_list();
- if (result == EXIT_FAILURE)
- {
- cmdline_parser_free (args_info);
- exit (EXIT_FAILURE);
- }
-
- return result;
+ if (file)
+ fclose(file);
+
+ free_cmd_list();
+ if (result == EXIT_FAILURE) {
+ cmdline_parser_free(args_info);
+ exit(EXIT_FAILURE);
+ }
+
+ return result;
}
diff --git a/sgsnemu/cmdline.h b/sgsnemu/cmdline.h
index 24185f4..17f7c18 100644
--- a/sgsnemu/cmdline.h
+++ b/sgsnemu/cmdline.h
@@ -12,7 +12,7 @@
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
#ifndef CMDLINE_PARSER_PACKAGE
#define CMDLINE_PARSER_PACKAGE PACKAGE
@@ -22,190 +22,189 @@ extern "C" {
#define CMDLINE_PARSER_VERSION VERSION
#endif
-struct gengetopt_args_info
-{
- const char *help_help; /* Print help and exit help description. */
- const char *version_help; /* Print version and exit help description. */
- int debug_flag; /* Run in debug mode (default=off). */
- const char *debug_help; /* Run in debug mode help description. */
- char * conf_arg; /* Read configuration file. */
- char * conf_orig; /* Read configuration file original value given at command line. */
- const char *conf_help; /* Read configuration file help description. */
- char * pidfile_arg; /* Filename of process id file (default='./sgsnemu.pid'). */
- char * pidfile_orig; /* Filename of process id file original value given at command line. */
- const char *pidfile_help; /* Filename of process id file help description. */
- char * statedir_arg; /* Directory of nonvolatile data (default='./'). */
- char * statedir_orig; /* Directory of nonvolatile data original value given at command line. */
- const char *statedir_help; /* Directory of nonvolatile data help description. */
- char * dns_arg; /* DNS Server to use. */
- char * dns_orig; /* DNS Server to use original value given at command line. */
- const char *dns_help; /* DNS Server to use help description. */
- char * listen_arg; /* Local interface. */
- char * listen_orig; /* Local interface original value given at command line. */
- const char *listen_help; /* Local interface help description. */
- char * remote_arg; /* Remote host. */
- char * remote_orig; /* Remote host original value given at command line. */
- const char *remote_help; /* Remote host help description. */
- int contexts_arg; /* Number of contexts (default='1'). */
- char * contexts_orig; /* Number of contexts original value given at command line. */
- const char *contexts_help; /* Number of contexts help description. */
- int timelimit_arg; /* Exit after timelimit seconds (default='0'). */
- char * timelimit_orig; /* Exit after timelimit seconds original value given at command line. */
- const char *timelimit_help; /* Exit after timelimit seconds help description. */
- int gtpversion_arg; /* GTP version to use (default='1'). */
- char * gtpversion_orig; /* GTP version to use original value given at command line. */
- const char *gtpversion_help; /* GTP version to use help description. */
- char * apn_arg; /* Access point name (default='internet'). */
- char * apn_orig; /* Access point name original value given at command line. */
- const char *apn_help; /* Access point name help description. */
- int selmode_arg; /* Selection mode (default='0x01'). */
- char * selmode_orig; /* Selection mode original value given at command line. */
- const char *selmode_help; /* Selection mode help description. */
- char * rattype_arg; /* Radio Access Technology Type (optional). */
- char * rattype_orig;
- char * rattype_help;
- char * userloc_arg; /* User Location Information (optional). */
- char * userloc_orig;
- char * userloc_help;
- char * rai_arg; /* Routing Area Information (optional). */
- char * rai_orig;
- char * rai_help;
- char * mstz_arg; /* MS Time Zone (optional). */
- char * mstz_orig;
- char * mstz_help;
- char * imeisv_arg; /* IMEI(SV) (optional). */
- char * imeisv_orig;
- char * imeisv_help;
- char * imsi_arg; /* IMSI (default='240010123456789'). */
- char * imsi_orig; /* IMSI original value given at command line. */
- const char *imsi_help; /* IMSI help description. */
- int nsapi_arg; /* NSAPI (default='0'). */
- char * nsapi_orig; /* NSAPI original value given at command line. */
- const char *nsapi_help; /* NSAPI help description. */
- char * msisdn_arg; /* Mobile Station ISDN number (default='46702123456'). */
- char * msisdn_orig; /* Mobile Station ISDN number original value given at command line. */
- const char *msisdn_help; /* Mobile Station ISDN number help description. */
- int qos_arg; /* Requested quality of service (default='0x0b921f'). */
- char * qos_orig; /* Requested quality of service original value given at command line. */
- const char *qos_help; /* Requested quality of service help description. */
- unsigned long long int qose1_arg; /* Requested quality of service Extension 1 */
- char * qose1_orig; /* Requested quality of service Extension 1 original value given at command line. */
- int qose2_arg; /* Requested quality of service Extension 2 */
- char * qose2_orig; /* Requested quality of service Extension 2 original value given at command line. */
- int qose3_arg; /* Requested quality of service Extension 3 */
- char * qose3_orig; /* Requested quality of service Extension 3 original value given at command line. */
- int qose4_arg; /* Requested quality of service Extension 4 */
- char * qose4_orig; /* Requested quality of service Extension 4 original value given at command line. */
- int charging_arg; /* Charging characteristics (default='0x0800'). */
- char * charging_orig; /* Charging characteristics original value given at command line. */
- const char *charging_help; /* Charging characteristics help description. */
- char * uid_arg; /* Login user ID (default='mig'). */
- char * uid_orig; /* Login user ID original value given at command line. */
- const char *uid_help; /* Login user ID help description. */
- char * pwd_arg; /* Login password (default='hemmelig'). */
- char * pwd_orig; /* Login password original value given at command line. */
- const char *pwd_help; /* Login password help description. */
- int createif_flag; /* Create local network interface (default=off). */
- const char *createif_help; /* Create local network interface help description. */
- char * net_arg; /* Network address for local interface. */
- char * net_orig; /* Network address for local interface original value given at command line. */
- const char *net_help; /* Network address for local interface help description. */
- int defaultroute_flag; /* Create default route (default=off). */
- const char *defaultroute_help; /* Create default route help description. */
- char * ipup_arg; /* Script to run after link-up. */
- char * ipup_orig; /* Script to run after link-up original value given at command line. */
- const char *ipup_help; /* Script to run after link-up help description. */
- char * ipdown_arg; /* Script to run after link-down. */
- char * ipdown_orig; /* Script to run after link-down original value given at command line. */
- const char *ipdown_help; /* Script to run after link-down help description. */
- char * pinghost_arg; /* Ping remote host. */
- char * pinghost_orig; /* Ping remote host original value given at command line. */
- const char *pinghost_help; /* Ping remote host help description. */
- int pingrate_arg; /* Number of ping req per second (default='1'). */
- char * pingrate_orig; /* Number of ping req per second original value given at command line. */
- const char *pingrate_help; /* Number of ping req per second help description. */
- int pingsize_arg; /* Number of ping data bytes (default='56'). */
- char * pingsize_orig; /* Number of ping data bytes original value given at command line. */
- const char *pingsize_help; /* Number of ping data bytes help description. */
- int pingcount_arg; /* Number of ping req to send (default='0'). */
- char * pingcount_orig; /* Number of ping req to send original value given at command line. */
- const char *pingcount_help; /* Number of ping req to send help description. */
- int pingquiet_flag; /* Do not print ping packet info (default=off). */
- const char *pingquiet_help; /* Do not print ping packet info help description. */
- int norecovery_flag; /* Do not print ping packet info (default=off). */
- const char *norecovery_help; /* Do not print ping packet info help description. */
-
- int help_given ; /* Whether help was given. */
- int version_given ; /* Whether version was given. */
- int debug_given ; /* Whether debug was given. */
- int conf_given ; /* Whether conf was given. */
- int pidfile_given ; /* Whether pidfile was given. */
- int statedir_given ; /* Whether statedir was given. */
- int dns_given ; /* Whether dns was given. */
- int listen_given ; /* Whether listen was given. */
- int remote_given ; /* Whether remote was given. */
- int contexts_given ; /* Whether contexts was given. */
- int timelimit_given ; /* Whether timelimit was given. */
- int gtpversion_given ; /* Whether gtpversion was given. */
- int apn_given ; /* Whether apn was given. */
- int selmode_given ; /* Whether selmode was given. */
- int rattype_given ; /* Whether rattype was given. */
- int userloc_given ; /* Whether userloc was given. */
- int rai_given ; /* Whether RAI was given. */
- int mstz_given ; /* Whether mstz was given. */
- int imeisv_given ; /* Whether imeisv was given. */
- int imsi_given ; /* Whether imsi was given. */
- int nsapi_given ; /* Whether nsapi was given. */
- int msisdn_given ; /* Whether msisdn was given. */
- int qos_given ; /* Whether qos was given. */
- int qose1_given ; /* Whether qos Extension 1 was given. */
- int qose2_given ; /* Whether qos Extension 2 was given. */
- int qose3_given ; /* Whether qos Extension 3 was given. */
- int qose4_given ; /* Whether qos Extension 4 was given. */
- int charging_given ; /* Whether charging was given. */
- int uid_given ; /* Whether uid was given. */
- int pwd_given ; /* Whether pwd was given. */
- int createif_given ; /* Whether createif was given. */
- int net_given ; /* Whether net was given. */
- int defaultroute_given ; /* Whether defaultroute was given. */
- int ipup_given ; /* Whether ipup was given. */
- int ipdown_given ; /* Whether ipdown was given. */
- int pinghost_given ; /* Whether pinghost was given. */
- int pingrate_given ; /* Whether pingrate was given. */
- int pingsize_given ; /* Whether pingsize was given. */
- int pingcount_given ; /* Whether pingcount was given. */
- int pingquiet_given ; /* Whether pingquiet was given. */
- int norecovery_given ; /* Whether norecovery was given. */
-
-} ;
-
-extern const char *gengetopt_args_info_purpose;
-extern const char *gengetopt_args_info_usage;
-extern const char *gengetopt_args_info_help[];
-
-int cmdline_parser (int argc, char * const *argv,
- struct gengetopt_args_info *args_info);
-int cmdline_parser2 (int argc, char * const *argv,
- struct gengetopt_args_info *args_info,
- int override, int initialize, int check_required);
-int cmdline_parser_file_save(const char *filename,
- struct gengetopt_args_info *args_info);
-
-void cmdline_parser_print_help(void);
-void cmdline_parser_print_version(void);
-
-void cmdline_parser_init (struct gengetopt_args_info *args_info);
-void cmdline_parser_free (struct gengetopt_args_info *args_info);
-
-int cmdline_parser_configfile (char * const filename,
- struct gengetopt_args_info *args_info,
- int override, int initialize, int check_required);
-
-int cmdline_parser_required (struct gengetopt_args_info *args_info,
- const char *prog_name);
-
+ struct gengetopt_args_info {
+ const char *help_help; /* Print help and exit help description. */
+ const char *version_help; /* Print version and exit help description. */
+ int debug_flag; /* Run in debug mode (default=off). */
+ const char *debug_help; /* Run in debug mode help description. */
+ char *conf_arg; /* Read configuration file. */
+ char *conf_orig; /* Read configuration file original value given at command line. */
+ const char *conf_help; /* Read configuration file help description. */
+ char *pidfile_arg; /* Filename of process id file (default='./sgsnemu.pid'). */
+ char *pidfile_orig; /* Filename of process id file original value given at command line. */
+ const char *pidfile_help; /* Filename of process id file help description. */
+ char *statedir_arg; /* Directory of nonvolatile data (default='./'). */
+ char *statedir_orig; /* Directory of nonvolatile data original value given at command line. */
+ const char *statedir_help; /* Directory of nonvolatile data help description. */
+ char *dns_arg; /* DNS Server to use. */
+ char *dns_orig; /* DNS Server to use original value given at command line. */
+ const char *dns_help; /* DNS Server to use help description. */
+ char *listen_arg; /* Local interface. */
+ char *listen_orig; /* Local interface original value given at command line. */
+ const char *listen_help; /* Local interface help description. */
+ char *remote_arg; /* Remote host. */
+ char *remote_orig; /* Remote host original value given at command line. */
+ const char *remote_help; /* Remote host help description. */
+ int contexts_arg; /* Number of contexts (default='1'). */
+ char *contexts_orig; /* Number of contexts original value given at command line. */
+ const char *contexts_help; /* Number of contexts help description. */
+ int timelimit_arg; /* Exit after timelimit seconds (default='0'). */
+ char *timelimit_orig; /* Exit after timelimit seconds original value given at command line. */
+ const char *timelimit_help; /* Exit after timelimit seconds help description. */
+ int gtpversion_arg; /* GTP version to use (default='1'). */
+ char *gtpversion_orig; /* GTP version to use original value given at command line. */
+ const char *gtpversion_help; /* GTP version to use help description. */
+ char *apn_arg; /* Access point name (default='internet'). */
+ char *apn_orig; /* Access point name original value given at command line. */
+ const char *apn_help; /* Access point name help description. */
+ int selmode_arg; /* Selection mode (default='0x01'). */
+ char *selmode_orig; /* Selection mode original value given at command line. */
+ const char *selmode_help; /* Selection mode help description. */
+ char *rattype_arg; /* Radio Access Technology Type (optional). */
+ char *rattype_orig;
+ char *rattype_help;
+ char *userloc_arg; /* User Location Information (optional). */
+ char *userloc_orig;
+ char *userloc_help;
+ char *rai_arg; /* Routing Area Information (optional). */
+ char *rai_orig;
+ char *rai_help;
+ char *mstz_arg; /* MS Time Zone (optional). */
+ char *mstz_orig;
+ char *mstz_help;
+ char *imeisv_arg; /* IMEI(SV) (optional). */
+ char *imeisv_orig;
+ char *imeisv_help;
+ char *imsi_arg; /* IMSI (default='240010123456789'). */
+ char *imsi_orig; /* IMSI original value given at command line. */
+ const char *imsi_help; /* IMSI help description. */
+ int nsapi_arg; /* NSAPI (default='0'). */
+ char *nsapi_orig; /* NSAPI original value given at command line. */
+ const char *nsapi_help; /* NSAPI help description. */
+ char *msisdn_arg; /* Mobile Station ISDN number (default='46702123456'). */
+ char *msisdn_orig; /* Mobile Station ISDN number original value given at command line. */
+ const char *msisdn_help; /* Mobile Station ISDN number help description. */
+ int qos_arg; /* Requested quality of service (default='0x0b921f'). */
+ char *qos_orig; /* Requested quality of service original value given at command line. */
+ const char *qos_help; /* Requested quality of service help description. */
+ unsigned long long int qose1_arg; /* Requested quality of service Extension 1 */
+ char *qose1_orig; /* Requested quality of service Extension 1 original value given at command line. */
+ int qose2_arg; /* Requested quality of service Extension 2 */
+ char *qose2_orig; /* Requested quality of service Extension 2 original value given at command line. */
+ int qose3_arg; /* Requested quality of service Extension 3 */
+ char *qose3_orig; /* Requested quality of service Extension 3 original value given at command line. */
+ int qose4_arg; /* Requested quality of service Extension 4 */
+ char *qose4_orig; /* Requested quality of service Extension 4 original value given at command line. */
+ int charging_arg; /* Charging characteristics (default='0x0800'). */
+ char *charging_orig; /* Charging characteristics original value given at command line. */
+ const char *charging_help; /* Charging characteristics help description. */
+ char *uid_arg; /* Login user ID (default='mig'). */
+ char *uid_orig; /* Login user ID original value given at command line. */
+ const char *uid_help; /* Login user ID help description. */
+ char *pwd_arg; /* Login password (default='hemmelig'). */
+ char *pwd_orig; /* Login password original value given at command line. */
+ const char *pwd_help; /* Login password help description. */
+ int createif_flag; /* Create local network interface (default=off). */
+ const char *createif_help; /* Create local network interface help description. */
+ char *net_arg; /* Network address for local interface. */
+ char *net_orig; /* Network address for local interface original value given at command line. */
+ const char *net_help; /* Network address for local interface help description. */
+ int defaultroute_flag; /* Create default route (default=off). */
+ const char *defaultroute_help; /* Create default route help description. */
+ char *ipup_arg; /* Script to run after link-up. */
+ char *ipup_orig; /* Script to run after link-up original value given at command line. */
+ const char *ipup_help; /* Script to run after link-up help description. */
+ char *ipdown_arg; /* Script to run after link-down. */
+ char *ipdown_orig; /* Script to run after link-down original value given at command line. */
+ const char *ipdown_help; /* Script to run after link-down help description. */
+ char *pinghost_arg; /* Ping remote host. */
+ char *pinghost_orig; /* Ping remote host original value given at command line. */
+ const char *pinghost_help; /* Ping remote host help description. */
+ int pingrate_arg; /* Number of ping req per second (default='1'). */
+ char *pingrate_orig; /* Number of ping req per second original value given at command line. */
+ const char *pingrate_help; /* Number of ping req per second help description. */
+ int pingsize_arg; /* Number of ping data bytes (default='56'). */
+ char *pingsize_orig; /* Number of ping data bytes original value given at command line. */
+ const char *pingsize_help; /* Number of ping data bytes help description. */
+ int pingcount_arg; /* Number of ping req to send (default='0'). */
+ char *pingcount_orig; /* Number of ping req to send original value given at command line. */
+ const char *pingcount_help; /* Number of ping req to send help description. */
+ int pingquiet_flag; /* Do not print ping packet info (default=off). */
+ const char *pingquiet_help; /* Do not print ping packet info help description. */
+ int norecovery_flag; /* Do not print ping packet info (default=off). */
+ const char *norecovery_help; /* Do not print ping packet info help description. */
+
+ int help_given; /* Whether help was given. */
+ int version_given; /* Whether version was given. */
+ int debug_given; /* Whether debug was given. */
+ int conf_given; /* Whether conf was given. */
+ int pidfile_given; /* Whether pidfile was given. */
+ int statedir_given; /* Whether statedir was given. */
+ int dns_given; /* Whether dns was given. */
+ int listen_given; /* Whether listen was given. */
+ int remote_given; /* Whether remote was given. */
+ int contexts_given; /* Whether contexts was given. */
+ int timelimit_given; /* Whether timelimit was given. */
+ int gtpversion_given; /* Whether gtpversion was given. */
+ int apn_given; /* Whether apn was given. */
+ int selmode_given; /* Whether selmode was given. */
+ int rattype_given; /* Whether rattype was given. */
+ int userloc_given; /* Whether userloc was given. */
+ int rai_given; /* Whether RAI was given. */
+ int mstz_given; /* Whether mstz was given. */
+ int imeisv_given; /* Whether imeisv was given. */
+ int imsi_given; /* Whether imsi was given. */
+ int nsapi_given; /* Whether nsapi was given. */
+ int msisdn_given; /* Whether msisdn was given. */
+ int qos_given; /* Whether qos was given. */
+ int qose1_given; /* Whether qos Extension 1 was given. */
+ int qose2_given; /* Whether qos Extension 2 was given. */
+ int qose3_given; /* Whether qos Extension 3 was given. */
+ int qose4_given; /* Whether qos Extension 4 was given. */
+ int charging_given; /* Whether charging was given. */
+ int uid_given; /* Whether uid was given. */
+ int pwd_given; /* Whether pwd was given. */
+ int createif_given; /* Whether createif was given. */
+ int net_given; /* Whether net was given. */
+ int defaultroute_given; /* Whether defaultroute was given. */
+ int ipup_given; /* Whether ipup was given. */
+ int ipdown_given; /* Whether ipdown was given. */
+ int pinghost_given; /* Whether pinghost was given. */
+ int pingrate_given; /* Whether pingrate was given. */
+ int pingsize_given; /* Whether pingsize was given. */
+ int pingcount_given; /* Whether pingcount was given. */
+ int pingquiet_given; /* Whether pingquiet was given. */
+ int norecovery_given; /* Whether norecovery was given. */
+
+ };
+
+ extern const char *gengetopt_args_info_purpose;
+ extern const char *gengetopt_args_info_usage;
+ extern const char *gengetopt_args_info_help[];
+
+ int cmdline_parser(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info);
+ int cmdline_parser2(int argc, char *const *argv,
+ struct gengetopt_args_info *args_info,
+ int override, int initialize, int check_required);
+ int cmdline_parser_file_save(const char *filename,
+ struct gengetopt_args_info *args_info);
+
+ void cmdline_parser_print_help(void);
+ void cmdline_parser_print_version(void);
+
+ void cmdline_parser_init(struct gengetopt_args_info *args_info);
+ void cmdline_parser_free(struct gengetopt_args_info *args_info);
+
+ int cmdline_parser_configfile(char *const filename,
+ struct gengetopt_args_info *args_info,
+ int override, int initialize,
+ int check_required);
+
+ int cmdline_parser_required(struct gengetopt_args_info *args_info,
+ const char *prog_name);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-#endif /* CMDLINE_H */
+#endif /* __cplusplus */
+#endif /* CMDLINE_H */
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 48a33ea..79494c9 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -14,12 +14,10 @@
*
*/
-
#ifdef __linux__
-#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
+#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
#endif
-
#include <syslog.h>
#include <ctype.h>
#include <netdb.h>
@@ -51,15 +49,15 @@
#include "../gtp/gtp.h"
#include "cmdline.h"
-#define IPADDRLEN 256 /* Character length of addresses */
-#define MAXCONTEXTS 1024 /* Max number of allowed contexts */
+#define IPADDRLEN 256 /* Character length of addresses */
+#define MAXCONTEXTS 1024 /* Max number of allowed contexts */
/* HASH tables for IP address allocation */
struct iphash_t {
- uint8_t inuse; /* 0=free. 1=used by somebody */
- struct iphash_t *ipnext;
- struct pdp_t *pdp;
- struct in_addr addr;
+ uint8_t inuse; /* 0=free. 1=used by somebody */
+ struct iphash_t *ipnext;
+ struct pdp_t *pdp;
+ struct in_addr addr;
};
struct iphash_t iparr[MAXCONTEXTS];
struct iphash_t *iphash[MAXCONTEXTS];
@@ -73,52 +71,51 @@ struct iphash_t *iphash[MAXCONTEXTS];
/* 5: Disconnected */
int state = 0;
-struct gsn_t *gsn = NULL; /* GSN instance */
-struct tun_t *tun = NULL; /* TUN instance */
-int maxfd = 0; /* For select() */
-int echoversion = 1; /* First try this version */
+struct gsn_t *gsn = NULL; /* GSN instance */
+struct tun_t *tun = NULL; /* TUN instance */
+int maxfd = 0; /* For select() */
+int echoversion = 1; /* First try this version */
/* Struct with local versions of gengetopt options */
struct {
- int debug; /* Print debug messages */
- int createif; /* Create local network interface */
- struct in_addr netaddr, destaddr, net, mask; /* Network interface */
- char *ipup, *ipdown; /* Filename of scripts */
- int defaultroute; /* Set up default route */
- struct in_addr pinghost; /* Remote ping host */
- int pingrate;
- int pingsize;
- int pingcount;
- int pingquiet;
- struct in_addr listen;
- struct in_addr remote;
- struct in_addr dns;
- int contexts; /* Number of contexts to create */
- int timelimit; /* Number of seconds to be connected */
- char *statedir;
- uint64_t imsi;
- uint8_t nsapi;
- int gtpversion;
- struct ul255_t pco;
- struct ul255_t qos;
- uint16_t cch;
- struct ul255_t apn;
- uint8_t selmode;
- struct ul255_t rattype;
- int rattype_given;
- struct ul255_t userloc;
- int userloc_given;
- struct ul255_t rai;
- int rai_given;
- struct ul255_t mstz;
- int mstz_given;
- struct ul255_t imeisv;
- int imeisv_given;
- struct ul16_t msisdn;
- int norecovery_given;
+ int debug; /* Print debug messages */
+ int createif; /* Create local network interface */
+ struct in_addr netaddr, destaddr, net, mask; /* Network interface */
+ char *ipup, *ipdown; /* Filename of scripts */
+ int defaultroute; /* Set up default route */
+ struct in_addr pinghost; /* Remote ping host */
+ int pingrate;
+ int pingsize;
+ int pingcount;
+ int pingquiet;
+ struct in_addr listen;
+ struct in_addr remote;
+ struct in_addr dns;
+ int contexts; /* Number of contexts to create */
+ int timelimit; /* Number of seconds to be connected */
+ char *statedir;
+ uint64_t imsi;
+ uint8_t nsapi;
+ int gtpversion;
+ struct ul255_t pco;
+ struct ul255_t qos;
+ uint16_t cch;
+ struct ul255_t apn;
+ uint8_t selmode;
+ struct ul255_t rattype;
+ int rattype_given;
+ struct ul255_t userloc;
+ int userloc_given;
+ struct ul255_t rai;
+ int rai_given;
+ struct ul255_t mstz;
+ int mstz_given;
+ struct ul255_t imeisv;
+ int imeisv_given;
+ struct ul16_t msisdn;
+ int norecovery_given;
} options;
-
/* Definitions to use for PING. Most of the ping code was derived from */
/* the original ping program by Mike Muuss */
@@ -128,23 +125,23 @@ struct {
#define CREATEPING_ICMP 8
struct ip_ping {
- uint8_t ipver; /* Type and header length*/
- uint8_t tos; /* Type of Service */
- uint16_t length; /* Total length */
- uint16_t fragid; /* Identifier */
- uint16_t offset; /* Flags and fragment offset */
- uint8_t ttl; /* Time to live */
- uint8_t protocol; /* Protocol */
- uint16_t ipcheck; /* Header checksum */
- uint32_t src; /* Source address */
- uint32_t dst; /* Destination */
- uint8_t type; /* Type and header length*/
- uint8_t code; /* Code */
- uint16_t checksum; /* Header checksum */
- uint16_t ident; /* Identifier */
- uint16_t seq; /* Sequence number */
- uint8_t data[CREATEPING_MAX]; /* Data */
-} __attribute__((packed));
+ uint8_t ipver; /* Type and header length */
+ uint8_t tos; /* Type of Service */
+ uint16_t length; /* Total length */
+ uint16_t fragid; /* Identifier */
+ uint16_t offset; /* Flags and fragment offset */
+ uint8_t ttl; /* Time to live */
+ uint8_t protocol; /* Protocol */
+ uint16_t ipcheck; /* Header checksum */
+ uint32_t src; /* Source address */
+ uint32_t dst; /* Destination */
+ uint8_t type; /* Type and header length */
+ uint8_t code; /* Code */
+ uint16_t checksum; /* Header checksum */
+ uint16_t ident; /* Identifier */
+ uint16_t seq; /* Sequence number */
+ uint8_t data[CREATEPING_MAX]; /* Data */
+} __attribute__ ((packed));
/* Statistical values for ping */
int nreceived = 0;
@@ -153,1489 +150,1562 @@ int ntransmitted = 0;
int tmin = 999999999;
int tmax = 0;
int tsum = 0;
-int pingseq = 0; /* Ping sequence counter */
+int pingseq = 0; /* Ping sequence counter */
struct timeval firstping;
-int ipset(struct iphash_t *ipaddr, struct in_addr *addr) {
- int hash = ippool_hash4(addr) % MAXCONTEXTS;
- struct iphash_t *h;
- struct iphash_t *prev = NULL;
- ipaddr->ipnext = NULL;
- ipaddr->addr.s_addr = addr->s_addr;
- for (h = iphash[hash]; h; h = h->ipnext)
- prev = h;
- if (!prev)
- iphash[hash] = ipaddr;
- else
- prev->ipnext = ipaddr;
- return 0;
+int ipset(struct iphash_t *ipaddr, struct in_addr *addr)
+{
+ int hash = ippool_hash4(addr) % MAXCONTEXTS;
+ struct iphash_t *h;
+ struct iphash_t *prev = NULL;
+ ipaddr->ipnext = NULL;
+ ipaddr->addr.s_addr = addr->s_addr;
+ for (h = iphash[hash]; h; h = h->ipnext)
+ prev = h;
+ if (!prev)
+ iphash[hash] = ipaddr;
+ else
+ prev->ipnext = ipaddr;
+ return 0;
}
-int ipdel(struct iphash_t *ipaddr) {
- int hash = ippool_hash4(&ipaddr->addr) % MAXCONTEXTS;
- struct iphash_t *h;
- struct iphash_t *prev = NULL;
- for (h = iphash[hash]; h; h = h->ipnext) {
- if (h == ipaddr) {
- if (!prev)
- iphash[hash] = h->ipnext;
- else
- prev->ipnext = h->ipnext;
- return 0;
- }
- prev = h;
- }
- return EOF; /* End of linked list and not found */
+int ipdel(struct iphash_t *ipaddr)
+{
+ int hash = ippool_hash4(&ipaddr->addr) % MAXCONTEXTS;
+ struct iphash_t *h;
+ struct iphash_t *prev = NULL;
+ for (h = iphash[hash]; h; h = h->ipnext) {
+ if (h == ipaddr) {
+ if (!prev)
+ iphash[hash] = h->ipnext;
+ else
+ prev->ipnext = h->ipnext;
+ return 0;
+ }
+ prev = h;
+ }
+ return EOF; /* End of linked list and not found */
}
-int ipget(struct iphash_t **ipaddr, struct in_addr *addr) {
- int hash = ippool_hash4(addr) % MAXCONTEXTS;
- struct iphash_t *h;
- for (h = iphash[hash]; h; h = h->ipnext) {
- if ((h->addr.s_addr == addr->s_addr)) {
- *ipaddr = h;
- return 0;
- }
- }
- return EOF; /* End of linked list and not found */
+int ipget(struct iphash_t **ipaddr, struct in_addr *addr)
+{
+ int hash = ippool_hash4(addr) % MAXCONTEXTS;
+ struct iphash_t *h;
+ for (h = iphash[hash]; h; h = h->ipnext) {
+ if ((h->addr.s_addr == addr->s_addr)) {
+ *ipaddr = h;
+ return 0;
+ }
+ }
+ return EOF; /* End of linked list and not found */
}
-
/* Used to write process ID to file. Assume someone else will delete */
-void log_pid(char *pidfile) {
- FILE *file;
- mode_t oldmask;
-
- oldmask = umask(022);
- file = fopen(pidfile, "w");
- umask(oldmask);
- if(!file)
- return;
- fprintf(file, "%d\n", (int) getpid());
- fclose(file);
+void log_pid(char *pidfile)
+{
+ FILE *file;
+ mode_t oldmask;
+
+ oldmask = umask(022);
+ file = fopen(pidfile, "w");
+ umask(oldmask);
+ if (!file)
+ return;
+ fprintf(file, "%d\n", (int)getpid());
+ fclose(file);
}
+int process_options(int argc, char **argv)
+{
+ /* gengeopt declarations */
+ struct gengetopt_args_info args_info;
+
+ struct hostent *host;
+ unsigned int n;
+ uint16_t i;
+ uint8_t a;
+ uint8_t b;
+ char *tmp;
+ char *pch;
+ char *type;
+ char *mcc;
+ char *mnc;
+ char *lac;
+ int lac_d;
+ char *rest;
+ char *userloc_el[] = { "TYPE", "MCC", "MNC", "LAC", "REST" };
+ char *rai_el[] = { "MCC", "MNC", "LAC", "RAC" };
+ char *mstz_el[] = { "SIGN", "QUARTERS", "DST" };
+ int sign;
+ int nbquarters;
+ int DST;
+
+ if (cmdline_parser(argc, argv, &args_info) != 0)
+ return -1;
+ if (args_info.debug_flag) {
+ if (args_info.remote_arg)
+ printf("remote: %s\n", args_info.remote_arg);
+ if (args_info.listen_arg)
+ printf("listen: %s\n", args_info.listen_arg);
+ if (args_info.conf_arg)
+ printf("conf: %s\n", args_info.conf_arg);
+ printf("debug: %d\n", args_info.debug_flag);
+ if (args_info.imsi_arg)
+ printf("imsi: %s\n", args_info.imsi_arg);
+ printf("qos: %#08x\n", args_info.qos_arg);
+ printf("qose1: %#0.16llx\n", args_info.qose1_arg);
+ printf("qose2: %#04x\n", args_info.qose2_arg);
+ printf("qose3: %#06x\n", args_info.qose3_arg);
+ printf("qose4: %#06x\n", args_info.qose4_arg);
+ printf("charging: %#04x\n", args_info.charging_arg);
+ if (args_info.apn_arg)
+ printf("apn: %s\n", args_info.apn_arg);
+ if (args_info.msisdn_arg)
+ printf("msisdn: %s\n", args_info.msisdn_arg);
+ if (args_info.uid_arg)
+ printf("uid: %s\n", args_info.uid_arg);
+ if (args_info.pwd_arg)
+ printf("pwd: %s\n", args_info.pwd_arg);
+ if (args_info.pidfile_arg)
+ printf("pidfile: %s\n", args_info.pidfile_arg);
+ if (args_info.statedir_arg)
+ printf("statedir: %s\n", args_info.statedir_arg);
+ if (args_info.dns_arg)
+ printf("dns: %s\n", args_info.dns_arg);
+ printf("contexts: %d\n", args_info.contexts_arg);
+ printf("timelimit: %d\n", args_info.timelimit_arg);
+ printf("createif: %d\n", args_info.createif_flag);
+ if (args_info.ipup_arg)
+ printf("ipup: %s\n", args_info.ipup_arg);
+ if (args_info.ipdown_arg)
+ printf("ipdown: %s\n", args_info.ipdown_arg);
+ printf("defaultroute: %d\n", args_info.defaultroute_flag);
+ if (args_info.pinghost_arg)
+ printf("pinghost: %s\n", args_info.pinghost_arg);
+ printf("pingrate: %d\n", args_info.pingrate_arg);
+ printf("pingsize: %d\n", args_info.pingsize_arg);
+ printf("pingcount: %d\n", args_info.pingcount_arg);
+ printf("pingquiet: %d\n", args_info.pingquiet_flag);
+ printf("norecovery: %d\n", args_info.norecovery_flag);
+ }
+
+ /* Try out our new parser */
+
+ if (args_info.conf_arg) {
+ if (cmdline_parser_configfile
+ (args_info.conf_arg, &args_info, 0, 0, 0) != 0)
+ return -1;
+ if (args_info.debug_flag) {
+ printf("cmdline_parser_configfile\n");
+ if (args_info.remote_arg)
+ printf("remote: %s\n", args_info.remote_arg);
+ if (args_info.listen_arg)
+ printf("listen: %s\n", args_info.listen_arg);
+ if (args_info.conf_arg)
+ printf("conf: %s\n", args_info.conf_arg);
+ printf("debug: %d\n", args_info.debug_flag);
+ if (args_info.imsi_arg)
+ printf("imsi: %s\n", args_info.imsi_arg);
+ printf("qos: %#08x\n", args_info.qos_arg);
+ printf("qose1: %#0.16llx\n", args_info.qose1_arg);
+ printf("qose2: %#04x\n", args_info.qose2_arg);
+ printf("qose3: %#06x\n", args_info.qose3_arg);
+ printf("qose4: %#06x\n", args_info.qose4_arg);
+ printf("charging: %#04x\n", args_info.charging_arg);
+ if (args_info.apn_arg)
+ printf("apn: %s\n", args_info.apn_arg);
+ if (args_info.msisdn_arg)
+ printf("msisdn: %s\n", args_info.msisdn_arg);
+ if (args_info.uid_arg)
+ printf("uid: %s\n", args_info.uid_arg);
+ if (args_info.pwd_arg)
+ printf("pwd: %s\n", args_info.pwd_arg);
+ if (args_info.pidfile_arg)
+ printf("pidfile: %s\n", args_info.pidfile_arg);
+ if (args_info.statedir_arg)
+ printf("statedir: %s\n",
+ args_info.statedir_arg);
+ if (args_info.dns_arg)
+ printf("dns: %s\n", args_info.dns_arg);
+ printf("contexts: %d\n", args_info.contexts_arg);
+ printf("timelimit: %d\n", args_info.timelimit_arg);
+ printf("createif: %d\n", args_info.createif_flag);
+ if (args_info.ipup_arg)
+ printf("ipup: %s\n", args_info.ipup_arg);
+ if (args_info.ipdown_arg)
+ printf("ipdown: %s\n", args_info.ipdown_arg);
+ printf("defaultroute: %d\n",
+ args_info.defaultroute_flag);
+ if (args_info.pinghost_arg)
+ printf("pinghost: %s\n",
+ args_info.pinghost_arg);
+ printf("pingrate: %d\n", args_info.pingrate_arg);
+ printf("pingsize: %d\n", args_info.pingsize_arg);
+ printf("pingcount: %d\n", args_info.pingcount_arg);
+ printf("pingquiet: %d\n", args_info.pingquiet_flag);
+ printf("norecovery: %d\n", args_info.norecovery_flag);
+ }
+ }
+
+ /* Handle each option */
+
+ /* foreground */
+ /* If fg flag not given run as a daemon */
+ /* Do not allow sgsnemu to run as deamon
+ if (!args_info.fg_flag)
+ {
+ closelog();
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+ freopen("/dev/null", "r", stdin);
+ daemon(0, 0);
+ openlog(PACKAGE, LOG_PID, LOG_DAEMON);
+ } */
+
+ /* debug */
+ options.debug = args_info.debug_flag;
+
+ /* pidfile */
+ /* This has to be done after we have our final pid */
+ if (args_info.pidfile_arg) {
+ log_pid(args_info.pidfile_arg);
+ }
+
+ /* dns */
+ /* If no dns option is given use system default */
+ /* Do hostname lookup to translate hostname to IP address */
+ printf("\n");
+ if (args_info.dns_arg) {
+ if (!(host = gethostbyname(args_info.dns_arg))) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Invalid DNS address: %s!", args_info.dns_arg);
+ return -1;
+ } else {
+ memcpy(&options.dns.s_addr, host->h_addr,
+ host->h_length);
+ _res.nscount = 1;
+ _res.nsaddr_list[0].sin_addr = options.dns;
+ printf("Using DNS server: %s (%s)\n",
+ args_info.dns_arg, inet_ntoa(options.dns));
+ }
+ } else {
+ options.dns.s_addr = 0;
+ printf("Using default DNS server\n");
+ }
+
+ /* listen */
+ /* If no listen option is specified listen to any local port */
+ /* Do hostname lookup to translate hostname to IP address */
+ if (args_info.listen_arg) {
+ if (!(host = gethostbyname(args_info.listen_arg))) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Invalid listening address: %s!",
+ args_info.listen_arg);
+ return -1;
+ } else {
+ memcpy(&options.listen.s_addr, host->h_addr,
+ host->h_length);
+ printf("Local IP address is: %s (%s)\n",
+ args_info.listen_arg, inet_ntoa(options.listen));
+ }
+ } else {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Listening address must be specified: %s!",
+ args_info.listen_arg);
+ return -1;
+ }
+
+ /* remote */
+ /* If no remote option is specified terminate */
+ /* Do hostname lookup to translate hostname to IP address */
+ if (args_info.remote_arg) {
+ if (!(host = gethostbyname(args_info.remote_arg))) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Invalid remote address: %s!",
+ args_info.remote_arg);
+ return -1;
+ } else {
+ memcpy(&options.remote.s_addr, host->h_addr,
+ host->h_length);
+ printf("Remote IP address is: %s (%s)\n",
+ args_info.remote_arg, inet_ntoa(options.remote));
+ }
+ } else {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "No remote address given!");
+ return -1;
+ }
+
+ /* imsi */
+ if (strlen(args_info.imsi_arg) != 15) {
+ printf("Invalid IMSI\n");
+ return -1;
+ }
+
+ options.imsi = 0xf000000000000000ull;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[0] - 48));
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[1] - 48)) << 4;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[2] - 48)) << 8;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[3] - 48)) << 12;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[4] - 48)) << 16;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[5] - 48)) << 20;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[6] - 48)) << 24;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[7] - 48)) << 28;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[8] - 48)) << 32;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[9] - 48)) << 36;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[10] - 48)) << 40;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[11] - 48)) << 44;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[12] - 48)) << 48;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[13] - 48)) << 52;
+ options.imsi |= ((uint64_t) (args_info.imsi_arg[14] - 48)) << 56;
+
+ printf("IMSI is: %s (%#08llx)\n",
+ args_info.imsi_arg, options.imsi);
+
+ /* nsapi */
+ if ((args_info.nsapi_arg > 15) || (args_info.nsapi_arg < 0)) {
+ printf("Invalid NSAPI\n");
+ return -1;
+ }
+ options.nsapi = args_info.nsapi_arg;
+ printf("Using NSAPI: %d\n", args_info.nsapi_arg);
+
+ /* qos */
+ options.qos.l = 4;
+ options.qos.v[3] = (args_info.qos_arg) & 0xff;
+ options.qos.v[2] = ((args_info.qos_arg) >> 8) & 0xff;
+ options.qos.v[1] = ((args_info.qos_arg) >> 16) & 0xff;
+ options.qos.v[0] = ((args_info.qos_arg) >> 24) & 0xff;
+ /* Extensions according to 3GPP TS 24.008 */
+ if (args_info.qose1_given == 1) {
+ options.qos.l = 12;
+ options.qos.v[11] = (args_info.qose1_arg) & 0xff;
+ options.qos.v[10] = ((args_info.qose1_arg) >> 8) & 0xff;
+ options.qos.v[9] = ((args_info.qose1_arg) >> 16) & 0xff;
+ options.qos.v[8] = ((args_info.qose1_arg) >> 24) & 0xff;
+ options.qos.v[7] = ((args_info.qose1_arg) >> 32) & 0xff;
+ options.qos.v[6] = ((args_info.qose1_arg) >> 40) & 0xff;
+ options.qos.v[5] = ((args_info.qose1_arg) >> 48) & 0xff;
+ options.qos.v[4] = ((args_info.qose1_arg) >> 56) & 0xff;
+ if (args_info.qose2_given == 1) {
+ options.qos.l = 13;
+ options.qos.v[12] = (args_info.qose2_arg) & 0xff;
+ if (args_info.qose3_given == 1) {
+ options.qos.l = 15;
+ options.qos.v[14] =
+ (args_info.qose3_arg) & 0xff;
+ options.qos.v[13] =
+ ((args_info.qose3_arg) >> 8) & 0xff;
+ if (args_info.qose4_given == 1) {
+ options.qos.l = 17;
+ options.qos.v[16] =
+ (args_info.qose4_arg) & 0xff;
+ options.qos.v[15] =
+ ((args_info.qose4_arg) >> 8) & 0xff;
+ }
+ }
+ }
+ }
+
+ /* charging */
+ options.cch = args_info.charging_arg;
-int process_options(int argc, char **argv) {
- /* gengeopt declarations */
- struct gengetopt_args_info args_info;
-
- struct hostent *host;
- unsigned int n;
- uint16_t i;
- uint8_t a;
- uint8_t b;
- char * tmp;
- char * pch;
- char * type;
- char * mcc;
- char * mnc;
- char * lac;
- int lac_d;
- char * rest;
- char *userloc_el[] = {"TYPE","MCC","MNC","LAC","REST"};
- char *rai_el[] = {"MCC","MNC","LAC","RAC"};
- char *mstz_el[] = {"SIGN","QUARTERS","DST"};
- int sign ;
- int nbquarters ;
- int DST ;
-
-
- if (cmdline_parser (argc, argv, &args_info) != 0)
- return -1;
- if (args_info.debug_flag) {
- if (args_info.remote_arg) printf("remote: %s\n", args_info.remote_arg);
- if (args_info.listen_arg) printf("listen: %s\n", args_info.listen_arg);
- if (args_info.conf_arg) printf("conf: %s\n", args_info.conf_arg);
- printf("debug: %d\n", args_info.debug_flag);
- if (args_info.imsi_arg) printf("imsi: %s\n", args_info.imsi_arg);
- printf("qos: %#08x\n", args_info.qos_arg);
- printf("qose1: %#0.16llx\n", args_info.qose1_arg);
- printf("qose2: %#04x\n", args_info.qose2_arg);
- printf("qose3: %#06x\n", args_info.qose3_arg);
- printf("qose4: %#06x\n", args_info.qose4_arg);
- printf("charging: %#04x\n", args_info.charging_arg);
- if (args_info.apn_arg) printf("apn: %s\n", args_info.apn_arg);
- if (args_info.msisdn_arg) printf("msisdn: %s\n", args_info.msisdn_arg);
- if (args_info.uid_arg) printf("uid: %s\n", args_info.uid_arg);
- if (args_info.pwd_arg) printf("pwd: %s\n", args_info.pwd_arg);
- if (args_info.pidfile_arg) printf("pidfile: %s\n", args_info.pidfile_arg);
- if (args_info.statedir_arg) printf("statedir: %s\n", args_info.statedir_arg);
- if (args_info.dns_arg) printf("dns: %s\n", args_info.dns_arg);
- printf("contexts: %d\n", args_info.contexts_arg);
- printf("timelimit: %d\n", args_info.timelimit_arg);
- printf("createif: %d\n", args_info.createif_flag);
- if (args_info.ipup_arg) printf("ipup: %s\n", args_info.ipup_arg);
- if (args_info.ipdown_arg) printf("ipdown: %s\n", args_info.ipdown_arg);
- printf("defaultroute: %d\n", args_info.defaultroute_flag);
- if (args_info.pinghost_arg) printf("pinghost: %s\n", args_info.pinghost_arg);
- printf("pingrate: %d\n", args_info.pingrate_arg);
- printf("pingsize: %d\n", args_info.pingsize_arg);
- printf("pingcount: %d\n", args_info.pingcount_arg);
- printf("pingquiet: %d\n", args_info.pingquiet_flag);
- printf("norecovery: %d\n", args_info.norecovery_flag);
- }
-
- /* Try out our new parser */
-
- if (args_info.conf_arg) {
- if (cmdline_parser_configfile (args_info.conf_arg, &args_info, 0, 0, 0) != 0)
- return -1;
- if (args_info.debug_flag) {
- printf("cmdline_parser_configfile\n");
- if (args_info.remote_arg) printf("remote: %s\n", args_info.remote_arg);
- if (args_info.listen_arg) printf("listen: %s\n", args_info.listen_arg);
- if (args_info.conf_arg) printf("conf: %s\n", args_info.conf_arg);
- printf("debug: %d\n", args_info.debug_flag);
- if (args_info.imsi_arg) printf("imsi: %s\n", args_info.imsi_arg);
- printf("qos: %#08x\n", args_info.qos_arg);
- printf("qose1: %#0.16llx\n", args_info.qose1_arg);
- printf("qose2: %#04x\n", args_info.qose2_arg);
- printf("qose3: %#06x\n", args_info.qose3_arg);
- printf("qose4: %#06x\n", args_info.qose4_arg);
- printf("charging: %#04x\n", args_info.charging_arg);
- if (args_info.apn_arg) printf("apn: %s\n", args_info.apn_arg);
- if (args_info.msisdn_arg) printf("msisdn: %s\n", args_info.msisdn_arg);
- if (args_info.uid_arg) printf("uid: %s\n", args_info.uid_arg);
- if (args_info.pwd_arg) printf("pwd: %s\n", args_info.pwd_arg);
- if (args_info.pidfile_arg) printf("pidfile: %s\n", args_info.pidfile_arg);
- if (args_info.statedir_arg) printf("statedir: %s\n", args_info.statedir_arg);
- if (args_info.dns_arg) printf("dns: %s\n", args_info.dns_arg);
- printf("contexts: %d\n", args_info.contexts_arg);
- printf("timelimit: %d\n", args_info.timelimit_arg);
- printf("createif: %d\n", args_info.createif_flag);
- if (args_info.ipup_arg) printf("ipup: %s\n", args_info.ipup_arg);
- if (args_info.ipdown_arg) printf("ipdown: %s\n", args_info.ipdown_arg);
- printf("defaultroute: %d\n", args_info.defaultroute_flag);
- if (args_info.pinghost_arg) printf("pinghost: %s\n", args_info.pinghost_arg);
- printf("pingrate: %d\n", args_info.pingrate_arg);
- printf("pingsize: %d\n", args_info.pingsize_arg);
- printf("pingcount: %d\n", args_info.pingcount_arg);
- printf("pingquiet: %d\n", args_info.pingquiet_flag);
- printf("norecovery: %d\n", args_info.norecovery_flag);
- }
- }
-
- /* Handle each option */
-
- /* foreground */
- /* If fg flag not given run as a daemon */
- /* Do not allow sgsnemu to run as deamon
- if (!args_info.fg_flag)
- {
- closelog();
- freopen("/dev/null", "w", stdout);
- freopen("/dev/null", "w", stderr);
- freopen("/dev/null", "r", stdin);
- daemon(0, 0);
- openlog(PACKAGE, LOG_PID, LOG_DAEMON);
- } */
-
- /* debug */
- options.debug = args_info.debug_flag;
-
- /* pidfile */
- /* This has to be done after we have our final pid */
- if (args_info.pidfile_arg) {
- log_pid(args_info.pidfile_arg);
- }
-
- /* dns */
- /* If no dns option is given use system default */
- /* Do hostname lookup to translate hostname to IP address */
- printf("\n");
- if (args_info.dns_arg) {
- if (!(host = gethostbyname(args_info.dns_arg))) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Invalid DNS address: %s!", args_info.dns_arg);
- return -1;
- }
- else {
- memcpy(&options.dns.s_addr, host->h_addr, host->h_length);
- _res.nscount = 1;
- _res.nsaddr_list[0].sin_addr = options.dns;
- printf("Using DNS server: %s (%s)\n",
- args_info.dns_arg, inet_ntoa(options.dns));
- }
- }
- else {
- options.dns.s_addr= 0;
- printf("Using default DNS server\n");
- }
-
- /* listen */
- /* If no listen option is specified listen to any local port */
- /* Do hostname lookup to translate hostname to IP address */
- if (args_info.listen_arg) {
- if (!(host = gethostbyname(args_info.listen_arg))) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Invalid listening address: %s!", args_info.listen_arg);
- return -1;
- }
- else {
- memcpy(&options.listen.s_addr, host->h_addr, host->h_length);
- printf("Local IP address is: %s (%s)\n",
- args_info.listen_arg, inet_ntoa(options.listen));
- }
- }
- else {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Listening address must be specified: %s!", args_info.listen_arg);
- return -1;
- }
-
-
- /* remote */
- /* If no remote option is specified terminate */
- /* Do hostname lookup to translate hostname to IP address */
- if (args_info.remote_arg) {
- if (!(host = gethostbyname(args_info.remote_arg))) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Invalid remote address: %s!", args_info.remote_arg);
- return -1;
- }
- else {
- memcpy(&options.remote.s_addr, host->h_addr, host->h_length);
- printf("Remote IP address is: %s (%s)\n",
- args_info.remote_arg, inet_ntoa(options.remote));
- }
- }
- else {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "No remote address given!");
- return -1;
- }
-
-
- /* imsi */
- if (strlen(args_info.imsi_arg)!=15) {
- printf("Invalid IMSI\n");
- return -1;
- }
-
- options.imsi = 0xf000000000000000ull;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 0]-48));
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 1]-48)) << 4;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 2]-48)) << 8;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 3]-48)) << 12;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 4]-48)) << 16;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 5]-48)) << 20;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 6]-48)) << 24;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 7]-48)) << 28;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 8]-48)) << 32;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[ 9]-48)) << 36;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[10]-48)) << 40;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[11]-48)) << 44;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[12]-48)) << 48;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[13]-48)) << 52;
- options.imsi |= ((uint64_t) (args_info.imsi_arg[14]-48)) << 56;
-
- printf("IMSI is: %s (%#08llx)\n",
- args_info.imsi_arg, options.imsi);
-
-
- /* nsapi */
- if ((args_info.nsapi_arg > 15) ||
- (args_info.nsapi_arg < 0)) {
- printf("Invalid NSAPI\n");
- return -1;
- }
- options.nsapi = args_info.nsapi_arg;
- printf("Using NSAPI: %d\n", args_info.nsapi_arg);
-
-
- /* qos */
- options.qos.l = 4;
- options.qos.v[3] = (args_info.qos_arg) & 0xff;
- options.qos.v[2] = ((args_info.qos_arg) >> 8)& 0xff;
- options.qos.v[1] = ((args_info.qos_arg) >> 16) & 0xff;
- options.qos.v[0] = ((args_info.qos_arg) >> 24) & 0xff;
- /* Extensions according to 3GPP TS 24.008 */
- if (args_info.qose1_given == 1 ) {
- options.qos.l = 12;
- options.qos.v[11] = (args_info.qose1_arg) & 0xff;
- options.qos.v[10] = ((args_info.qose1_arg) >> 8)& 0xff;
- options.qos.v[9] = ((args_info.qose1_arg) >> 16)& 0xff;
- options.qos.v[8] = ((args_info.qose1_arg) >> 24)& 0xff;
- options.qos.v[7] = ((args_info.qose1_arg) >> 32)& 0xff;
- options.qos.v[6] = ((args_info.qose1_arg) >> 40) & 0xff;
- options.qos.v[5] = ((args_info.qose1_arg) >> 48) & 0xff;
- options.qos.v[4] = ((args_info.qose1_arg) >> 56) & 0xff;
- if (args_info.qose2_given == 1 ) {
- options.qos.l = 13;
- options.qos.v[12] = (args_info.qose2_arg) & 0xff;
- if (args_info.qose3_given == 1 ) {
- options.qos.l = 15;
- options.qos.v[14] = (args_info.qose3_arg) & 0xff;
- options.qos.v[13] = ((args_info.qose3_arg) >> 8)& 0xff;
- if (args_info.qose4_given == 1 ) {
- options.qos.l = 17;
- options.qos.v[16] = (args_info.qose4_arg) & 0xff;
- options.qos.v[15] = ((args_info.qose4_arg) >> 8)& 0xff;
+ /* contexts */
+ if (args_info.contexts_arg > MAXCONTEXTS) {
+ printf("Contexts has to be less than %d\n", MAXCONTEXTS);
+ return -1;
}
- }
- }
- }
-
- /* charging */
- options.cch = args_info.charging_arg;
-
- /* contexts */
- if (args_info.contexts_arg > MAXCONTEXTS) {
- printf("Contexts has to be less than %d\n", MAXCONTEXTS);
- return -1;
- }
- options.contexts = args_info.contexts_arg;
-
- /* Timelimit */
- options.timelimit = args_info.timelimit_arg;
-
- /* gtpversion */
- if ((args_info.gtpversion_arg > 1) ||
- (args_info.gtpversion_arg < 0)) {
- printf("Invalid GTP version\n");
- return -1;
- }
- options.gtpversion = args_info.gtpversion_arg;
- printf("Using GTP version: %d\n", args_info.gtpversion_arg);
-
-
- /* apn */
- if (strlen(args_info.apn_arg) > (sizeof(options.apn.v)-1)) {
- printf("Invalid APN\n");
- return -1;
- }
- options.apn.l = strlen(args_info.apn_arg);
- strncpy((char *)options.apn.v, args_info.apn_arg, sizeof(options.apn.v));
- options.apn.v[sizeof(options.apn.v)-1] = 0;
- printf("Using APN: %s\n", args_info.apn_arg);
-
-
- /* selmode */
- options.selmode = args_info.selmode_arg;
- printf("Using selection mode: %d\n", args_info.selmode_arg);
-
- /* rattype */
- if (args_info.rattype_given == 1 ) {
- options.rattype_given = 1 ;
- options.rattype.l = strlen(args_info.rattype_arg) ;
- options.rattype.v[0] = atoi(args_info.rattype_arg) ;
- printf("Using RAT Type: %s\n", args_info.rattype_arg);
- }
-
- /* userloc */
- if (args_info.userloc_given == 1 ) {
- printf("Using User Location Information: %s\n", args_info.userloc_arg);
- tmp = args_info.userloc_arg ;
- n=0;
- pch = strtok (tmp,".");
- while (pch != NULL) {
- userloc_el[n] = pch ;
- pch = strtok (NULL, ".");
- n++;
- }
-
- options.userloc_given = 1 ;
- options.userloc.l = 8 ;
-
- /* 3GPP Geographic Location Type t0 / t1 / t2 */
- type = userloc_el[0];
- printf("->type : %c\n", type[0]);
- if ( (strlen(type)!=1) || (!isdigit(type[0])) ) {
- printf("Invalid type \n");
- return -1;
- }
- /* options.userloc.v[0] = 0x00 */
- options.userloc.v[0] = type[0] - 48;
-
- /* MCC */
- mcc = userloc_el[1] ;
- printf("->mcc : %s\n", mcc);
- if (strlen(mcc)!=3) {
- printf("Invalid MCC lenght\n");
- return -1;
- }
-
- /* MNC */
- mnc = userloc_el[2] ;
- printf("->mnc : %s\n", mnc);
-
- /* octet 5 - MCC Digit 2 - MCC Digit 1 */
- /* options.userloc.v[1] = 0x52 */
- a = (uint8_t) (mcc[0] - 48);
- b = (uint8_t) (mcc[1] - 48);
- options.userloc.v[1] = 16*b+a ;
-
- /* octet 6 - MNC Digit 3 - MCC Digit 3 */
- /* options.userloc.v[2] = 0xf0 */
- a = (uint8_t) (mcc[2] - 48);
-
- if ( (strlen(mnc) > 3) || (strlen(mnc) < 2)) {
- printf("Invalid MNC lenght\n");
- return -1;
- }
- if (strlen(mnc)==2) {
- b = 15 ;
- }
- if (strlen(mnc)==3) {
- b = (uint8_t) (mnc[2] - 48);
- }
- options.userloc.v[2] = 16*b+a ;
-
- /* octet 7 - MNC Digit 2 - MNC Digit 1 */
- /* options.userloc.v[3] = 0x99*/
- a = (uint8_t) (mnc[0]- 48);
- b = (uint8_t) (mnc[1]- 48);
- options.userloc.v[3] = 16*b+a ;
-
- /* LAC */
- lac = userloc_el[3] ;
- /*options.userloc.v[4] = 0x12 ; */
- /*options.userloc.v[5] = 0x10 ; */
- printf("->LAC: %s\n", lac);
- lac_d = atoi(lac);
- if (lac_d>65535 || lac_d<1) {
- printf("Invalid LAC\n");
- return -1;
- }
- i = lac_d >> 8 ;
- options.userloc.v[4] = i; /* octet 8 - LAC */
- options.userloc.v[5] = lac_d; /* octet 9 - LAC */
-
- /* CI/SAC/RAC */
- rest = userloc_el[4] ;
- printf("->CI/SAC/RAC : %s\n", rest);
- lac_d = atoi(rest);
- if (lac_d>65535 || lac_d<1) {
- printf("Invalid CI/SAC/RAC\n");
- return -1;
- }
- /*options.userloc.v[6] = 0x04 ; */
- /*options.userloc.v[7] = 0xb7 ; */
- i = lac_d >> 8 ;
- options.userloc.v[6] = i; /* octet 10 - t0,CI / t1,SAC / t2,RAC */
- options.userloc.v[7] = lac_d; /* octet 11 - t0,CI / t1,SAC / t2,RAC */
- }
-
- /* RAI */
- if (args_info.rai_given == 1 ) {
- printf("Using RAI: %s\n", args_info.rai_arg);
- tmp = args_info.rai_arg ;
- n=0;
- pch = strtok (tmp,".");
- while (pch != NULL) {
- rai_el[n] = pch ;
- pch = strtok (NULL, ".");
- n++;
- }
-
- options.rai_given = 1 ;
- options.rai.l = 6 ;
-
-
- /* MCC */
- mcc = rai_el[0] ;
- printf("->mcc : %s\n", mcc);
- if (strlen(mcc)!=3) {
- printf("Invalid MCC lenght\n");
- return -1;
- }
-
- /* MNC */
- mnc = rai_el[1] ;
- printf("->mnc : %s\n", mnc);
-
- a = (uint8_t) (mcc[0] - 48);
- b = (uint8_t) (mcc[1] - 48);
- options.rai.v[0] = 16*b+a ;
-
- /* octet 3 - MNC Digit 3 - MCC Digit 3 */
- a = (uint8_t) (mcc[2] - 48);
-
- if ( (strlen(mnc) > 3) || (strlen(mnc) < 2)) {
- printf("Invalid MNC lenght\n");
- return -1;
- }
- if (strlen(mnc)==2) {
- b = 15 ;
- }
- if (strlen(mnc)==3) {
- b = (uint8_t) (mnc[2] - 48);
- }
- options.rai.v[1] = 16*b+a ;
-
- /* octet 4 - MNC Digit 2 - MNC Digit 1 */
- a = (uint8_t) (mnc[0]- 48);
- b = (uint8_t) (mnc[1]- 48);
- options.rai.v[2] = 16*b+a ;
-
- /* LAC */
- lac = rai_el[2] ;
- printf("->LAC: %s\n", lac);
- lac_d = atoi(lac);
- if (lac_d>65535 || lac_d<1) {
- printf("Invalid LAC\n");
- return -1;
- }
- i = lac_d >> 8 ;
- options.rai.v[3] = i; /* octet 5 - LAC */
- options.rai.v[4] = lac_d; /* octet 6 - LAC */
-
- /* RAC */
- rest = rai_el[3] ;
- printf("->RAC : %s\n", rest);
- lac_d = atoi(rest);
- if (lac_d>255 || lac_d<1) {
- printf("Invalid RAC\n");
- return -1;
- }
- options.rai.v[5] = lac_d; /* octet 7 - RAC */
- }
-
- /* mstz */
- if (args_info.mstz_given == 1 ) {
- options.mstz_given = 1 ;
- options.mstz.l = 2 ;
-
- printf("Using MS Time Zone: %s\n", args_info.mstz_arg);
- tmp = args_info.mstz_arg ;
- n=0;
- pch = strtok (tmp,".");
- while (pch != NULL) {
- mstz_el[n] = pch ;
- pch = strtok (NULL, ".");
- n++;
- }
-
- /* sign */
- sign = atoi(mstz_el[0]) ;
- printf("->Sign (0=+ / 1=-): %d\n", sign);
- if ( sign!=0 && sign!=1 ) {
- printf("Invalid Sign \n");
- return -1;
- }
- /* nbquarters */
- nbquarters = atoi(mstz_el[1]) ;
- printf("->Number of Quarters of an Hour : %d\n", nbquarters);
- if ( nbquarters<0 || nbquarters>79 ) {
- printf("Invalid Number of Quarters \n");
- return -1;
- }
- /* DST */
- DST = atoi(mstz_el[2]) ;
- printf("->Daylight Saving Time Adjustment : %d\n", DST);
- if ( DST<0 || DST>3 ) {
- printf("Invalid DST Adjustment \n");
- return -1;
- }
- /* 12345678
- bits 123 = unit of # of quarters of an hour
- bits 678 = # of quarters of an hour / 10
- bit 5 = sign
- */
- i= nbquarters % 10 ;
- i = i << 4 ;
- i = i + nbquarters / 10 + 8 * sign;
- /* options.mstz.v[0] = 0x69 ; */
- /* options.mstz.v[1] = 0x01 ; */
- options.mstz.v[0] = i ;
- options.mstz.v[1] = DST ;
- n = (i & 0x08) ? '-' : '+';
- printf("->Human Readable MS Time Zone : GMT %c %d hours %d minutes\n", n , nbquarters / 4, nbquarters % 4 * 15);
- }
-
- /* imeisv */
- if (args_info.imeisv_given == 1 ) {
- options.imeisv_given = 1 ;
- if (strlen(args_info.imeisv_arg)!=16) {
- printf("Invalid IMEI(SV)\n");
- return -1;
- }
- options.imeisv.l = 8 ;
- for(n=0; n<8; n++) {
- a = (uint8_t) (args_info.imeisv_arg [2*n] - 48) ;
- b = (uint8_t) (args_info.imeisv_arg [2*n + 1] - 48) ;
- options.imeisv.v[n] = 16*b+a ;
- }
- printf("Using IMEI(SV): %s\n", args_info.imeisv_arg);
- }
-
- /* msisdn */
- if (strlen(args_info.msisdn_arg)>(sizeof(options.msisdn.v)-1)) {
- printf("Invalid MSISDN\n");
- return -1;
- }
- options.msisdn.l = 1;
- options.msisdn.v[0] = 0x91; /* International format */
- for(n=0; n<strlen(args_info.msisdn_arg); n++) {
- if ((n%2) == 0) {
- options.msisdn.v[((int)n/2)+1] = args_info.msisdn_arg[n] - 48 + 0xf0;
- options.msisdn.l += 1;
- }
- else {
- options.msisdn.v[((int)n/2)+1] =
- (options.msisdn.v[((int)n/2)+1] & 0x0f) +
- (args_info.msisdn_arg[n] - 48) * 16;
- }
- }
- printf("Using MSISDN: %s\n", args_info.msisdn_arg);
-
- /* UID and PWD */
- /* Might need to also insert stuff like DNS etc. */
- if ((strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 10)>
- (sizeof(options.pco.v)-1)) {
- printf("invalid UID and PWD\n");
- return -1;
- }
- options.pco.l = strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 10;
- options.pco.v[0] = 0x80; /* PPP */
- options.pco.v[1] = 0xc0; /* PAP */
- options.pco.v[2] = 0x23;
- options.pco.v[3] = strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 6;
- options.pco.v[4] = 0x01; /* Authenticate request */
- options.pco.v[5] = 0x01;
- options.pco.v[6] = 0x00; /* MSB of length */
- options.pco.v[7] = strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 6;
- options.pco.v[8] = strlen(args_info.uid_arg);
- memcpy(&options.pco.v[9], args_info.uid_arg, strlen(args_info.uid_arg));
- options.pco.v[9+strlen(args_info.uid_arg)] = strlen(args_info.pwd_arg);
- memcpy(&options.pco.v[10+strlen(args_info.uid_arg)],
- args_info.pwd_arg, strlen(args_info.pwd_arg));
-
- /* createif */
- options.createif = args_info.createif_flag;
-
- /* net */
- /* Store net as in_addr net and mask */
- if (args_info.net_arg) {
- if(ippool_aton(&options.net, &options.mask, args_info.net_arg, 0)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Invalid network address: %s!", args_info.net_arg);
- exit(1);
- }
+ options.contexts = args_info.contexts_arg;
+ /* Timelimit */
+ options.timelimit = args_info.timelimit_arg;
+
+ /* gtpversion */
+ if ((args_info.gtpversion_arg > 1) || (args_info.gtpversion_arg < 0)) {
+ printf("Invalid GTP version\n");
+ return -1;
+ }
+ options.gtpversion = args_info.gtpversion_arg;
+ printf("Using GTP version: %d\n", args_info.gtpversion_arg);
+
+ /* apn */
+ if (strlen(args_info.apn_arg) > (sizeof(options.apn.v) - 1)) {
+ printf("Invalid APN\n");
+ return -1;
+ }
+ options.apn.l = strlen(args_info.apn_arg);
+ strncpy((char *)options.apn.v, args_info.apn_arg,
+ sizeof(options.apn.v));
+ options.apn.v[sizeof(options.apn.v) - 1] = 0;
+ printf("Using APN: %s\n", args_info.apn_arg);
+
+ /* selmode */
+ options.selmode = args_info.selmode_arg;
+ printf("Using selection mode: %d\n", args_info.selmode_arg);
+
+ /* rattype */
+ if (args_info.rattype_given == 1) {
+ options.rattype_given = 1;
+ options.rattype.l = strlen(args_info.rattype_arg);
+ options.rattype.v[0] = atoi(args_info.rattype_arg);
+ printf("Using RAT Type: %s\n", args_info.rattype_arg);
+ }
+
+ /* userloc */
+ if (args_info.userloc_given == 1) {
+ printf("Using User Location Information: %s\n",
+ args_info.userloc_arg);
+ tmp = args_info.userloc_arg;
+ n = 0;
+ pch = strtok(tmp, ".");
+ while (pch != NULL) {
+ userloc_el[n] = pch;
+ pch = strtok(NULL, ".");
+ n++;
+ }
+
+ options.userloc_given = 1;
+ options.userloc.l = 8;
+
+ /* 3GPP Geographic Location Type t0 / t1 / t2 */
+ type = userloc_el[0];
+ printf("->type : %c\n", type[0]);
+ if ((strlen(type) != 1) || (!isdigit(type[0]))) {
+ printf("Invalid type \n");
+ return -1;
+ }
+ /* options.userloc.v[0] = 0x00 */
+ options.userloc.v[0] = type[0] - 48;
+
+ /* MCC */
+ mcc = userloc_el[1];
+ printf("->mcc : %s\n", mcc);
+ if (strlen(mcc) != 3) {
+ printf("Invalid MCC lenght\n");
+ return -1;
+ }
+
+ /* MNC */
+ mnc = userloc_el[2];
+ printf("->mnc : %s\n", mnc);
+
+ /* octet 5 - MCC Digit 2 - MCC Digit 1 */
+ /* options.userloc.v[1] = 0x52 */
+ a = (uint8_t) (mcc[0] - 48);
+ b = (uint8_t) (mcc[1] - 48);
+ options.userloc.v[1] = 16 * b + a;
+
+ /* octet 6 - MNC Digit 3 - MCC Digit 3 */
+ /* options.userloc.v[2] = 0xf0 */
+ a = (uint8_t) (mcc[2] - 48);
+
+ if ((strlen(mnc) > 3) || (strlen(mnc) < 2)) {
+ printf("Invalid MNC lenght\n");
+ return -1;
+ }
+ if (strlen(mnc) == 2) {
+ b = 15;
+ }
+ if (strlen(mnc) == 3) {
+ b = (uint8_t) (mnc[2] - 48);
+ }
+ options.userloc.v[2] = 16 * b + a;
+
+ /* octet 7 - MNC Digit 2 - MNC Digit 1 */
+ /* options.userloc.v[3] = 0x99 */
+ a = (uint8_t) (mnc[0] - 48);
+ b = (uint8_t) (mnc[1] - 48);
+ options.userloc.v[3] = 16 * b + a;
+
+ /* LAC */
+ lac = userloc_el[3];
+ /*options.userloc.v[4] = 0x12 ; */
+ /*options.userloc.v[5] = 0x10 ; */
+ printf("->LAC: %s\n", lac);
+ lac_d = atoi(lac);
+ if (lac_d > 65535 || lac_d < 1) {
+ printf("Invalid LAC\n");
+ return -1;
+ }
+ i = lac_d >> 8;
+ options.userloc.v[4] = i; /* octet 8 - LAC */
+ options.userloc.v[5] = lac_d; /* octet 9 - LAC */
+
+ /* CI/SAC/RAC */
+ rest = userloc_el[4];
+ printf("->CI/SAC/RAC : %s\n", rest);
+ lac_d = atoi(rest);
+ if (lac_d > 65535 || lac_d < 1) {
+ printf("Invalid CI/SAC/RAC\n");
+ return -1;
+ }
+ /*options.userloc.v[6] = 0x04 ; */
+ /*options.userloc.v[7] = 0xb7 ; */
+ i = lac_d >> 8;
+ options.userloc.v[6] = i; /* octet 10 - t0,CI / t1,SAC / t2,RAC */
+ options.userloc.v[7] = lac_d; /* octet 11 - t0,CI / t1,SAC / t2,RAC */
+ }
+
+ /* RAI */
+ if (args_info.rai_given == 1) {
+ printf("Using RAI: %s\n", args_info.rai_arg);
+ tmp = args_info.rai_arg;
+ n = 0;
+ pch = strtok(tmp, ".");
+ while (pch != NULL) {
+ rai_el[n] = pch;
+ pch = strtok(NULL, ".");
+ n++;
+ }
+
+ options.rai_given = 1;
+ options.rai.l = 6;
+
+ /* MCC */
+ mcc = rai_el[0];
+ printf("->mcc : %s\n", mcc);
+ if (strlen(mcc) != 3) {
+ printf("Invalid MCC lenght\n");
+ return -1;
+ }
+
+ /* MNC */
+ mnc = rai_el[1];
+ printf("->mnc : %s\n", mnc);
+
+ a = (uint8_t) (mcc[0] - 48);
+ b = (uint8_t) (mcc[1] - 48);
+ options.rai.v[0] = 16 * b + a;
+
+ /* octet 3 - MNC Digit 3 - MCC Digit 3 */
+ a = (uint8_t) (mcc[2] - 48);
+
+ if ((strlen(mnc) > 3) || (strlen(mnc) < 2)) {
+ printf("Invalid MNC lenght\n");
+ return -1;
+ }
+ if (strlen(mnc) == 2) {
+ b = 15;
+ }
+ if (strlen(mnc) == 3) {
+ b = (uint8_t) (mnc[2] - 48);
+ }
+ options.rai.v[1] = 16 * b + a;
+
+ /* octet 4 - MNC Digit 2 - MNC Digit 1 */
+ a = (uint8_t) (mnc[0] - 48);
+ b = (uint8_t) (mnc[1] - 48);
+ options.rai.v[2] = 16 * b + a;
+
+ /* LAC */
+ lac = rai_el[2];
+ printf("->LAC: %s\n", lac);
+ lac_d = atoi(lac);
+ if (lac_d > 65535 || lac_d < 1) {
+ printf("Invalid LAC\n");
+ return -1;
+ }
+ i = lac_d >> 8;
+ options.rai.v[3] = i; /* octet 5 - LAC */
+ options.rai.v[4] = lac_d; /* octet 6 - LAC */
+
+ /* RAC */
+ rest = rai_el[3];
+ printf("->RAC : %s\n", rest);
+ lac_d = atoi(rest);
+ if (lac_d > 255 || lac_d < 1) {
+ printf("Invalid RAC\n");
+ return -1;
+ }
+ options.rai.v[5] = lac_d; /* octet 7 - RAC */
+ }
+
+ /* mstz */
+ if (args_info.mstz_given == 1) {
+ options.mstz_given = 1;
+ options.mstz.l = 2;
+
+ printf("Using MS Time Zone: %s\n", args_info.mstz_arg);
+ tmp = args_info.mstz_arg;
+ n = 0;
+ pch = strtok(tmp, ".");
+ while (pch != NULL) {
+ mstz_el[n] = pch;
+ pch = strtok(NULL, ".");
+ n++;
+ }
+
+ /* sign */
+ sign = atoi(mstz_el[0]);
+ printf("->Sign (0=+ / 1=-): %d\n", sign);
+ if (sign != 0 && sign != 1) {
+ printf("Invalid Sign \n");
+ return -1;
+ }
+ /* nbquarters */
+ nbquarters = atoi(mstz_el[1]);
+ printf("->Number of Quarters of an Hour : %d\n", nbquarters);
+ if (nbquarters < 0 || nbquarters > 79) {
+ printf("Invalid Number of Quarters \n");
+ return -1;
+ }
+ /* DST */
+ DST = atoi(mstz_el[2]);
+ printf("->Daylight Saving Time Adjustment : %d\n", DST);
+ if (DST < 0 || DST > 3) {
+ printf("Invalid DST Adjustment \n");
+ return -1;
+ }
+ /* 12345678
+ bits 123 = unit of # of quarters of an hour
+ bits 678 = # of quarters of an hour / 10
+ bit 5 = sign
+ */
+ i = nbquarters % 10;
+ i = i << 4;
+ i = i + nbquarters / 10 + 8 * sign;
+ /* options.mstz.v[0] = 0x69 ; */
+ /* options.mstz.v[1] = 0x01 ; */
+ options.mstz.v[0] = i;
+ options.mstz.v[1] = DST;
+ n = (i & 0x08) ? '-' : '+';
+ printf
+ ("->Human Readable MS Time Zone : GMT %c %d hours %d minutes\n",
+ n, nbquarters / 4, nbquarters % 4 * 15);
+ }
+
+ /* imeisv */
+ if (args_info.imeisv_given == 1) {
+ options.imeisv_given = 1;
+ if (strlen(args_info.imeisv_arg) != 16) {
+ printf("Invalid IMEI(SV)\n");
+ return -1;
+ }
+ options.imeisv.l = 8;
+ for (n = 0; n < 8; n++) {
+ a = (uint8_t) (args_info.imeisv_arg[2 * n] - 48);
+ b = (uint8_t) (args_info.imeisv_arg[2 * n + 1] - 48);
+ options.imeisv.v[n] = 16 * b + a;
+ }
+ printf("Using IMEI(SV): %s\n", args_info.imeisv_arg);
+ }
+
+ /* msisdn */
+ if (strlen(args_info.msisdn_arg) > (sizeof(options.msisdn.v) - 1)) {
+ printf("Invalid MSISDN\n");
+ return -1;
+ }
+ options.msisdn.l = 1;
+ options.msisdn.v[0] = 0x91; /* International format */
+ for (n = 0; n < strlen(args_info.msisdn_arg); n++) {
+ if ((n % 2) == 0) {
+ options.msisdn.v[((int)n / 2) + 1] =
+ args_info.msisdn_arg[n] - 48 + 0xf0;
+ options.msisdn.l += 1;
+ } else {
+ options.msisdn.v[((int)n / 2) + 1] =
+ (options.msisdn.v[((int)n / 2) + 1] & 0x0f) +
+ (args_info.msisdn_arg[n] - 48) * 16;
+ }
+ }
+ printf("Using MSISDN: %s\n", args_info.msisdn_arg);
+
+ /* UID and PWD */
+ /* Might need to also insert stuff like DNS etc. */
+ if ((strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 10) >
+ (sizeof(options.pco.v) - 1)) {
+ printf("invalid UID and PWD\n");
+ return -1;
+ }
+ options.pco.l =
+ strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 10;
+ options.pco.v[0] = 0x80; /* PPP */
+ options.pco.v[1] = 0xc0; /* PAP */
+ options.pco.v[2] = 0x23;
+ options.pco.v[3] =
+ strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 6;
+ options.pco.v[4] = 0x01; /* Authenticate request */
+ options.pco.v[5] = 0x01;
+ options.pco.v[6] = 0x00; /* MSB of length */
+ options.pco.v[7] =
+ strlen(args_info.uid_arg) + strlen(args_info.pwd_arg) + 6;
+ options.pco.v[8] = strlen(args_info.uid_arg);
+ memcpy(&options.pco.v[9], args_info.uid_arg, strlen(args_info.uid_arg));
+ options.pco.v[9 + strlen(args_info.uid_arg)] =
+ strlen(args_info.pwd_arg);
+ memcpy(&options.pco.v[10 + strlen(args_info.uid_arg)],
+ args_info.pwd_arg, strlen(args_info.pwd_arg));
+
+ /* createif */
+ options.createif = args_info.createif_flag;
+
+ /* net */
+ /* Store net as in_addr net and mask */
+ if (args_info.net_arg) {
+ if (ippool_aton
+ (&options.net, &options.mask, args_info.net_arg, 0)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Invalid network address: %s!",
+ args_info.net_arg);
+ exit(1);
+ }
#if defined (__sun__)
- options.netaddr.s_addr = htonl(ntohl(options.net.s_addr) + 1);
- options.destaddr.s_addr = htonl(ntohl(options.net.s_addr) + 1);
+ options.netaddr.s_addr = htonl(ntohl(options.net.s_addr) + 1);
+ options.destaddr.s_addr = htonl(ntohl(options.net.s_addr) + 1);
#else
- options.netaddr.s_addr = options.net.s_addr;
- options.destaddr.s_addr = options.net.s_addr;
+ options.netaddr.s_addr = options.net.s_addr;
+ options.destaddr.s_addr = options.net.s_addr;
#endif
- }
- else {
- options.net.s_addr = 0;
- options.mask.s_addr = 0;
- options.netaddr.s_addr = 0;
- options.destaddr.s_addr = 0;
- }
-
- /* ipup */
- options.ipup = args_info.ipup_arg;
-
- /* ipdown */
- options.ipdown = args_info.ipdown_arg;
-
- /* statedir */
- options.statedir = args_info.statedir_arg;
-
- /* defaultroute */
- options.defaultroute = args_info.defaultroute_flag;
-
-
- /* pinghost */
- /* Store ping host as in_addr */
- if (args_info.pinghost_arg) {
- if (!(host = gethostbyname(args_info.pinghost_arg))) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Invalid ping host: %s!", args_info.pinghost_arg);
- return -1;
- }
- else {
- memcpy(&options.pinghost.s_addr, host->h_addr, host->h_length);
- printf("Using ping host: %s (%s)\n",
- args_info.pinghost_arg, inet_ntoa(options.pinghost));
- }
- }
-
- /* Other ping parameters */
- options.pingrate = args_info.pingrate_arg;
- options.pingsize = args_info.pingsize_arg;
- options.pingcount = args_info.pingcount_arg;
- options.pingquiet = args_info.pingquiet_flag;
-
- /* norecovery */
- options.norecovery_given = args_info.norecovery_flag;
-
- return 0;
+ } else {
+ options.net.s_addr = 0;
+ options.mask.s_addr = 0;
+ options.netaddr.s_addr = 0;
+ options.destaddr.s_addr = 0;
+ }
-}
+ /* ipup */
+ options.ipup = args_info.ipup_arg;
+
+ /* ipdown */
+ options.ipdown = args_info.ipdown_arg;
+
+ /* statedir */
+ options.statedir = args_info.statedir_arg;
+
+ /* defaultroute */
+ options.defaultroute = args_info.defaultroute_flag;
+
+ /* pinghost */
+ /* Store ping host as in_addr */
+ if (args_info.pinghost_arg) {
+ if (!(host = gethostbyname(args_info.pinghost_arg))) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Invalid ping host: %s!",
+ args_info.pinghost_arg);
+ return -1;
+ } else {
+ memcpy(&options.pinghost.s_addr, host->h_addr,
+ host->h_length);
+ printf("Using ping host: %s (%s)\n",
+ args_info.pinghost_arg,
+ inet_ntoa(options.pinghost));
+ }
+ }
+ /* Other ping parameters */
+ options.pingrate = args_info.pingrate_arg;
+ options.pingsize = args_info.pingsize_arg;
+ options.pingcount = args_info.pingcount_arg;
+ options.pingquiet = args_info.pingquiet_flag;
+
+ /* norecovery */
+ options.norecovery_given = args_info.norecovery_flag;
+
+ return 0;
-int encaps_printf(struct pdp_t *pdp, void *pack, unsigned len) {
- unsigned int i;
- printf("The packet looks like this:\n");
- for( i=0; i<len; i++) {
- printf("%02x ", (unsigned char)*(char *)(pack+i));
- if (!((i+1)%16)) printf("\n");
- };
- printf("\n");
- return 0;
}
-char * print_ipprot(int t) {
- switch (t) {
- case 1: return "ICMP";
- case 6: return "TCP";
- case 17: return "UDP";
- default: return "Unknown";
- };
+int encaps_printf(struct pdp_t *pdp, void *pack, unsigned len)
+{
+ unsigned int i;
+ printf("The packet looks like this:\n");
+ for (i = 0; i < len; i++) {
+ printf("%02x ", (unsigned char)*(char *)(pack + i));
+ if (!((i + 1) % 16))
+ printf("\n");
+ };
+ printf("\n");
+ return 0;
}
+char *print_ipprot(int t)
+{
+ switch (t) {
+ case 1:
+ return "ICMP";
+ case 6:
+ return "TCP";
+ case 17:
+ return "UDP";
+ default:
+ return "Unknown";
+ };
+}
-char * print_icmptype(int t) {
- static char *ttab[] = {
- "Echo Reply",
- "ICMP 1",
- "ICMP 2",
- "Dest Unreachable",
- "Source Quench",
- "Redirect",
- "ICMP 6",
- "ICMP 7",
- "Echo",
- "ICMP 9",
- "ICMP 10",
- "Time Exceeded",
- "Parameter Problem",
- "Timestamp",
- "Timestamp Reply",
- "Info Request",
- "Info Reply"
- };
- if( t < 0 || t > 16 )
- return("OUT-OF-RANGE");
- return(ttab[t]);
+char *print_icmptype(int t)
+{
+ static char *ttab[] = {
+ "Echo Reply",
+ "ICMP 1",
+ "ICMP 2",
+ "Dest Unreachable",
+ "Source Quench",
+ "Redirect",
+ "ICMP 6",
+ "ICMP 7",
+ "Echo",
+ "ICMP 9",
+ "ICMP 10",
+ "Time Exceeded",
+ "Parameter Problem",
+ "Timestamp",
+ "Timestamp Reply",
+ "Info Request",
+ "Info Reply"
+ };
+ if (t < 0 || t > 16)
+ return ("OUT-OF-RANGE");
+ return (ttab[t]);
}
-int msisdn_add(struct ul16_t *src, struct ul16_t *dst, int add) {
- unsigned int n;
- uint64_t i64 = 0;
- uint8_t msa[sizeof(i64) * 3]; /* Allocate 3 digits per octet (0..255) */
- unsigned int msalen = 0;
-
- /* Convert to uint64_t from ul16_t format (most significant digit first) */
- /* ul16_t format always starts with 0x91 to indicate international format */
- /* In ul16_t format 0x0f/0xf0 indicates that digit is not used */
- for (n=0; n< src->l; n++) {
- if ((src->v[n] & 0x0f) != 0x0f) {
- i64 *= 10;
- i64 += src->v[n] & 0x0f;
- }
- if ((src->v[n] & 0xf0) != 0xf0) {
- i64 *= 10;
- i64 += (src->v[n] & 0xf0) >> 4;
- }
- }
-
- i64 += add;
-
- /* Generate array with least significant digit in first octet */
- while (i64) {
- msa[msalen++] = i64 % 10;
- i64 = i64 / 10;
- }
-
- /* Convert back to ul16_t format */
- for(n=0; n<msalen; n++) {
- if ((n%2) == 0) {
- dst->v[((int)n/2)] = msa[msalen-n-1] + 0xf0;
- dst->l += 1;
- }
- else {
- dst->v[((int)n/2)] = (dst->v[((int)n/2)] & 0x0f) +
- msa[msalen-n-1] * 16;
- }
- }
-
- return 0;
+int msisdn_add(struct ul16_t *src, struct ul16_t *dst, int add)
+{
+ unsigned int n;
+ uint64_t i64 = 0;
+ uint8_t msa[sizeof(i64) * 3]; /* Allocate 3 digits per octet (0..255) */
+ unsigned int msalen = 0;
+
+ /* Convert to uint64_t from ul16_t format (most significant digit first) */
+ /* ul16_t format always starts with 0x91 to indicate international format */
+ /* In ul16_t format 0x0f/0xf0 indicates that digit is not used */
+ for (n = 0; n < src->l; n++) {
+ if ((src->v[n] & 0x0f) != 0x0f) {
+ i64 *= 10;
+ i64 += src->v[n] & 0x0f;
+ }
+ if ((src->v[n] & 0xf0) != 0xf0) {
+ i64 *= 10;
+ i64 += (src->v[n] & 0xf0) >> 4;
+ }
+ }
+
+ i64 += add;
+
+ /* Generate array with least significant digit in first octet */
+ while (i64) {
+ msa[msalen++] = i64 % 10;
+ i64 = i64 / 10;
+ }
+
+ /* Convert back to ul16_t format */
+ for (n = 0; n < msalen; n++) {
+ if ((n % 2) == 0) {
+ dst->v[((int)n / 2)] = msa[msalen - n - 1] + 0xf0;
+ dst->l += 1;
+ } else {
+ dst->v[((int)n / 2)] = (dst->v[((int)n / 2)] & 0x0f) +
+ msa[msalen - n - 1] * 16;
+ }
+ }
+
+ return 0;
}
-int imsi_add(uint64_t src, uint64_t *dst, int add) {
- /* TODO: big endian / small endian ??? */
- uint64_t i64 = 0;
-
- /* Convert from uint64_t bcd to uint64_t integer format */
- /* The resulting integer format is multiplied by 10 */
- while (src) {
- if ((src & 0x0f) != 0x0f) {
- i64 *= 10;
- i64 += (src & 0x0f);
- }
- if ((src & 0xf0) != 0xf0) {
- i64 *= 10;
- i64 += (src & 0xf0) >> 4;
- }
- src = src >> 8;
- }
-
- i64 += add * 10;
-
- *dst = 0;
- while (i64) {
- *dst = *dst << 4;
- *dst += (i64 % 10);
- i64 = i64 / 10;
- }
-
- *dst |= 0xf000000000000000ull;
-
- return 0;
+int imsi_add(uint64_t src, uint64_t * dst, int add)
+{
+ /* TODO: big endian / small endian ??? */
+ uint64_t i64 = 0;
+
+ /* Convert from uint64_t bcd to uint64_t integer format */
+ /* The resulting integer format is multiplied by 10 */
+ while (src) {
+ if ((src & 0x0f) != 0x0f) {
+ i64 *= 10;
+ i64 += (src & 0x0f);
+ }
+ if ((src & 0xf0) != 0xf0) {
+ i64 *= 10;
+ i64 += (src & 0xf0) >> 4;
+ }
+ src = src >> 8;
+ }
+
+ i64 += add * 10;
+
+ *dst = 0;
+ while (i64) {
+ *dst = *dst << 4;
+ *dst += (i64 % 10);
+ i64 = i64 / 10;
+ }
+
+ *dst |= 0xf000000000000000ull;
+
+ return 0;
}
/* Calculate time left until we have to send off next ping packet */
-int ping_timeout(struct timeval *tp) {
- struct timezone tz;
- struct timeval tv;
- int diff;
- if ((options.pinghost.s_addr) && (2 == state) &&
- ((pingseq < options.pingcount) || (options.pingcount == 0))) {
- gettimeofday(&tv, &tz);
- diff = 1000000 / options.pingrate * pingseq -
- 1000000 * (tv.tv_sec - firstping.tv_sec) -
- (tv.tv_usec - firstping.tv_usec); /* Microseconds safe up to 500 sec */
- tp->tv_sec = 0;
- if (diff > 0)
- tp->tv_usec = diff;
- else {
- /* For some reason we get packet loss if set to zero */
- tp->tv_usec = 100000 / options.pingrate; /* 10 times pingrate */
- tp->tv_usec = 0;
- }
- }
- return 0;
+int ping_timeout(struct timeval *tp)
+{
+ struct timezone tz;
+ struct timeval tv;
+ int diff;
+ if ((options.pinghost.s_addr) && (2 == state) &&
+ ((pingseq < options.pingcount) || (options.pingcount == 0))) {
+ gettimeofday(&tv, &tz);
+ diff = 1000000 / options.pingrate * pingseq - 1000000 * (tv.tv_sec - firstping.tv_sec) - (tv.tv_usec - firstping.tv_usec); /* Microseconds safe up to 500 sec */
+ tp->tv_sec = 0;
+ if (diff > 0)
+ tp->tv_usec = diff;
+ else {
+ /* For some reason we get packet loss if set to zero */
+ tp->tv_usec = 100000 / options.pingrate; /* 10 times pingrate */
+ tp->tv_usec = 0;
+ }
+ }
+ return 0;
}
/* Print out statistics when at the end of ping sequence */
int ping_finish()
{
- struct timezone tz;
- struct timeval tv;
- int elapsed;
- gettimeofday(&tv, &tz);
- elapsed = 1000000 * (tv.tv_sec - firstping.tv_sec) +
- (tv.tv_usec - firstping.tv_usec); /* Microseconds */
- printf("\n");
- printf("\n----%s PING Statistics----\n", inet_ntoa(options.pinghost));
- printf("%d packets transmitted in %.3f seconds, ", ntransmitted,
- elapsed / 1000000.0);
- printf("%d packets received, ", nreceived );
- if (ntransmitted) {
- if( nreceived > ntransmitted)
- printf("-- somebody's printing up packets!");
- else
- printf("%d%% packet loss",
- (int) (((ntransmitted-nreceived)*100) /
- ntransmitted));
- }
- printf("\n");
- if (options.debug) printf("%d packets received in total\n", ntreceived );
- if (nreceived && tsum)
- printf("round-trip (ms) min/avg/max = %.3f/%.3f/%.3f\n\n",
- tmin/1000.0,
- tsum/1000.0/nreceived,
- tmax/1000.0 );
- printf("%d packets transmitted \n", ntreceived );
-
- ntransmitted = 0;
- return 0;
+ struct timezone tz;
+ struct timeval tv;
+ int elapsed;
+ gettimeofday(&tv, &tz);
+ elapsed = 1000000 * (tv.tv_sec - firstping.tv_sec) + (tv.tv_usec - firstping.tv_usec); /* Microseconds */
+ printf("\n");
+ printf("\n----%s PING Statistics----\n", inet_ntoa(options.pinghost));
+ printf("%d packets transmitted in %.3f seconds, ", ntransmitted,
+ elapsed / 1000000.0);
+ printf("%d packets received, ", nreceived);
+ if (ntransmitted) {
+ if (nreceived > ntransmitted)
+ printf("-- somebody's printing up packets!");
+ else
+ printf("%d%% packet loss",
+ (int)(((ntransmitted - nreceived) * 100) /
+ ntransmitted));
+ }
+ printf("\n");
+ if (options.debug)
+ printf("%d packets received in total\n", ntreceived);
+ if (nreceived && tsum)
+ printf("round-trip (ms) min/avg/max = %.3f/%.3f/%.3f\n\n",
+ tmin / 1000.0, tsum / 1000.0 / nreceived, tmax / 1000.0);
+ printf("%d packets transmitted \n", ntreceived);
+
+ ntransmitted = 0;
+ return 0;
}
/* Handle a received ping packet. Print out line and update statistics. */
-int encaps_ping(struct pdp_t *pdp, void *pack, unsigned len) {
- struct timezone tz;
- struct timeval tv;
- struct timeval *tp;
- struct ip_ping *pingpack = pack;
- struct in_addr src;
- int triptime;
-
- src.s_addr = pingpack->src;
-
- gettimeofday(&tv, &tz);
- if (options.debug) printf("%d.%6d ", (int) tv.tv_sec, (int) tv.tv_usec);
-
- if (len < CREATEPING_IP + CREATEPING_ICMP) {
- printf("packet too short (%d bytes) from %s\n", len,
- inet_ntoa(src));
- return 0;
- }
-
- ntreceived++;
- if (pingpack->protocol != 1) {
- if (!options.pingquiet) printf("%d bytes from %s: ip_protocol=%d (%s)\n",
- len, inet_ntoa(src), pingpack->protocol,
- print_ipprot(pingpack->protocol));
- return 0;
- }
-
- if (pingpack->type != 0) {
- if (!options.pingquiet) printf("%d bytes from %s: icmp_type=%d (%s) icmp_code=%d\n",
- len, inet_ntoa(src), pingpack->type,
- print_icmptype(pingpack->type), pingpack->code);
- return 0;
- }
-
- nreceived++;
- if (!options.pingquiet) printf("%d bytes from %s: icmp_seq=%d", len,
- inet_ntoa(src), ntohs(pingpack->seq));
-
- if (len >= sizeof(struct timeval) + CREATEPING_IP + CREATEPING_ICMP) {
- gettimeofday(&tv, &tz);
- tp = (struct timeval *) pingpack->data;
- if( (tv.tv_usec -= tp->tv_usec) < 0 ) {
- tv.tv_sec--;
- tv.tv_usec += 1000000;
- }
- tv.tv_sec -= tp->tv_sec;
-
- triptime = tv.tv_sec*1000000+(tv.tv_usec);
- tsum += triptime;
- if( triptime < tmin )
- tmin = triptime;
- if( triptime > tmax )
- tmax = triptime;
-
- if (!options.pingquiet) printf(" time=%.3f ms\n", triptime/1000.0);
-
- }
- else
- if (!options.pingquiet) printf("\n");
- return 0;
+int encaps_ping(struct pdp_t *pdp, void *pack, unsigned len)
+{
+ struct timezone tz;
+ struct timeval tv;
+ struct timeval *tp;
+ struct ip_ping *pingpack = pack;
+ struct in_addr src;
+ int triptime;
+
+ src.s_addr = pingpack->src;
+
+ gettimeofday(&tv, &tz);
+ if (options.debug)
+ printf("%d.%6d ", (int)tv.tv_sec, (int)tv.tv_usec);
+
+ if (len < CREATEPING_IP + CREATEPING_ICMP) {
+ printf("packet too short (%d bytes) from %s\n", len,
+ inet_ntoa(src));
+ return 0;
+ }
+
+ ntreceived++;
+ if (pingpack->protocol != 1) {
+ if (!options.pingquiet)
+ printf("%d bytes from %s: ip_protocol=%d (%s)\n",
+ len, inet_ntoa(src), pingpack->protocol,
+ print_ipprot(pingpack->protocol));
+ return 0;
+ }
+
+ if (pingpack->type != 0) {
+ if (!options.pingquiet)
+ printf
+ ("%d bytes from %s: icmp_type=%d (%s) icmp_code=%d\n",
+ len, inet_ntoa(src), pingpack->type,
+ print_icmptype(pingpack->type), pingpack->code);
+ return 0;
+ }
+
+ nreceived++;
+ if (!options.pingquiet)
+ printf("%d bytes from %s: icmp_seq=%d", len,
+ inet_ntoa(src), ntohs(pingpack->seq));
+
+ if (len >= sizeof(struct timeval) + CREATEPING_IP + CREATEPING_ICMP) {
+ gettimeofday(&tv, &tz);
+ tp = (struct timeval *)pingpack->data;
+ if ((tv.tv_usec -= tp->tv_usec) < 0) {
+ tv.tv_sec--;
+ tv.tv_usec += 1000000;
+ }
+ tv.tv_sec -= tp->tv_sec;
+
+ triptime = tv.tv_sec * 1000000 + (tv.tv_usec);
+ tsum += triptime;
+ if (triptime < tmin)
+ tmin = triptime;
+ if (triptime > tmax)
+ tmax = triptime;
+
+ if (!options.pingquiet)
+ printf(" time=%.3f ms\n", triptime / 1000.0);
+
+ } else if (!options.pingquiet)
+ printf("\n");
+ return 0;
}
/* Create a new ping packet and send it off to peer. */
int create_ping(void *gsn, struct pdp_t *pdp,
- struct in_addr *dst, int seq, unsigned int datasize) {
-
- struct ip_ping pack;
- uint16_t *p = (uint16_t *) &pack;
- uint8_t *p8 = (uint8_t *) &pack;
- struct in_addr src;
- unsigned int n;
- long int sum = 0;
- int count = 0;
-
- struct timezone tz;
- struct timeval *tp = (struct timeval *) &p8[CREATEPING_IP + CREATEPING_ICMP];
-
- if (datasize > CREATEPING_MAX) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Ping size to large: %d!", datasize);
- return -1;
- }
-
- memcpy(&src, &(pdp->eua.v[2]), 4); /* Copy a 4 byte address */
-
- pack.ipver = 0x45;
- pack.tos = 0x00;
- pack.length = htons(CREATEPING_IP + CREATEPING_ICMP + datasize);
- pack.fragid = 0x0000;
- pack.offset = 0x0040;
- pack.ttl = 0x40;
- pack.protocol = 0x01;
- pack.ipcheck = 0x0000;
- pack.src = src.s_addr;
- pack.dst = dst->s_addr;
- pack.type = 0x08;
- pack.code = 0x00;
- pack.checksum = 0x0000;
- pack.ident = 0x0000;
- pack.seq = htons(seq);
-
- /* Generate ICMP payload */
- p8 = (uint8_t *) &pack + CREATEPING_IP + CREATEPING_ICMP;
- for (n=0; n<(datasize); n++) p8[n] = n;
-
- if (datasize >= sizeof(struct timeval))
- gettimeofday(tp, &tz);
-
- /* Calculate IP header checksum */
- p = (uint16_t *) &pack;
- count = CREATEPING_IP;
- sum = 0;
- while (count>1) {
- sum += *p++;
- count -= 2;
- }
- while (sum>>16)
- sum = (sum & 0xffff) + (sum >> 16);
- pack.ipcheck = ~sum;
-
-
- /* Calculate ICMP checksum */
- count = CREATEPING_ICMP + datasize; /* Length of ICMP message */
- sum = 0;
- p = (uint16_t *) &pack;
- p += CREATEPING_IP / 2;
- while (count>1) {
- sum += *p++;
- count -= 2;
- }
- if (count>0)
- sum += * (unsigned char *) p;
- while (sum>>16)
- sum = (sum & 0xffff) + (sum >> 16);
- pack.checksum = ~sum;
-
- ntransmitted++;
- return gtp_data_req(gsn, pdp, &pack, 28 + datasize);
+ struct in_addr *dst, int seq, unsigned int datasize)
+{
+
+ struct ip_ping pack;
+ uint16_t *p = (uint16_t *) & pack;
+ uint8_t *p8 = (uint8_t *) & pack;
+ struct in_addr src;
+ unsigned int n;
+ long int sum = 0;
+ int count = 0;
+
+ struct timezone tz;
+ struct timeval *tp =
+ (struct timeval *)&p8[CREATEPING_IP + CREATEPING_ICMP];
+
+ if (datasize > CREATEPING_MAX) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Ping size to large: %d!", datasize);
+ return -1;
+ }
+
+ memcpy(&src, &(pdp->eua.v[2]), 4); /* Copy a 4 byte address */
+
+ pack.ipver = 0x45;
+ pack.tos = 0x00;
+ pack.length = htons(CREATEPING_IP + CREATEPING_ICMP + datasize);
+ pack.fragid = 0x0000;
+ pack.offset = 0x0040;
+ pack.ttl = 0x40;
+ pack.protocol = 0x01;
+ pack.ipcheck = 0x0000;
+ pack.src = src.s_addr;
+ pack.dst = dst->s_addr;
+ pack.type = 0x08;
+ pack.code = 0x00;
+ pack.checksum = 0x0000;
+ pack.ident = 0x0000;
+ pack.seq = htons(seq);
+
+ /* Generate ICMP payload */
+ p8 = (uint8_t *) & pack + CREATEPING_IP + CREATEPING_ICMP;
+ for (n = 0; n < (datasize); n++)
+ p8[n] = n;
+
+ if (datasize >= sizeof(struct timeval))
+ gettimeofday(tp, &tz);
+
+ /* Calculate IP header checksum */
+ p = (uint16_t *) & pack;
+ count = CREATEPING_IP;
+ sum = 0;
+ while (count > 1) {
+ sum += *p++;
+ count -= 2;
+ }
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ pack.ipcheck = ~sum;
+
+ /* Calculate ICMP checksum */
+ count = CREATEPING_ICMP + datasize; /* Length of ICMP message */
+ sum = 0;
+ p = (uint16_t *) & pack;
+ p += CREATEPING_IP / 2;
+ while (count > 1) {
+ sum += *p++;
+ count -= 2;
+ }
+ if (count > 0)
+ sum += *(unsigned char *)p;
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ pack.checksum = ~sum;
+
+ ntransmitted++;
+ return gtp_data_req(gsn, pdp, &pack, 28 + datasize);
}
-
-int delete_context(struct pdp_t *pdp) {
+int delete_context(struct pdp_t *pdp)
+{
- if (tun && options.ipdown) tun_runscript(tun, options.ipdown);
+ if (tun && options.ipdown)
+ tun_runscript(tun, options.ipdown);
- ipdel((struct iphash_t*) pdp->peer);
- memset(pdp->peer, 0, sizeof(struct iphash_t)); /* To be sure */
+ ipdel((struct iphash_t *)pdp->peer);
+ memset(pdp->peer, 0, sizeof(struct iphash_t)); /* To be sure */
- if (1 == options.contexts)
- state = 5; /* Disconnected */
+ if (1 == options.contexts)
+ state = 5; /* Disconnected */
- return 0;
+ return 0;
}
-
/* Callback for receiving messages from tun */
-int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len) {
- struct iphash_t *ipm;
- struct in_addr src;
- struct tun_packet_t *iph = (struct tun_packet_t*) pack;
-
- src.s_addr = iph->src;
-
- if (ipget(&ipm, &src)) {
- printf("Received packet without a valid source address!!!\n");
- return 0;
- }
-
- if (ipm->pdp) /* Check if a peer protocol is defined */
- gtp_data_req(gsn, ipm->pdp, pack, len);
- return 0;
+int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len)
+{
+ struct iphash_t *ipm;
+ struct in_addr src;
+ struct tun_packet_t *iph = (struct tun_packet_t *)pack;
+
+ src.s_addr = iph->src;
+
+ if (ipget(&ipm, &src)) {
+ printf("Received packet without a valid source address!!!\n");
+ return 0;
+ }
+
+ if (ipm->pdp) /* Check if a peer protocol is defined */
+ gtp_data_req(gsn, ipm->pdp, pack, len);
+ return 0;
}
-int create_pdp_conf(struct pdp_t *pdp, void *cbp, int cause) {
- struct in_addr addr;
-
- struct iphash_t *iph = (struct iphash_t*) cbp;
-
- if (cause < 0) {
- printf("Create PDP Context Request timed out\n");
- if (iph->pdp->version == 1) {
- printf("Retrying with version 0\n");
- iph->pdp->version = 0;
- gtp_create_context_req(gsn, iph->pdp, iph);
- return 0;
- }
- else {
- state = 0;
- pdp_freepdp(iph->pdp);
- iph->pdp = NULL;
- return EOF;
- }
- }
-
- if (cause != 128) {
- printf("Received create PDP context response. Cause value: %d\n", cause);
- state = 0;
- pdp_freepdp(iph->pdp);
- iph->pdp = NULL;
- return EOF; /* Not what we expected */
- }
-
- if (pdp_euaton(&pdp->eua, &addr)) {
- printf("Received create PDP context response. Cause value: %d\n", cause);
- pdp_freepdp(iph->pdp);
- iph->pdp = NULL;
- state = 0;
- return EOF; /* Not a valid IP address */
- }
-
- printf("Received create PDP context response. IP address: %s\n",
- inet_ntoa(addr));
-
- if ((options.createif) && (!options.net.s_addr)) {
- struct in_addr m;
+int create_pdp_conf(struct pdp_t *pdp, void *cbp, int cause)
+{
+ struct in_addr addr;
+
+ struct iphash_t *iph = (struct iphash_t *)cbp;
+
+ if (cause < 0) {
+ printf("Create PDP Context Request timed out\n");
+ if (iph->pdp->version == 1) {
+ printf("Retrying with version 0\n");
+ iph->pdp->version = 0;
+ gtp_create_context_req(gsn, iph->pdp, iph);
+ return 0;
+ } else {
+ state = 0;
+ pdp_freepdp(iph->pdp);
+ iph->pdp = NULL;
+ return EOF;
+ }
+ }
+
+ if (cause != 128) {
+ printf
+ ("Received create PDP context response. Cause value: %d\n",
+ cause);
+ state = 0;
+ pdp_freepdp(iph->pdp);
+ iph->pdp = NULL;
+ return EOF; /* Not what we expected */
+ }
+
+ if (pdp_euaton(&pdp->eua, &addr)) {
+ printf
+ ("Received create PDP context response. Cause value: %d\n",
+ cause);
+ pdp_freepdp(iph->pdp);
+ iph->pdp = NULL;
+ state = 0;
+ return EOF; /* Not a valid IP address */
+ }
+
+ printf("Received create PDP context response. IP address: %s\n",
+ inet_ntoa(addr));
+
+ if ((options.createif) && (!options.net.s_addr)) {
+ struct in_addr m;
#ifdef HAVE_INET_ATON
- inet_aton("255.255.255.255", &m);
+ inet_aton("255.255.255.255", &m);
#else
- m.s_addr = -1;
+ m.s_addr = -1;
#endif
- /* printf("Setting up interface and routing\n");*/
- tun_addaddr(tun, &addr, &addr, &m);
- if (options.defaultroute) {
- struct in_addr rm;
- rm.s_addr = 0;
- tun_addroute(tun, &rm, &addr, &rm);
- }
- if (options.ipup) tun_runscript(tun, options.ipup);
- }
-
- ipset((struct iphash_t*) pdp->peer, &addr);
-
- state = 2; /* Connected */
-
- return 0;
-}
+ /* printf("Setting up interface and routing\n"); */
+ tun_addaddr(tun, &addr, &addr, &m);
+ if (options.defaultroute) {
+ struct in_addr rm;
+ rm.s_addr = 0;
+ tun_addroute(tun, &rm, &addr, &rm);
+ }
+ if (options.ipup)
+ tun_runscript(tun, options.ipup);
+ }
-int delete_pdp_conf(struct pdp_t *pdp, int cause) {
- printf("Received delete PDP context response. Cause value: %d\n", cause);
- return 0;
+ ipset((struct iphash_t *)pdp->peer, &addr);
+
+ state = 2; /* Connected */
+
+ return 0;
}
-int echo_conf(int recovery) {
-
- if (recovery < 0) {
- printf("Echo Request timed out\n");
- if (echoversion == 1) {
- printf("Retrying with version 0\n");
- echoversion = 0;
- gtp_echo_req(gsn, echoversion, NULL, &options.remote);
- return 0;
- }
- else {
- state = 0;
- return EOF;
- }
- }
- else {
- printf("Received echo response\n");
- if (!options.contexts) state = 5;
- }
- return 0;
+int delete_pdp_conf(struct pdp_t *pdp, int cause)
+{
+ printf("Received delete PDP context response. Cause value: %d\n",
+ cause);
+ return 0;
}
-int conf(int type, int cause, struct pdp_t* pdp, void *cbp) {
- /* if (cause < 0) return 0; Some error occurred. We don't care */
- switch (type) {
- case GTP_ECHO_REQ:
- return echo_conf(cause);
- case GTP_CREATE_PDP_REQ:
- return create_pdp_conf(pdp, cbp, cause);
- case GTP_DELETE_PDP_REQ:
- if (cause !=128) return 0; /* Request not accepted. We don't care */
- return delete_pdp_conf(pdp, cause);
- default:
- return 0;
- }
+int echo_conf(int recovery)
+{
+
+ if (recovery < 0) {
+ printf("Echo Request timed out\n");
+ if (echoversion == 1) {
+ printf("Retrying with version 0\n");
+ echoversion = 0;
+ gtp_echo_req(gsn, echoversion, NULL, &options.remote);
+ return 0;
+ } else {
+ state = 0;
+ return EOF;
+ }
+ } else {
+ printf("Received echo response\n");
+ if (!options.contexts)
+ state = 5;
+ }
+ return 0;
}
+int conf(int type, int cause, struct pdp_t *pdp, void *cbp)
+{
+ /* if (cause < 0) return 0; Some error occurred. We don't care */
+ switch (type) {
+ case GTP_ECHO_REQ:
+ return echo_conf(cause);
+ case GTP_CREATE_PDP_REQ:
+ return create_pdp_conf(pdp, cbp, cause);
+ case GTP_DELETE_PDP_REQ:
+ if (cause != 128)
+ return 0; /* Request not accepted. We don't care */
+ return delete_pdp_conf(pdp, cause);
+ default:
+ return 0;
+ }
+}
-int encaps_tun(struct pdp_t *pdp, void *pack, unsigned len) {
- /* printf("encaps_tun. Packet received: forwarding to tun\n");*/
- return tun_encaps((struct tun_t*) pdp->ipif, pack, len);
+int encaps_tun(struct pdp_t *pdp, void *pack, unsigned len)
+{
+ /* printf("encaps_tun. Packet received: forwarding to tun\n"); */
+ return tun_encaps((struct tun_t *)pdp->ipif, pack, len);
}
int main(int argc, char **argv)
{
- fd_set fds; /* For select() */
- struct timeval idleTime; /* How long to select() */
- struct pdp_t *pdp;
- int n;
- int starttime = time(NULL); /* Time program was started */
- int stoptime = 0; /* Time to exit */
- int pingtimeout = 0; /* Time to print ping statistics */
-
- struct timezone tz; /* Used for calculating ping times */
- struct timeval tv;
- int diff;
-
- /* open a connection to the syslog daemon */
- /*openlog(PACKAGE, LOG_PID, LOG_DAEMON);*/
- /* TODO: Only use LOG__PERROR for linux */
+ fd_set fds; /* For select() */
+ struct timeval idleTime; /* How long to select() */
+ struct pdp_t *pdp;
+ int n;
+ int starttime = time(NULL); /* Time program was started */
+ int stoptime = 0; /* Time to exit */
+ int pingtimeout = 0; /* Time to print ping statistics */
+
+ struct timezone tz; /* Used for calculating ping times */
+ struct timeval tv;
+ int diff;
+
+ /* open a connection to the syslog daemon */
+ /*openlog(PACKAGE, LOG_PID, LOG_DAEMON); */
+ /* TODO: Only use LOG__PERROR for linux */
#ifdef __linux__
- openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON);
+ openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON);
#else
- openlog(PACKAGE, (LOG_PID), LOG_DAEMON);
+ openlog(PACKAGE, (LOG_PID), LOG_DAEMON);
#endif
+ /* Process options given in configuration file and command line */
+ if (process_options(argc, argv))
+ exit(1);
+
+ printf("\nInitialising GTP library\n");
+ if (gtp_new(&gsn, options.statedir, &options.listen, GTP_MODE_SGSN)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0, "Failed to create gtp");
+ exit(1);
+ }
+ if (gsn->fd0 > maxfd)
+ maxfd = gsn->fd0;
+ if (gsn->fd1c > maxfd)
+ maxfd = gsn->fd1c;
+ if (gsn->fd1u > maxfd)
+ maxfd = gsn->fd1u;
+
+ gtp_set_cb_delete_context(gsn, delete_context);
+ gtp_set_cb_conf(gsn, conf);
+ if (options.createif)
+ gtp_set_cb_data_ind(gsn, encaps_tun);
+ else
+ gtp_set_cb_data_ind(gsn, encaps_ping);
+
+ if (options.createif) {
+ printf("Setting up interface\n");
+ /* Create a tunnel interface */
+ if (tun_new((struct tun_t **)&tun)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Failed to create tun");
+ exit(1);
+ }
+ tun_set_cb_ind(tun, cb_tun_ind);
+ if (tun->fd > maxfd)
+ maxfd = tun->fd;
+ }
+
+ if ((options.createif) && (options.net.s_addr)) {
+ /* printf("Setting up interface and routing\n"); */
+ tun_addaddr(tun, &options.netaddr, &options.destaddr,
+ &options.mask);
+ if (options.defaultroute) {
+ struct in_addr rm;
+ rm.s_addr = 0;
+ tun_addroute(tun, &rm, &options.destaddr, &rm);
+ }
+ if (options.ipup)
+ tun_runscript(tun, options.ipup);
+ }
- /* Process options given in configuration file and command line */
- if (process_options(argc, argv))
- exit(1);
-
- printf("\nInitialising GTP library\n");
- if (gtp_new(&gsn, options.statedir, &options.listen, GTP_MODE_SGSN)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Failed to create gtp");
- exit(1);
- }
- if (gsn->fd0 > maxfd) maxfd = gsn->fd0;
- if (gsn->fd1c > maxfd) maxfd = gsn->fd1c;
- if (gsn->fd1u > maxfd) maxfd = gsn->fd1u;
-
- gtp_set_cb_delete_context(gsn, delete_context);
- gtp_set_cb_conf(gsn, conf);
- if (options.createif)
- gtp_set_cb_data_ind(gsn, encaps_tun);
- else
- gtp_set_cb_data_ind(gsn, encaps_ping);
-
- if (options.createif) {
- printf("Setting up interface\n");
- /* Create a tunnel interface */
- if (tun_new((struct tun_t**) &tun)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Failed to create tun");
- exit(1);
- }
- tun_set_cb_ind(tun, cb_tun_ind);
- if (tun->fd > maxfd) maxfd = tun->fd;
- }
-
- if ((options.createif) && (options.net.s_addr)) {
- /* printf("Setting up interface and routing\n");*/
- tun_addaddr(tun, &options.netaddr, &options.destaddr, &options.mask);
- if (options.defaultroute) {
- struct in_addr rm;
- rm.s_addr = 0;
- tun_addroute(tun, &rm, &options.destaddr, &rm);
- }
- if (options.ipup) tun_runscript(tun, options.ipup);
- }
-
-
- /* Initialise hash tables */
- memset(&iphash, 0, sizeof(iphash));
- memset(&iparr, 0, sizeof(iparr));
-
- printf("Done initialising GTP library\n\n");
-
- /* See if anybody is there */
- printf("Sending off echo request\n");
- echoversion = options.gtpversion;
- gtp_echo_req(gsn, echoversion, NULL, &options.remote); /* Is remote alive? */
-
- for(n=0; n<options.contexts; n++) {
- uint64_t myimsi;
- printf("Setting up PDP context #%d\n", n);
- iparr[n].inuse = 1; /* TODO */
-
- imsi_add(options.imsi, &myimsi, n);
-
- /* Allocated here. */
- /* If create context failes we have to deallocate ourselves. */
- /* Otherwise it is deallocated by gtplib */
- pdp_newpdp(&pdp, myimsi, options.nsapi, NULL);
-
- pdp->peer = &iparr[n];
- pdp->ipif = tun; /* TODO */
- iparr[n].pdp = pdp;
-
- if (options.gtpversion == 0) {
- if (options.qos.l - 1 > sizeof(pdp->qos_req0)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0, "QoS length too big");
- exit(1);
- }
- else {
- memcpy(pdp->qos_req0, options.qos.v, options.qos.l);
- }
- }
-
- pdp->qos_req.l = options.qos.l ;
- memcpy(pdp->qos_req.v, options.qos.v, options.qos.l);
-
- pdp->selmode = options.selmode;
-
- pdp->rattype.l = options.rattype.l;
- memcpy(pdp->rattype.v, options.rattype.v, options.rattype.l);
- pdp->rattype_given = options.rattype_given;
-
- pdp->userloc.l = options.userloc.l;
- memcpy(pdp->userloc.v, options.userloc.v, options.userloc.l);
- pdp->userloc_given = options.userloc_given;
-
- pdp->rai.l = options.rai.l;
- memcpy(pdp->rai.v, options.rai.v, options.rai.l);
- pdp->rai_given = options.rai_given;
-
- pdp->mstz.l = options.mstz.l;
- memcpy(pdp->mstz.v, options.mstz.v, options.mstz.l);
- pdp->mstz_given = options.mstz_given;
-
- pdp->imeisv.l = options.imeisv.l;
- memcpy(pdp->imeisv.v, options.imeisv.v, options.imeisv.l);
- pdp->imeisv_given = options.imeisv_given;
-
- pdp->norecovery_given = options.norecovery_given;
-
- if (options.apn.l > sizeof(pdp->apn_use.v)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0, "APN length too big");
- exit(1);
- }
- else {
- pdp->apn_use.l = options.apn.l;
- memcpy(pdp->apn_use.v, options.apn.v, options.apn.l);
- }
-
- pdp->gsnlc.l = sizeof(options.listen);
- memcpy(pdp->gsnlc.v, &options.listen, sizeof(options.listen));
- pdp->gsnlu.l = sizeof(options.listen);
- memcpy(pdp->gsnlu.v, &options.listen, sizeof(options.listen));
-
- if (options.msisdn.l > sizeof(pdp->msisdn.v)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0, "MSISDN length too big");
- exit(1);
- }
- else {
- msisdn_add(&options.msisdn, &pdp->msisdn, n);
- }
-
- ipv42eua(&pdp->eua, NULL); /* Request dynamic IP address */
-
- if (options.pco.l > sizeof(pdp->pco_req.v)) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0, "PCO length too big");
- exit(1);
- }
- else {
- pdp->pco_req.l = options.pco.l;
- memcpy(pdp->pco_req.v, options.pco.v, options.pco.l);
- }
-
- pdp->version = options.gtpversion;
-
- pdp->hisaddr0 = options.remote;
- pdp->hisaddr1 = options.remote;
-
- pdp->cch_pdp = options.cch; /* 2048 = Normal, 1024 = Prepaid,
- 512 = Flat rate, 256 = Hot billing */
-
- /* Create context */
- /* We send this of once. Retransmissions are handled by gtplib */
- gtp_create_context_req(gsn, pdp, &iparr[n]);
- }
-
- state = 1; /* Enter wait_connection state */
-
- printf("Waiting for response from ggsn........\n\n");
+ /* Initialise hash tables */
+ memset(&iphash, 0, sizeof(iphash));
+ memset(&iparr, 0, sizeof(iparr));
+
+ printf("Done initialising GTP library\n\n");
+
+ /* See if anybody is there */
+ printf("Sending off echo request\n");
+ echoversion = options.gtpversion;
+ gtp_echo_req(gsn, echoversion, NULL, &options.remote); /* Is remote alive? */
+
+ for (n = 0; n < options.contexts; n++) {
+ uint64_t myimsi;
+ printf("Setting up PDP context #%d\n", n);
+ iparr[n].inuse = 1; /* TODO */
+
+ imsi_add(options.imsi, &myimsi, n);
+
+ /* Allocated here. */
+ /* If create context failes we have to deallocate ourselves. */
+ /* Otherwise it is deallocated by gtplib */
+ pdp_newpdp(&pdp, myimsi, options.nsapi, NULL);
+
+ pdp->peer = &iparr[n];
+ pdp->ipif = tun; /* TODO */
+ iparr[n].pdp = pdp;
+
+ if (options.gtpversion == 0) {
+ if (options.qos.l - 1 > sizeof(pdp->qos_req0)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "QoS length too big");
+ exit(1);
+ } else {
+ memcpy(pdp->qos_req0, options.qos.v,
+ options.qos.l);
+ }
+ }
+
+ pdp->qos_req.l = options.qos.l;
+ memcpy(pdp->qos_req.v, options.qos.v, options.qos.l);
+
+ pdp->selmode = options.selmode;
+
+ pdp->rattype.l = options.rattype.l;
+ memcpy(pdp->rattype.v, options.rattype.v, options.rattype.l);
+ pdp->rattype_given = options.rattype_given;
+
+ pdp->userloc.l = options.userloc.l;
+ memcpy(pdp->userloc.v, options.userloc.v, options.userloc.l);
+ pdp->userloc_given = options.userloc_given;
+
+ pdp->rai.l = options.rai.l;
+ memcpy(pdp->rai.v, options.rai.v, options.rai.l);
+ pdp->rai_given = options.rai_given;
+
+ pdp->mstz.l = options.mstz.l;
+ memcpy(pdp->mstz.v, options.mstz.v, options.mstz.l);
+ pdp->mstz_given = options.mstz_given;
+
+ pdp->imeisv.l = options.imeisv.l;
+ memcpy(pdp->imeisv.v, options.imeisv.v, options.imeisv.l);
+ pdp->imeisv_given = options.imeisv_given;
+
+ pdp->norecovery_given = options.norecovery_given;
+
+ if (options.apn.l > sizeof(pdp->apn_use.v)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "APN length too big");
+ exit(1);
+ } else {
+ pdp->apn_use.l = options.apn.l;
+ memcpy(pdp->apn_use.v, options.apn.v, options.apn.l);
+ }
+
+ pdp->gsnlc.l = sizeof(options.listen);
+ memcpy(pdp->gsnlc.v, &options.listen, sizeof(options.listen));
+ pdp->gsnlu.l = sizeof(options.listen);
+ memcpy(pdp->gsnlu.v, &options.listen, sizeof(options.listen));
+
+ if (options.msisdn.l > sizeof(pdp->msisdn.v)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "MSISDN length too big");
+ exit(1);
+ } else {
+ msisdn_add(&options.msisdn, &pdp->msisdn, n);
+ }
+
+ ipv42eua(&pdp->eua, NULL); /* Request dynamic IP address */
+
+ if (options.pco.l > sizeof(pdp->pco_req.v)) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "PCO length too big");
+ exit(1);
+ } else {
+ pdp->pco_req.l = options.pco.l;
+ memcpy(pdp->pco_req.v, options.pco.v, options.pco.l);
+ }
+
+ pdp->version = options.gtpversion;
+
+ pdp->hisaddr0 = options.remote;
+ pdp->hisaddr1 = options.remote;
+
+ pdp->cch_pdp = options.cch; /* 2048 = Normal, 1024 = Prepaid,
+ 512 = Flat rate, 256 = Hot billing */
+
+ /* Create context */
+ /* We send this of once. Retransmissions are handled by gtplib */
+ gtp_create_context_req(gsn, pdp, &iparr[n]);
+ }
+ state = 1; /* Enter wait_connection state */
+
+ printf("Waiting for response from ggsn........\n\n");
/******************************************************************/
- /* Main select loop */
+ /* Main select loop */
/******************************************************************/
- while ((0 != state) && (5 != state)) {
-
- /* Take down client after timeout after disconnect */
- if ((4 == state) && ((stoptime) <= time(NULL))) {
- state = 5;
- }
-
- /* Take down client after timelimit timeout */
- if ((2 == state) && (options.timelimit) &&
- ((starttime + options.timelimit) <= time(NULL))) {
- state = 3;
- }
-
- /* Take down client after ping timeout */
- if ((2 == state) && (pingtimeout) && (pingtimeout <= time(NULL))) {
- state = 3;
- }
-
- /* Set pingtimeout for later disconnection */
- if (options.pingcount && ntransmitted >= options.pingcount) {
- pingtimeout = time(NULL) + 5; /* Extra seconds */
- }
-
- /* Print statistics if no more ping packets are missing */
- if (ntransmitted && options.pingcount && nreceived >= options.pingcount) {
- ping_finish();
- if (!options.createif)
- state = 3;
- }
-
- /* Send off disconnect */
- if (3 == state) {
- state = 4;
- stoptime = time(NULL) + 5; /* Extra seconds to allow disconnect */
- for(n=0; n<options.contexts; n++) {
- /* Delete context */
- printf("Disconnecting PDP context #%d\n", n);
- gtp_delete_context_req(gsn, iparr[n].pdp, NULL, 1);
- if ((options.pinghost.s_addr !=0) && ntransmitted) ping_finish();
- }
- }
-
- /* Send of ping packets */
- diff = 0;
- while (( diff<=0 ) &&
- /* Send off an ICMP ping packet */
- /*if (*/(options.pinghost.s_addr) && (2 == state) &&
- ((pingseq < options.pingcount) || (options.pingcount == 0))) {
- if (!pingseq) gettimeofday(&firstping, &tz); /* Set time of first ping */
- gettimeofday(&tv, &tz);
- diff = 1000000 / options.pingrate * pingseq -
- 1000000 * (tv.tv_sec - firstping.tv_sec) -
- (tv.tv_usec - firstping.tv_usec); /* Microseconds safe up to 500 sec */
- if (diff <=0) {
- if (options.debug) printf("Create_ping %d\n", diff);
- create_ping(gsn, iparr[pingseq % options.contexts].pdp,
- &options.pinghost, pingseq, options.pingsize);
- pingseq++;
- }
- }
-
- FD_ZERO(&fds);
- if (tun) FD_SET(tun->fd, &fds);
- FD_SET(gsn->fd0, &fds);
- FD_SET(gsn->fd1c, &fds);
- FD_SET(gsn->fd1u, &fds);
-
- gtp_retranstimeout(gsn, &idleTime);
- ping_timeout(&idleTime);
-
- if (options.debug) printf("idletime.tv_sec %d, idleTime.tv_usec %d\n",
- (int) idleTime.tv_sec, (int) idleTime.tv_usec);
-
- switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
- case -1:
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "Select returned -1");
- break;
- case 0:
- gtp_retrans(gsn); /* Only retransmit if nothing else */
- break;
- default:
- break;
- }
-
- if ((tun) && FD_ISSET(tun->fd, &fds) && tun_decaps(tun) < 0) {
- sys_err(LOG_ERR, __FILE__, __LINE__, 0,
- "TUN decaps failed");
- }
-
- if (FD_ISSET(gsn->fd0, &fds))
- gtp_decaps0(gsn);
-
- if (FD_ISSET(gsn->fd1c, &fds))
- gtp_decaps1c(gsn);
-
- if (FD_ISSET(gsn->fd1u, &fds))
- gtp_decaps1u(gsn);
- }
-
- gtp_free(gsn); /* Clean up the gsn instance */
-
- if (options.createif)
- tun_free(tun);
-
- if (0 == state)
- exit(1); /* Indicate error */
-
- return 0;
-}
+ while ((0 != state) && (5 != state)) {
+
+ /* Take down client after timeout after disconnect */
+ if ((4 == state) && ((stoptime) <= time(NULL))) {
+ state = 5;
+ }
+
+ /* Take down client after timelimit timeout */
+ if ((2 == state) && (options.timelimit) &&
+ ((starttime + options.timelimit) <= time(NULL))) {
+ state = 3;
+ }
+
+ /* Take down client after ping timeout */
+ if ((2 == state) && (pingtimeout)
+ && (pingtimeout <= time(NULL))) {
+ state = 3;
+ }
+
+ /* Set pingtimeout for later disconnection */
+ if (options.pingcount && ntransmitted >= options.pingcount) {
+ pingtimeout = time(NULL) + 5; /* Extra seconds */
+ }
+
+ /* Print statistics if no more ping packets are missing */
+ if (ntransmitted && options.pingcount
+ && nreceived >= options.pingcount) {
+ ping_finish();
+ if (!options.createif)
+ state = 3;
+ }
+
+ /* Send off disconnect */
+ if (3 == state) {
+ state = 4;
+ stoptime = time(NULL) + 5; /* Extra seconds to allow disconnect */
+ for (n = 0; n < options.contexts; n++) {
+ /* Delete context */
+ printf("Disconnecting PDP context #%d\n", n);
+ gtp_delete_context_req(gsn, iparr[n].pdp, NULL,
+ 1);
+ if ((options.pinghost.s_addr != 0)
+ && ntransmitted)
+ ping_finish();
+ }
+ }
+
+ /* Send of ping packets */
+ diff = 0;
+ while ((diff <= 0) &&
+ /* Send off an ICMP ping packet */
+ /*if ( */ (options.pinghost.s_addr) && (2 == state) &&
+ ((pingseq < options.pingcount)
+ || (options.pingcount == 0))) {
+ if (!pingseq)
+ gettimeofday(&firstping, &tz); /* Set time of first ping */
+ gettimeofday(&tv, &tz);
+ diff = 1000000 / options.pingrate * pingseq - 1000000 * (tv.tv_sec - firstping.tv_sec) - (tv.tv_usec - firstping.tv_usec); /* Microseconds safe up to 500 sec */
+ if (diff <= 0) {
+ if (options.debug)
+ printf("Create_ping %d\n", diff);
+ create_ping(gsn,
+ iparr[pingseq %
+ options.contexts].pdp,
+ &options.pinghost, pingseq,
+ options.pingsize);
+ pingseq++;
+ }
+ }
+
+ FD_ZERO(&fds);
+ if (tun)
+ FD_SET(tun->fd, &fds);
+ FD_SET(gsn->fd0, &fds);
+ FD_SET(gsn->fd1c, &fds);
+ FD_SET(gsn->fd1u, &fds);
+
+ gtp_retranstimeout(gsn, &idleTime);
+ ping_timeout(&idleTime);
+
+ if (options.debug)
+ printf("idletime.tv_sec %d, idleTime.tv_usec %d\n",
+ (int)idleTime.tv_sec, (int)idleTime.tv_usec);
+
+ switch (select(maxfd + 1, &fds, NULL, NULL, &idleTime)) {
+ case -1:
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "Select returned -1");
+ break;
+ case 0:
+ gtp_retrans(gsn); /* Only retransmit if nothing else */
+ break;
+ default:
+ break;
+ }
+
+ if ((tun) && FD_ISSET(tun->fd, &fds) && tun_decaps(tun) < 0) {
+ sys_err(LOG_ERR, __FILE__, __LINE__, 0,
+ "TUN decaps failed");
+ }
+
+ if (FD_ISSET(gsn->fd0, &fds))
+ gtp_decaps0(gsn);
+
+ if (FD_ISSET(gsn->fd1c, &fds))
+ gtp_decaps1c(gsn);
+
+ if (FD_ISSET(gsn->fd1u, &fds))
+ gtp_decaps1u(gsn);
+ }
+
+ gtp_free(gsn); /* Clean up the gsn instance */
+ if (options.createif)
+ tun_free(tun);
+
+ if (0 == state)
+ exit(1); /* Indicate error */
+
+ return 0;
+}