jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1 | /* |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 2 | File autogenerated by gengetopt version 2.22.6 |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 3 | generated with the following command: |
jjako | 1a51df7 | 2004-07-20 08:30:21 +0000 | [diff] [blame] | 4 | gengetopt --conf-parser |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 5 | |
| 6 | The developers of gengetopt consider the fixed text that goes in all |
| 7 | gengetopt output files to be in the public domain: |
| 8 | we make no copyright claims on it. |
| 9 | */ |
| 10 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 11 | /* If we use autoconf. */ |
| 12 | #ifdef HAVE_CONFIG_H |
| 13 | #include "config.h" |
| 14 | #endif |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 15 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 20 | #ifndef FIX_UNUSED |
| 21 | #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ |
| 22 | #endif |
| 23 | |
| 24 | #include <getopt.h> |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 25 | |
| 26 | #include "cmdline.h" |
| 27 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 28 | const char *gengetopt_args_info_purpose = ""; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 29 | |
Harald Welte | 7e1175f | 2017-09-24 10:53:53 +0800 | [diff] [blame] | 30 | const char *gengetopt_args_info_usage = "Usage: sgsnemu [OPTIONS]..."; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 31 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 32 | const char *gengetopt_args_info_versiontext = ""; |
| 33 | |
| 34 | const char *gengetopt_args_info_description = ""; |
| 35 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 36 | const char *gengetopt_args_info_help[] = { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 37 | " -h, --help Print help and exit", |
| 38 | " -V, --version Print version and exit", |
| 39 | " -d, --debug Run in debug mode (default=off)", |
| 40 | " -c, --conf=STRING Read configuration file", |
| 41 | " --pidfile=STRING Filename of process id file\n (default=`./sgsnemu.pid')", |
| 42 | " --statedir=STRING Directory of nonvolatile data (default=`./')", |
| 43 | " --dns=STRING DNS Server to use", |
Pau Espin Pedrol | 5fdda13 | 2018-02-12 18:03:09 +0100 | [diff] [blame] | 44 | " -l, --listen=STRING Local host", |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 45 | " -r, --remote=STRING Remote host", |
| 46 | " --contexts=INT Number of contexts (default=`1')", |
| 47 | " --timelimit=INT Exit after timelimit seconds (default=`0')", |
| 48 | " --gtpversion=INT GTP version to use (default=`1')", |
| 49 | " -a, --apn=STRING Access point name (default=`internet')", |
| 50 | " --selmode=INT Selection mode (default=`0x01')", |
| 51 | " --rattype=1..5 Radio Access Technology Type (default=`1')", |
| 52 | " --userloc=type.MCC.MNC.LAC.CIorSACorRAC\n User Location Information\n (default=`02509946241207')", |
| 53 | " --rai=MCC.MNC.LAC.RAC Routing Area Information\n (default=`02509946241207')", |
| 54 | " --mstz=sign.NbQuartersOfAnHour.DSTAdjustment\n MS Time Zone (default=`0')", |
| 55 | " --imeisv=STRING IMEI(SV) International Mobile Equipment\n Identity (and Software Version)\n (default=`2143658709214365')", |
| 56 | " --norecovery Do not send recovery (default=off)", |
| 57 | " -i, --imsi=STRING IMSI (default=`240010123456789')", |
| 58 | " --nsapi=INT NSAPI (default=`0')", |
| 59 | " -m, --msisdn=STRING Mobile Station ISDN number\n (default=`46702123456')", |
| 60 | " -q, --qos=INT Requested quality of service\n (default=`0x000b921f')", |
| 61 | " --qose1=INT Requested quality of service Extension 1\n (default=`0x9396404074f9ffff')", |
| 62 | " --qose2=INT Requested quality of service Extension 2\n (default=`0x11')", |
| 63 | " --qose3=INT Requested quality of service Extension 3\n (default=`0x0101')", |
| 64 | " --qose4=INT Requested quality of service Extension 4\n (default=`0x4040')", |
| 65 | " --charging=INT Charging characteristics (default=`0x0800')", |
| 66 | " -u, --uid=STRING Login user ID (default=`mig')", |
| 67 | " -p, --pwd=STRING Login password (default=`hemmelig')", |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 68 | "\n Mode: createif\n any option of this mode is related to tun interface, all payload going in and\n out via tunN interface", |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 69 | " --createif Create local network interface (default=off)", |
| 70 | " -n, --net=STRING Network address for local interface", |
| 71 | " --defaultroute Create default route (default=off)", |
| 72 | " --ipup=STRING Script to run after link-up", |
| 73 | " --ipdown=STRING Script to run after link-down", |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 74 | " --tun-device=STRING Name of the local network interface", |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 75 | "\n Mode: pinghost\n generate ICMP payload inside G-PDU without setting up tun interface", |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 76 | " --pinghost=STRING Ping remote host", |
| 77 | " --pingrate=INT Number of ping req per second (default=`1')", |
| 78 | " --pingsize=INT Number of ping data bytes (default=`56')", |
| 79 | " --pingcount=INT Number of ping req to send (default=`0')", |
| 80 | " --pingquiet Do not print ping packet info (default=off)", |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 81 | " --no-tx-gpdu-seq Don't transmit G-PDU sequence nums\n (default=off)", |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 82 | " -t, --pdp-type=(v4|v6) PDP Type (default=`v4')", |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 83 | 0 |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 86 | typedef enum { ARG_NO, ARG_FLAG, ARG_STRING, ARG_INT |
| 87 | } cmdline_parser_arg_type; |
| 88 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 89 | static |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 90 | void clear_given(struct gengetopt_args_info *args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 91 | static |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 92 | void clear_args(struct gengetopt_args_info *args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 93 | |
| 94 | static int |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 95 | cmdline_parser_internal(int argc, char **argv, |
| 96 | struct gengetopt_args_info *args_info, |
| 97 | struct cmdline_parser_params *params, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 98 | const char *additional_error); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 99 | |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 100 | static int |
| 101 | cmdline_parser_required2(struct gengetopt_args_info *args_info, |
| 102 | const char *prog_name, const char *additional_error); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 103 | struct line_list { |
| 104 | char *string_arg; |
| 105 | struct line_list *next; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static struct line_list *cmd_line_list = 0; |
| 109 | static struct line_list *cmd_line_list_tmp = 0; |
| 110 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 111 | static void free_cmd_list(void) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 112 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 113 | /* free the list of a previous call */ |
| 114 | if (cmd_line_list) { |
| 115 | while (cmd_line_list) { |
| 116 | cmd_line_list_tmp = cmd_line_list; |
| 117 | cmd_line_list = cmd_line_list->next; |
| 118 | free(cmd_line_list_tmp->string_arg); |
| 119 | free(cmd_line_list_tmp); |
| 120 | } |
| 121 | } |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 124 | static char *gengetopt_strdup(const char *s); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 125 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 126 | static |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 127 | void clear_given(struct gengetopt_args_info *args_info) |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 128 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 129 | args_info->help_given = 0; |
| 130 | args_info->version_given = 0; |
| 131 | args_info->debug_given = 0; |
| 132 | args_info->conf_given = 0; |
| 133 | args_info->pidfile_given = 0; |
| 134 | args_info->statedir_given = 0; |
| 135 | args_info->dns_given = 0; |
| 136 | args_info->listen_given = 0; |
| 137 | args_info->remote_given = 0; |
| 138 | args_info->contexts_given = 0; |
| 139 | args_info->timelimit_given = 0; |
| 140 | args_info->gtpversion_given = 0; |
| 141 | args_info->apn_given = 0; |
| 142 | args_info->selmode_given = 0; |
| 143 | args_info->rattype_given = 0; |
| 144 | args_info->userloc_given = 0; |
| 145 | args_info->rai_given = 0; |
| 146 | args_info->mstz_given = 0; |
| 147 | args_info->imeisv_given = 0; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 148 | args_info->norecovery_given = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 149 | args_info->imsi_given = 0; |
| 150 | args_info->nsapi_given = 0; |
| 151 | args_info->msisdn_given = 0; |
| 152 | args_info->qos_given = 0; |
| 153 | args_info->qose1_given = 0; |
| 154 | args_info->qose2_given = 0; |
| 155 | args_info->qose3_given = 0; |
| 156 | args_info->qose4_given = 0; |
| 157 | args_info->charging_given = 0; |
| 158 | args_info->uid_given = 0; |
| 159 | args_info->pwd_given = 0; |
| 160 | args_info->createif_given = 0; |
| 161 | args_info->net_given = 0; |
| 162 | args_info->defaultroute_given = 0; |
| 163 | args_info->ipup_given = 0; |
| 164 | args_info->ipdown_given = 0; |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 165 | args_info->tun_device_given = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 166 | args_info->pinghost_given = 0; |
| 167 | args_info->pingrate_given = 0; |
| 168 | args_info->pingsize_given = 0; |
| 169 | args_info->pingcount_given = 0; |
| 170 | args_info->pingquiet_given = 0; |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 171 | args_info->no_tx_gpdu_seq_given = 0; |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 172 | args_info->pdp_type_given = 0; |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 173 | args_info->createif_mode_counter = 0; |
| 174 | args_info->pinghost_mode_counter = 0; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 177 | static |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 178 | void clear_args(struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 179 | { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 180 | FIX_UNUSED(args_info); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 181 | args_info->debug_flag = 0; |
| 182 | args_info->conf_arg = NULL; |
| 183 | args_info->conf_orig = NULL; |
| 184 | args_info->pidfile_arg = gengetopt_strdup("./sgsnemu.pid"); |
| 185 | args_info->pidfile_orig = NULL; |
| 186 | args_info->statedir_arg = gengetopt_strdup("./"); |
| 187 | args_info->statedir_orig = NULL; |
| 188 | args_info->dns_arg = NULL; |
| 189 | args_info->dns_orig = NULL; |
| 190 | args_info->listen_arg = NULL; |
| 191 | args_info->listen_orig = NULL; |
| 192 | args_info->remote_arg = NULL; |
| 193 | args_info->remote_orig = NULL; |
| 194 | args_info->contexts_arg = 1; |
| 195 | args_info->contexts_orig = NULL; |
| 196 | args_info->timelimit_arg = 0; |
| 197 | args_info->timelimit_orig = NULL; |
| 198 | args_info->gtpversion_arg = 1; |
| 199 | args_info->gtpversion_orig = NULL; |
| 200 | args_info->apn_arg = gengetopt_strdup("internet"); |
| 201 | args_info->apn_orig = NULL; |
| 202 | args_info->selmode_arg = 0x01; |
| 203 | args_info->selmode_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 204 | args_info->rattype_arg = 1; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 205 | args_info->rattype_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 206 | args_info->userloc_arg = gengetopt_strdup("02509946241207"); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 207 | args_info->userloc_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 208 | args_info->rai_arg = gengetopt_strdup("02509946241207"); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 209 | args_info->rai_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 210 | args_info->mstz_arg = gengetopt_strdup("0"); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 211 | args_info->mstz_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 212 | args_info->imeisv_arg = gengetopt_strdup("2143658709214365"); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 213 | args_info->imeisv_orig = NULL; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 214 | args_info->norecovery_flag = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 215 | args_info->imsi_arg = gengetopt_strdup("240010123456789"); |
| 216 | args_info->imsi_orig = NULL; |
| 217 | args_info->nsapi_arg = 0; |
| 218 | args_info->nsapi_orig = NULL; |
| 219 | args_info->msisdn_arg = gengetopt_strdup("46702123456"); |
| 220 | args_info->msisdn_orig = NULL; |
| 221 | args_info->qos_arg = 0x000b921f; |
| 222 | args_info->qos_orig = NULL; |
| 223 | args_info->qose1_arg = 0x9396404074f9ffff; |
| 224 | args_info->qose1_orig = NULL; |
| 225 | args_info->qose2_arg = 0x11; |
| 226 | args_info->qose2_orig = NULL; |
| 227 | args_info->qose3_arg = 0x0101; |
| 228 | args_info->qose3_orig = NULL; |
| 229 | args_info->qose4_arg = 0x4040; |
| 230 | args_info->qose4_orig = NULL; |
| 231 | args_info->charging_arg = 0x0800; |
| 232 | args_info->charging_orig = NULL; |
| 233 | args_info->uid_arg = gengetopt_strdup("mig"); |
| 234 | args_info->uid_orig = NULL; |
| 235 | args_info->pwd_arg = gengetopt_strdup("hemmelig"); |
| 236 | args_info->pwd_orig = NULL; |
| 237 | args_info->createif_flag = 0; |
| 238 | args_info->net_arg = NULL; |
| 239 | args_info->net_orig = NULL; |
| 240 | args_info->defaultroute_flag = 0; |
| 241 | args_info->ipup_arg = NULL; |
| 242 | args_info->ipup_orig = NULL; |
| 243 | args_info->ipdown_arg = NULL; |
| 244 | args_info->ipdown_orig = NULL; |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 245 | args_info->tun_device_arg = NULL; |
| 246 | args_info->tun_device_orig = NULL; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 247 | args_info->pinghost_arg = NULL; |
| 248 | args_info->pinghost_orig = NULL; |
| 249 | args_info->pingrate_arg = 1; |
| 250 | args_info->pingrate_orig = NULL; |
| 251 | args_info->pingsize_arg = 56; |
| 252 | args_info->pingsize_orig = NULL; |
| 253 | args_info->pingcount_arg = 0; |
| 254 | args_info->pingcount_orig = NULL; |
| 255 | args_info->pingquiet_flag = 0; |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 256 | args_info->no_tx_gpdu_seq_flag = 0; |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 257 | args_info->pdp_type_arg = gengetopt_strdup("v4"); |
| 258 | args_info->pdp_type_orig = NULL; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 259 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static |
| 263 | void init_args_info(struct gengetopt_args_info *args_info) |
| 264 | { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 265 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 266 | args_info->help_help = gengetopt_args_info_help[0]; |
| 267 | args_info->version_help = gengetopt_args_info_help[1]; |
| 268 | args_info->debug_help = gengetopt_args_info_help[2]; |
| 269 | args_info->conf_help = gengetopt_args_info_help[3]; |
| 270 | args_info->pidfile_help = gengetopt_args_info_help[4]; |
| 271 | args_info->statedir_help = gengetopt_args_info_help[5]; |
| 272 | args_info->dns_help = gengetopt_args_info_help[6]; |
| 273 | args_info->listen_help = gengetopt_args_info_help[7]; |
| 274 | args_info->remote_help = gengetopt_args_info_help[8]; |
| 275 | args_info->contexts_help = gengetopt_args_info_help[9]; |
| 276 | args_info->timelimit_help = gengetopt_args_info_help[10]; |
| 277 | args_info->gtpversion_help = gengetopt_args_info_help[11]; |
| 278 | args_info->apn_help = gengetopt_args_info_help[12]; |
| 279 | args_info->selmode_help = gengetopt_args_info_help[13]; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 280 | args_info->rattype_help = gengetopt_args_info_help[14]; |
| 281 | args_info->userloc_help = gengetopt_args_info_help[15]; |
| 282 | args_info->rai_help = gengetopt_args_info_help[16]; |
| 283 | args_info->mstz_help = gengetopt_args_info_help[17]; |
| 284 | args_info->imeisv_help = gengetopt_args_info_help[18]; |
| 285 | args_info->norecovery_help = gengetopt_args_info_help[19]; |
| 286 | args_info->imsi_help = gengetopt_args_info_help[20]; |
| 287 | args_info->nsapi_help = gengetopt_args_info_help[21]; |
| 288 | args_info->msisdn_help = gengetopt_args_info_help[22]; |
| 289 | args_info->qos_help = gengetopt_args_info_help[23]; |
| 290 | args_info->qose1_help = gengetopt_args_info_help[24]; |
| 291 | args_info->qose2_help = gengetopt_args_info_help[25]; |
| 292 | args_info->qose3_help = gengetopt_args_info_help[26]; |
| 293 | args_info->qose4_help = gengetopt_args_info_help[27]; |
| 294 | args_info->charging_help = gengetopt_args_info_help[28]; |
| 295 | args_info->uid_help = gengetopt_args_info_help[29]; |
| 296 | args_info->pwd_help = gengetopt_args_info_help[30]; |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 297 | args_info->createif_help = gengetopt_args_info_help[32]; |
| 298 | args_info->net_help = gengetopt_args_info_help[33]; |
| 299 | args_info->defaultroute_help = gengetopt_args_info_help[34]; |
| 300 | args_info->ipup_help = gengetopt_args_info_help[35]; |
| 301 | args_info->ipdown_help = gengetopt_args_info_help[36]; |
| 302 | args_info->tun_device_help = gengetopt_args_info_help[37]; |
| 303 | args_info->pinghost_help = gengetopt_args_info_help[39]; |
| 304 | args_info->pingrate_help = gengetopt_args_info_help[40]; |
| 305 | args_info->pingsize_help = gengetopt_args_info_help[41]; |
| 306 | args_info->pingcount_help = gengetopt_args_info_help[42]; |
| 307 | args_info->pingquiet_help = gengetopt_args_info_help[43]; |
| 308 | args_info->no_tx_gpdu_seq_help = gengetopt_args_info_help[44]; |
| 309 | args_info->pdp_type_help = gengetopt_args_info_help[45]; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 310 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 313 | void cmdline_parser_print_version(void) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 314 | { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 315 | printf("%s %s\n", |
| 316 | (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? |
| 317 | CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), |
| 318 | CMDLINE_PARSER_VERSION); |
| 319 | |
| 320 | if (strlen(gengetopt_args_info_versiontext) > 0) |
| 321 | printf("\n%s\n", gengetopt_args_info_versiontext); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 324 | static void print_help_common(void) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 325 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 326 | cmdline_parser_print_version(); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 327 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 328 | if (strlen(gengetopt_args_info_purpose) > 0) |
| 329 | printf("\n%s\n", gengetopt_args_info_purpose); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 330 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 331 | if (strlen(gengetopt_args_info_usage) > 0) |
| 332 | printf("\n%s\n", gengetopt_args_info_usage); |
| 333 | |
| 334 | printf("\n"); |
| 335 | |
| 336 | if (strlen(gengetopt_args_info_description) > 0) |
| 337 | printf("%s\n\n", gengetopt_args_info_description); |
| 338 | } |
| 339 | |
| 340 | void cmdline_parser_print_help(void) |
| 341 | { |
| 342 | int i = 0; |
| 343 | print_help_common(); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 344 | while (gengetopt_args_info_help[i]) |
| 345 | printf("%s\n", gengetopt_args_info_help[i++]); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 348 | void cmdline_parser_init(struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 349 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 350 | clear_given(args_info); |
| 351 | clear_args(args_info); |
| 352 | init_args_info(args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 355 | void cmdline_parser_params_init(struct cmdline_parser_params *params) |
| 356 | { |
| 357 | if (params) { |
| 358 | params->override = 0; |
| 359 | params->initialize = 1; |
| 360 | params->check_required = 1; |
| 361 | params->check_ambiguity = 0; |
| 362 | params->print_errors = 1; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | struct cmdline_parser_params *cmdline_parser_params_create(void) |
| 367 | { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 368 | struct cmdline_parser_params *params = (struct cmdline_parser_params *) |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 369 | malloc(sizeof(struct cmdline_parser_params)); |
| 370 | cmdline_parser_params_init(params); |
| 371 | return params; |
| 372 | } |
| 373 | |
| 374 | static void free_string_field(char **s) |
| 375 | { |
| 376 | if (*s) { |
| 377 | free(*s); |
| 378 | *s = 0; |
| 379 | } |
| 380 | } |
| 381 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 382 | static void cmdline_parser_release(struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 383 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 384 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 385 | free_string_field(&(args_info->conf_arg)); |
| 386 | free_string_field(&(args_info->conf_orig)); |
| 387 | free_string_field(&(args_info->pidfile_arg)); |
| 388 | free_string_field(&(args_info->pidfile_orig)); |
| 389 | free_string_field(&(args_info->statedir_arg)); |
| 390 | free_string_field(&(args_info->statedir_orig)); |
| 391 | free_string_field(&(args_info->dns_arg)); |
| 392 | free_string_field(&(args_info->dns_orig)); |
| 393 | free_string_field(&(args_info->listen_arg)); |
| 394 | free_string_field(&(args_info->listen_orig)); |
| 395 | free_string_field(&(args_info->remote_arg)); |
| 396 | free_string_field(&(args_info->remote_orig)); |
| 397 | free_string_field(&(args_info->contexts_orig)); |
| 398 | free_string_field(&(args_info->timelimit_orig)); |
| 399 | free_string_field(&(args_info->gtpversion_orig)); |
| 400 | free_string_field(&(args_info->apn_arg)); |
| 401 | free_string_field(&(args_info->apn_orig)); |
| 402 | free_string_field(&(args_info->selmode_orig)); |
| 403 | free_string_field(&(args_info->rattype_orig)); |
| 404 | free_string_field(&(args_info->userloc_arg)); |
| 405 | free_string_field(&(args_info->userloc_orig)); |
| 406 | free_string_field(&(args_info->rai_arg)); |
| 407 | free_string_field(&(args_info->rai_orig)); |
| 408 | free_string_field(&(args_info->mstz_arg)); |
| 409 | free_string_field(&(args_info->mstz_orig)); |
| 410 | free_string_field(&(args_info->imeisv_arg)); |
| 411 | free_string_field(&(args_info->imeisv_orig)); |
| 412 | free_string_field(&(args_info->imsi_arg)); |
| 413 | free_string_field(&(args_info->imsi_orig)); |
| 414 | free_string_field(&(args_info->nsapi_orig)); |
| 415 | free_string_field(&(args_info->msisdn_arg)); |
| 416 | free_string_field(&(args_info->msisdn_orig)); |
| 417 | free_string_field(&(args_info->qos_orig)); |
| 418 | free_string_field(&(args_info->qose1_orig)); |
| 419 | free_string_field(&(args_info->qose2_orig)); |
| 420 | free_string_field(&(args_info->qose3_orig)); |
| 421 | free_string_field(&(args_info->qose4_orig)); |
| 422 | free_string_field(&(args_info->charging_orig)); |
| 423 | free_string_field(&(args_info->uid_arg)); |
| 424 | free_string_field(&(args_info->uid_orig)); |
| 425 | free_string_field(&(args_info->pwd_arg)); |
| 426 | free_string_field(&(args_info->pwd_orig)); |
| 427 | free_string_field(&(args_info->net_arg)); |
| 428 | free_string_field(&(args_info->net_orig)); |
| 429 | free_string_field(&(args_info->ipup_arg)); |
| 430 | free_string_field(&(args_info->ipup_orig)); |
| 431 | free_string_field(&(args_info->ipdown_arg)); |
| 432 | free_string_field(&(args_info->ipdown_orig)); |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 433 | free_string_field(&(args_info->tun_device_arg)); |
| 434 | free_string_field(&(args_info->tun_device_orig)); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 435 | free_string_field(&(args_info->pinghost_arg)); |
| 436 | free_string_field(&(args_info->pinghost_orig)); |
| 437 | free_string_field(&(args_info->pingrate_orig)); |
| 438 | free_string_field(&(args_info->pingsize_orig)); |
| 439 | free_string_field(&(args_info->pingcount_orig)); |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 440 | free_string_field(&(args_info->pdp_type_arg)); |
| 441 | free_string_field(&(args_info->pdp_type_orig)); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 442 | |
| 443 | clear_given(args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 446 | static void |
| 447 | write_into_file(FILE * outfile, const char *opt, const char *arg, |
| 448 | const char *values[]) |
| 449 | { |
| 450 | FIX_UNUSED(values); |
| 451 | if (arg) { |
| 452 | fprintf(outfile, "%s=\"%s\"\n", opt, arg); |
| 453 | } else { |
| 454 | fprintf(outfile, "%s\n", opt); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | int cmdline_parser_dump(FILE * outfile, struct gengetopt_args_info *args_info) |
| 459 | { |
| 460 | int i = 0; |
| 461 | |
| 462 | if (!outfile) { |
| 463 | fprintf(stderr, "%s: cannot dump options to stream\n", |
| 464 | CMDLINE_PARSER_PACKAGE); |
| 465 | return EXIT_FAILURE; |
| 466 | } |
| 467 | |
| 468 | if (args_info->help_given) |
| 469 | write_into_file(outfile, "help", 0, 0); |
| 470 | if (args_info->version_given) |
| 471 | write_into_file(outfile, "version", 0, 0); |
| 472 | if (args_info->debug_given) |
| 473 | write_into_file(outfile, "debug", 0, 0); |
| 474 | if (args_info->conf_given) |
| 475 | write_into_file(outfile, "conf", args_info->conf_orig, 0); |
| 476 | if (args_info->pidfile_given) |
| 477 | write_into_file(outfile, "pidfile", args_info->pidfile_orig, 0); |
| 478 | if (args_info->statedir_given) |
| 479 | write_into_file(outfile, "statedir", args_info->statedir_orig, |
| 480 | 0); |
| 481 | if (args_info->dns_given) |
| 482 | write_into_file(outfile, "dns", args_info->dns_orig, 0); |
| 483 | if (args_info->listen_given) |
| 484 | write_into_file(outfile, "listen", args_info->listen_orig, 0); |
| 485 | if (args_info->remote_given) |
| 486 | write_into_file(outfile, "remote", args_info->remote_orig, 0); |
| 487 | if (args_info->contexts_given) |
| 488 | write_into_file(outfile, "contexts", args_info->contexts_orig, |
| 489 | 0); |
| 490 | if (args_info->timelimit_given) |
| 491 | write_into_file(outfile, "timelimit", args_info->timelimit_orig, |
| 492 | 0); |
| 493 | if (args_info->gtpversion_given) |
| 494 | write_into_file(outfile, "gtpversion", |
| 495 | args_info->gtpversion_orig, 0); |
| 496 | if (args_info->apn_given) |
| 497 | write_into_file(outfile, "apn", args_info->apn_orig, 0); |
| 498 | if (args_info->selmode_given) |
| 499 | write_into_file(outfile, "selmode", args_info->selmode_orig, 0); |
| 500 | if (args_info->rattype_given) |
| 501 | write_into_file(outfile, "rattype", args_info->rattype_orig, 0); |
| 502 | if (args_info->userloc_given) |
| 503 | write_into_file(outfile, "userloc", args_info->userloc_orig, 0); |
| 504 | if (args_info->rai_given) |
| 505 | write_into_file(outfile, "rai", args_info->rai_orig, 0); |
| 506 | if (args_info->mstz_given) |
| 507 | write_into_file(outfile, "mstz", args_info->mstz_orig, 0); |
| 508 | if (args_info->imeisv_given) |
| 509 | write_into_file(outfile, "imeisv", args_info->imeisv_orig, 0); |
| 510 | if (args_info->norecovery_given) |
| 511 | write_into_file(outfile, "norecovery", 0, 0); |
| 512 | if (args_info->imsi_given) |
| 513 | write_into_file(outfile, "imsi", args_info->imsi_orig, 0); |
| 514 | if (args_info->nsapi_given) |
| 515 | write_into_file(outfile, "nsapi", args_info->nsapi_orig, 0); |
| 516 | if (args_info->msisdn_given) |
| 517 | write_into_file(outfile, "msisdn", args_info->msisdn_orig, 0); |
| 518 | if (args_info->qos_given) |
| 519 | write_into_file(outfile, "qos", args_info->qos_orig, 0); |
| 520 | if (args_info->qose1_given) |
| 521 | write_into_file(outfile, "qose1", args_info->qose1_orig, 0); |
| 522 | if (args_info->qose2_given) |
| 523 | write_into_file(outfile, "qose2", args_info->qose2_orig, 0); |
| 524 | if (args_info->qose3_given) |
| 525 | write_into_file(outfile, "qose3", args_info->qose3_orig, 0); |
| 526 | if (args_info->qose4_given) |
| 527 | write_into_file(outfile, "qose4", args_info->qose4_orig, 0); |
| 528 | if (args_info->charging_given) |
| 529 | write_into_file(outfile, "charging", args_info->charging_orig, |
| 530 | 0); |
| 531 | if (args_info->uid_given) |
| 532 | write_into_file(outfile, "uid", args_info->uid_orig, 0); |
| 533 | if (args_info->pwd_given) |
| 534 | write_into_file(outfile, "pwd", args_info->pwd_orig, 0); |
| 535 | if (args_info->createif_given) |
| 536 | write_into_file(outfile, "createif", 0, 0); |
| 537 | if (args_info->net_given) |
| 538 | write_into_file(outfile, "net", args_info->net_orig, 0); |
| 539 | if (args_info->defaultroute_given) |
| 540 | write_into_file(outfile, "defaultroute", 0, 0); |
| 541 | if (args_info->ipup_given) |
| 542 | write_into_file(outfile, "ipup", args_info->ipup_orig, 0); |
| 543 | if (args_info->ipdown_given) |
| 544 | write_into_file(outfile, "ipdown", args_info->ipdown_orig, 0); |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 545 | if (args_info->tun_device_given) |
| 546 | write_into_file(outfile, "tun-device", |
| 547 | args_info->tun_device_orig, 0); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 548 | if (args_info->pinghost_given) |
| 549 | write_into_file(outfile, "pinghost", args_info->pinghost_orig, |
| 550 | 0); |
| 551 | if (args_info->pingrate_given) |
| 552 | write_into_file(outfile, "pingrate", args_info->pingrate_orig, |
| 553 | 0); |
| 554 | if (args_info->pingsize_given) |
| 555 | write_into_file(outfile, "pingsize", args_info->pingsize_orig, |
| 556 | 0); |
| 557 | if (args_info->pingcount_given) |
| 558 | write_into_file(outfile, "pingcount", args_info->pingcount_orig, |
| 559 | 0); |
| 560 | if (args_info->pingquiet_given) |
| 561 | write_into_file(outfile, "pingquiet", 0, 0); |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 562 | if (args_info->no_tx_gpdu_seq_given) |
| 563 | write_into_file(outfile, "no-tx-gpdu-seq", 0, 0); |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 564 | if (args_info->pdp_type_given) |
| 565 | write_into_file(outfile, "pdp-type", args_info->pdp_type_orig, |
| 566 | 0); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 567 | |
| 568 | i = EXIT_SUCCESS; |
| 569 | return i; |
| 570 | } |
| 571 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 572 | int |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 573 | cmdline_parser_file_save(const char *filename, |
| 574 | struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 575 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 576 | FILE *outfile; |
| 577 | int i = 0; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 578 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 579 | outfile = fopen(filename, "w"); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 580 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 581 | if (!outfile) { |
| 582 | fprintf(stderr, "%s: cannot open file for writing: %s\n", |
| 583 | CMDLINE_PARSER_PACKAGE, filename); |
| 584 | return EXIT_FAILURE; |
| 585 | } |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 586 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 587 | i = cmdline_parser_dump(outfile, args_info); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 588 | fclose(outfile); |
| 589 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 590 | return i; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 593 | void cmdline_parser_free(struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 594 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 595 | cmdline_parser_release(args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 598 | /** @brief replacement of strdup, which is not standard */ |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 599 | char *gengetopt_strdup(const char *s) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 600 | { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 601 | char *result = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 602 | if (!s) |
| 603 | return result; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 604 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 605 | result = (char *)malloc(strlen(s) + 1); |
| 606 | if (result == (char *)0) |
| 607 | return (char *)0; |
| 608 | strcpy(result, s); |
| 609 | return result; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 612 | int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 613 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 614 | return cmdline_parser2(argc, argv, args_info, 0, 1, 1); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | int |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 618 | cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, |
| 619 | struct cmdline_parser_params *params) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 620 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 621 | int result; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 622 | result = cmdline_parser_internal(argc, argv, args_info, params, 0); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 623 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 624 | if (result == EXIT_FAILURE) { |
| 625 | cmdline_parser_free(args_info); |
| 626 | exit(EXIT_FAILURE); |
| 627 | } |
| 628 | |
| 629 | return result; |
| 630 | } |
| 631 | |
| 632 | int |
| 633 | cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, |
| 634 | int override, int initialize, int check_required) |
| 635 | { |
| 636 | int result; |
| 637 | struct cmdline_parser_params params; |
| 638 | |
| 639 | params.override = override; |
| 640 | params.initialize = initialize; |
| 641 | params.check_required = check_required; |
| 642 | params.check_ambiguity = 0; |
| 643 | params.print_errors = 1; |
| 644 | |
| 645 | result = cmdline_parser_internal(argc, argv, args_info, ¶ms, 0); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 646 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 647 | if (result == EXIT_FAILURE) { |
| 648 | cmdline_parser_free(args_info); |
| 649 | exit(EXIT_FAILURE); |
| 650 | } |
| 651 | |
| 652 | return result; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | int |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 656 | cmdline_parser_required(struct gengetopt_args_info *args_info, |
| 657 | const char *prog_name) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 658 | { |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 659 | int result = EXIT_SUCCESS; |
| 660 | |
| 661 | if (cmdline_parser_required2(args_info, prog_name, 0) > 0) |
| 662 | result = EXIT_FAILURE; |
| 663 | |
| 664 | if (result == EXIT_FAILURE) { |
| 665 | cmdline_parser_free(args_info); |
| 666 | exit(EXIT_FAILURE); |
| 667 | } |
| 668 | |
| 669 | return result; |
| 670 | } |
| 671 | |
| 672 | int |
| 673 | cmdline_parser_required2(struct gengetopt_args_info *args_info, |
| 674 | const char *prog_name, const char *additional_error) |
| 675 | { |
| 676 | int error_occurred = 0; |
| 677 | FIX_UNUSED(additional_error); |
| 678 | |
| 679 | /* checks for required options */ |
| 680 | |
| 681 | /* checks for dependences among options */ |
Harald Welte | ea0c26a | 2017-10-10 08:54:04 +0800 | [diff] [blame] | 682 | if (args_info->net_given && !args_info->createif_given) { |
| 683 | fprintf(stderr, |
| 684 | "%s: '--net' ('-n') option depends on option 'createif'%s\n", |
| 685 | prog_name, (additional_error ? additional_error : "")); |
| 686 | error_occurred = 1; |
| 687 | } |
| 688 | if (args_info->defaultroute_given && !args_info->createif_given) { |
| 689 | fprintf(stderr, |
| 690 | "%s: '--defaultroute' option depends on option 'createif'%s\n", |
| 691 | prog_name, (additional_error ? additional_error : "")); |
| 692 | error_occurred = 1; |
| 693 | } |
| 694 | if (args_info->ipup_given && !args_info->createif_given) { |
| 695 | fprintf(stderr, |
| 696 | "%s: '--ipup' option depends on option 'createif'%s\n", |
| 697 | prog_name, (additional_error ? additional_error : "")); |
| 698 | error_occurred = 1; |
| 699 | } |
| 700 | if (args_info->ipdown_given && !args_info->createif_given) { |
| 701 | fprintf(stderr, |
| 702 | "%s: '--ipdown' option depends on option 'createif'%s\n", |
| 703 | prog_name, (additional_error ? additional_error : "")); |
| 704 | error_occurred = 1; |
| 705 | } |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 706 | if (args_info->tun_device_given && !args_info->createif_given) { |
| 707 | fprintf(stderr, |
| 708 | "%s: '--tun-device' option depends on option 'createif'%s\n", |
| 709 | prog_name, (additional_error ? additional_error : "")); |
| 710 | error_occurred = 1; |
| 711 | } |
Harald Welte | ea0c26a | 2017-10-10 08:54:04 +0800 | [diff] [blame] | 712 | if (args_info->pingrate_given && !args_info->pinghost_given) { |
| 713 | fprintf(stderr, |
| 714 | "%s: '--pingrate' option depends on option 'pinghost'%s\n", |
| 715 | prog_name, (additional_error ? additional_error : "")); |
| 716 | error_occurred = 1; |
| 717 | } |
| 718 | if (args_info->pingsize_given && !args_info->pinghost_given) { |
| 719 | fprintf(stderr, |
| 720 | "%s: '--pingsize' option depends on option 'pinghost'%s\n", |
| 721 | prog_name, (additional_error ? additional_error : "")); |
| 722 | error_occurred = 1; |
| 723 | } |
| 724 | if (args_info->pingcount_given && !args_info->pinghost_given) { |
| 725 | fprintf(stderr, |
| 726 | "%s: '--pingcount' option depends on option 'pinghost'%s\n", |
| 727 | prog_name, (additional_error ? additional_error : "")); |
| 728 | error_occurred = 1; |
| 729 | } |
| 730 | if (args_info->pingquiet_given && !args_info->pinghost_given) { |
| 731 | fprintf(stderr, |
| 732 | "%s: '--pingquiet' option depends on option 'pinghost'%s\n", |
| 733 | prog_name, (additional_error ? additional_error : "")); |
| 734 | error_occurred = 1; |
| 735 | } |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 736 | |
| 737 | return error_occurred; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 740 | static char *package_name = 0; |
| 741 | |
| 742 | /** |
| 743 | * @brief updates an option |
| 744 | * @param field the generic pointer to the field to update |
| 745 | * @param orig_field the pointer to the orig field |
| 746 | * @param field_given the pointer to the number of occurrence of this option |
| 747 | * @param prev_given the pointer to the number of occurrence already seen |
| 748 | * @param value the argument for this option (if null no arg was specified) |
| 749 | * @param possible_values the possible values for this option (if specified) |
| 750 | * @param default_value the default value (in case the option only accepts fixed values) |
| 751 | * @param arg_type the type of this option |
| 752 | * @param check_ambiguity @see cmdline_parser_params.check_ambiguity |
| 753 | * @param override @see cmdline_parser_params.override |
| 754 | * @param no_free whether to free a possible previous value |
| 755 | * @param multiple_option whether this is a multiple option |
| 756 | * @param long_opt the corresponding long option |
| 757 | * @param short_opt the corresponding short option (or '-' if none) |
| 758 | * @param additional_error possible further error specification |
| 759 | */ |
| 760 | static |
| 761 | int update_arg(void *field, char **orig_field, |
| 762 | unsigned int *field_given, unsigned int *prev_given, |
| 763 | char *value, const char *possible_values[], |
| 764 | const char *default_value, |
| 765 | cmdline_parser_arg_type arg_type, |
| 766 | int check_ambiguity, int override, |
| 767 | int no_free, int multiple_option, |
| 768 | const char *long_opt, char short_opt, |
| 769 | const char *additional_error) |
| 770 | { |
| 771 | char *stop_char = 0; |
| 772 | const char *val = value; |
| 773 | int found; |
| 774 | char **string_field; |
| 775 | FIX_UNUSED(field); |
| 776 | |
| 777 | stop_char = 0; |
| 778 | found = 0; |
| 779 | |
| 780 | if (!multiple_option && prev_given |
| 781 | && (*prev_given || (check_ambiguity && *field_given))) { |
| 782 | if (short_opt != '-') |
| 783 | fprintf(stderr, |
| 784 | "%s: `--%s' (`-%c') option given more than once%s\n", |
| 785 | package_name, long_opt, short_opt, |
| 786 | (additional_error ? additional_error : "")); |
| 787 | else |
| 788 | fprintf(stderr, |
| 789 | "%s: `--%s' option given more than once%s\n", |
| 790 | package_name, long_opt, |
| 791 | (additional_error ? additional_error : "")); |
| 792 | return 1; /* failure */ |
| 793 | } |
| 794 | |
| 795 | FIX_UNUSED(default_value); |
| 796 | |
| 797 | if (field_given && *field_given && !override) |
| 798 | return 0; |
| 799 | if (prev_given) |
| 800 | (*prev_given)++; |
| 801 | if (field_given) |
| 802 | (*field_given)++; |
| 803 | if (possible_values) |
| 804 | val = possible_values[found]; |
| 805 | |
| 806 | switch (arg_type) { |
| 807 | case ARG_FLAG: |
| 808 | *((int *)field) = !*((int *)field); |
| 809 | break; |
| 810 | case ARG_INT: |
| 811 | if (val) |
| 812 | *((int *)field) = strtol(val, &stop_char, 0); |
| 813 | break; |
| 814 | case ARG_STRING: |
| 815 | if (val) { |
| 816 | string_field = (char **)field; |
| 817 | if (!no_free && *string_field) |
| 818 | free(*string_field); /* free previous string */ |
| 819 | *string_field = gengetopt_strdup(val); |
| 820 | } |
| 821 | break; |
| 822 | default: |
| 823 | break; |
| 824 | }; |
| 825 | |
| 826 | /* check numeric conversion */ |
| 827 | switch (arg_type) { |
| 828 | case ARG_INT: |
| 829 | if (val && !(stop_char && *stop_char == '\0')) { |
| 830 | fprintf(stderr, "%s: invalid numeric value: %s\n", |
| 831 | package_name, val); |
| 832 | return 1; /* failure */ |
| 833 | } |
| 834 | break; |
| 835 | default: |
| 836 | ; |
| 837 | }; |
| 838 | |
| 839 | /* store the original value */ |
| 840 | switch (arg_type) { |
| 841 | case ARG_NO: |
| 842 | case ARG_FLAG: |
| 843 | break; |
| 844 | default: |
| 845 | if (value && orig_field) { |
| 846 | if (no_free) { |
| 847 | *orig_field = value; |
| 848 | } else { |
| 849 | if (*orig_field) |
| 850 | free(*orig_field); /* free previous string */ |
| 851 | *orig_field = gengetopt_strdup(value); |
| 852 | } |
| 853 | } |
| 854 | }; |
| 855 | |
| 856 | return 0; /* OK */ |
| 857 | } |
| 858 | |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 859 | static int check_modes(int given1[], const char *options1[], |
| 860 | int given2[], const char *options2[]) |
| 861 | { |
| 862 | int i = 0, j = 0, errors = 0; |
| 863 | |
| 864 | while (given1[i] >= 0) { |
| 865 | if (given1[i]) { |
| 866 | while (given2[j] >= 0) { |
| 867 | if (given2[j]) { |
| 868 | ++errors; |
| 869 | fprintf(stderr, |
| 870 | "%s: option %s conflicts with option %s\n", |
| 871 | package_name, options1[i], |
| 872 | options2[j]); |
| 873 | } |
| 874 | ++j; |
| 875 | } |
| 876 | } |
| 877 | ++i; |
| 878 | } |
| 879 | |
| 880 | return errors; |
| 881 | } |
| 882 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 883 | int |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 884 | cmdline_parser_internal(int argc, char **argv, |
| 885 | struct gengetopt_args_info *args_info, |
| 886 | struct cmdline_parser_params *params, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 887 | const char *additional_error) |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 888 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 889 | int c; /* Character of the parsed option. */ |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 890 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 891 | int error_occurred = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 892 | struct gengetopt_args_info local_args_info; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 893 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 894 | int override; |
| 895 | int initialize; |
| 896 | int check_required; |
| 897 | int check_ambiguity; |
| 898 | |
| 899 | package_name = argv[0]; |
| 900 | |
| 901 | override = params->override; |
| 902 | initialize = params->initialize; |
| 903 | check_required = params->check_required; |
| 904 | check_ambiguity = params->check_ambiguity; |
| 905 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 906 | if (initialize) |
| 907 | cmdline_parser_init(args_info); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 908 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 909 | cmdline_parser_init(&local_args_info); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 910 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 911 | optarg = 0; |
| 912 | optind = 0; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 913 | opterr = params->print_errors; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 914 | optopt = '?'; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 915 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 916 | while (1) { |
| 917 | int option_index = 0; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 918 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 919 | static struct option long_options[] = { |
| 920 | {"help", 0, NULL, 'h'}, |
| 921 | {"version", 0, NULL, 'V'}, |
| 922 | {"debug", 0, NULL, 'd'}, |
| 923 | {"conf", 1, NULL, 'c'}, |
| 924 | {"pidfile", 1, NULL, 0}, |
| 925 | {"statedir", 1, NULL, 0}, |
| 926 | {"dns", 1, NULL, 0}, |
| 927 | {"listen", 1, NULL, 'l'}, |
| 928 | {"remote", 1, NULL, 'r'}, |
| 929 | {"contexts", 1, NULL, 0}, |
| 930 | {"timelimit", 1, NULL, 0}, |
| 931 | {"gtpversion", 1, NULL, 0}, |
| 932 | {"apn", 1, NULL, 'a'}, |
| 933 | {"selmode", 1, NULL, 0}, |
| 934 | {"rattype", 1, NULL, 0}, |
| 935 | {"userloc", 1, NULL, 0}, |
| 936 | {"rai", 1, NULL, 0}, |
| 937 | {"mstz", 1, NULL, 0}, |
| 938 | {"imeisv", 1, NULL, 0}, |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 939 | {"norecovery", 0, NULL, 0}, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 940 | {"imsi", 1, NULL, 'i'}, |
| 941 | {"nsapi", 1, NULL, 0}, |
| 942 | {"msisdn", 1, NULL, 'm'}, |
| 943 | {"qos", 1, NULL, 'q'}, |
| 944 | {"qose1", 1, NULL, 0}, |
| 945 | {"qose2", 1, NULL, 0}, |
| 946 | {"qose3", 1, NULL, 0}, |
| 947 | {"qose4", 1, NULL, 0}, |
| 948 | {"charging", 1, NULL, 0}, |
| 949 | {"uid", 1, NULL, 'u'}, |
| 950 | {"pwd", 1, NULL, 'p'}, |
| 951 | {"createif", 0, NULL, 0}, |
| 952 | {"net", 1, NULL, 'n'}, |
| 953 | {"defaultroute", 0, NULL, 0}, |
| 954 | {"ipup", 1, NULL, 0}, |
| 955 | {"ipdown", 1, NULL, 0}, |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 956 | {"tun-device", 1, NULL, 0}, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 957 | {"pinghost", 1, NULL, 0}, |
| 958 | {"pingrate", 1, NULL, 0}, |
| 959 | {"pingsize", 1, NULL, 0}, |
| 960 | {"pingcount", 1, NULL, 0}, |
| 961 | {"pingquiet", 0, NULL, 0}, |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 962 | {"no-tx-gpdu-seq", 0, NULL, 0}, |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 963 | {"pdp-type", 1, NULL, 't'}, |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 964 | {0, 0, 0, 0} |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 965 | }; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 966 | |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 967 | c = getopt_long(argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:t:", |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 968 | long_options, &option_index); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 969 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 970 | if (c == -1) |
| 971 | break; /* Exit from `while (1)' loop. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 972 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 973 | switch (c) { |
| 974 | case 'h': /* Print help and exit. */ |
| 975 | cmdline_parser_print_help(); |
| 976 | cmdline_parser_free(&local_args_info); |
| 977 | exit(EXIT_SUCCESS); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 978 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 979 | case 'V': /* Print version and exit. */ |
| 980 | cmdline_parser_print_version(); |
| 981 | cmdline_parser_free(&local_args_info); |
| 982 | exit(EXIT_SUCCESS); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 983 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 984 | case 'd': /* Run in debug mode. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 985 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 986 | if (update_arg |
| 987 | ((void *)&(args_info->debug_flag), 0, |
| 988 | &(args_info->debug_given), |
| 989 | &(local_args_info.debug_given), optarg, 0, 0, |
| 990 | ARG_FLAG, check_ambiguity, override, 1, 0, "debug", |
| 991 | 'd', additional_error)) |
| 992 | goto failure; |
| 993 | |
| 994 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 995 | case 'c': /* Read configuration file. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 996 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 997 | if (update_arg((void *)&(args_info->conf_arg), |
| 998 | &(args_info->conf_orig), |
| 999 | &(args_info->conf_given), |
| 1000 | &(local_args_info.conf_given), optarg, 0, |
| 1001 | 0, ARG_STRING, check_ambiguity, override, |
| 1002 | 0, 0, "conf", 'c', additional_error)) |
| 1003 | goto failure; |
| 1004 | |
| 1005 | break; |
Pau Espin Pedrol | 5fdda13 | 2018-02-12 18:03:09 +0100 | [diff] [blame] | 1006 | case 'l': /* Local host. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1007 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1008 | if (update_arg((void *)&(args_info->listen_arg), |
| 1009 | &(args_info->listen_orig), |
| 1010 | &(args_info->listen_given), |
| 1011 | &(local_args_info.listen_given), optarg, |
| 1012 | 0, 0, ARG_STRING, check_ambiguity, |
| 1013 | override, 0, 0, "listen", 'l', |
| 1014 | additional_error)) |
| 1015 | goto failure; |
| 1016 | |
| 1017 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1018 | case 'r': /* Remote host. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1019 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1020 | if (update_arg((void *)&(args_info->remote_arg), |
| 1021 | &(args_info->remote_orig), |
| 1022 | &(args_info->remote_given), |
| 1023 | &(local_args_info.remote_given), optarg, |
| 1024 | 0, 0, ARG_STRING, check_ambiguity, |
| 1025 | override, 0, 0, "remote", 'r', |
| 1026 | additional_error)) |
| 1027 | goto failure; |
| 1028 | |
| 1029 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1030 | case 'a': /* Access point name. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1031 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1032 | if (update_arg((void *)&(args_info->apn_arg), |
| 1033 | &(args_info->apn_orig), |
| 1034 | &(args_info->apn_given), |
| 1035 | &(local_args_info.apn_given), optarg, 0, |
| 1036 | "internet", ARG_STRING, check_ambiguity, |
| 1037 | override, 0, 0, "apn", 'a', |
| 1038 | additional_error)) |
| 1039 | goto failure; |
| 1040 | |
| 1041 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1042 | case 'i': /* IMSI. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1043 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1044 | if (update_arg((void *)&(args_info->imsi_arg), |
| 1045 | &(args_info->imsi_orig), |
| 1046 | &(args_info->imsi_given), |
| 1047 | &(local_args_info.imsi_given), optarg, 0, |
| 1048 | "240010123456789", ARG_STRING, |
| 1049 | check_ambiguity, override, 0, 0, "imsi", |
| 1050 | 'i', additional_error)) |
| 1051 | goto failure; |
| 1052 | |
| 1053 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1054 | case 'm': /* Mobile Station ISDN number. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1055 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1056 | if (update_arg((void *)&(args_info->msisdn_arg), |
| 1057 | &(args_info->msisdn_orig), |
| 1058 | &(args_info->msisdn_given), |
| 1059 | &(local_args_info.msisdn_given), optarg, |
| 1060 | 0, "46702123456", ARG_STRING, |
| 1061 | check_ambiguity, override, 0, 0, |
| 1062 | "msisdn", 'm', additional_error)) |
| 1063 | goto failure; |
| 1064 | |
| 1065 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1066 | case 'q': /* Requested quality of service. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1067 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1068 | if (update_arg((void *)&(args_info->qos_arg), |
| 1069 | &(args_info->qos_orig), |
| 1070 | &(args_info->qos_given), |
| 1071 | &(local_args_info.qos_given), optarg, 0, |
| 1072 | "0x000b921f", ARG_INT, check_ambiguity, |
| 1073 | override, 0, 0, "qos", 'q', |
| 1074 | additional_error)) |
| 1075 | goto failure; |
| 1076 | |
| 1077 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1078 | case 'u': /* Login user ID. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1079 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1080 | if (update_arg((void *)&(args_info->uid_arg), |
| 1081 | &(args_info->uid_orig), |
| 1082 | &(args_info->uid_given), |
| 1083 | &(local_args_info.uid_given), optarg, 0, |
| 1084 | "mig", ARG_STRING, check_ambiguity, |
| 1085 | override, 0, 0, "uid", 'u', |
| 1086 | additional_error)) |
| 1087 | goto failure; |
| 1088 | |
| 1089 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1090 | case 'p': /* Login password. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1091 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1092 | if (update_arg((void *)&(args_info->pwd_arg), |
| 1093 | &(args_info->pwd_orig), |
| 1094 | &(args_info->pwd_given), |
| 1095 | &(local_args_info.pwd_given), optarg, 0, |
| 1096 | "hemmelig", ARG_STRING, check_ambiguity, |
| 1097 | override, 0, 0, "pwd", 'p', |
| 1098 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1099 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1100 | |
| 1101 | break; |
| 1102 | case 'n': /* Network address for local interface. */ |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1103 | args_info->createif_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1104 | |
| 1105 | if (update_arg((void *)&(args_info->net_arg), |
| 1106 | &(args_info->net_orig), |
| 1107 | &(args_info->net_given), |
| 1108 | &(local_args_info.net_given), optarg, 0, |
| 1109 | 0, ARG_STRING, check_ambiguity, override, |
| 1110 | 0, 0, "net", 'n', additional_error)) |
| 1111 | goto failure; |
| 1112 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1113 | break; |
Harald Welte | 840a8e9 | 2017-09-24 18:12:40 +0800 | [diff] [blame] | 1114 | case 't': /* PDP Type. */ |
| 1115 | |
| 1116 | if (update_arg((void *)&(args_info->pdp_type_arg), |
| 1117 | &(args_info->pdp_type_orig), |
| 1118 | &(args_info->pdp_type_given), |
| 1119 | &(local_args_info.pdp_type_given), |
| 1120 | optarg, 0, "v4", ARG_STRING, |
| 1121 | check_ambiguity, override, 0, 0, |
| 1122 | "pdp-type", 't', additional_error)) |
| 1123 | goto failure; |
| 1124 | |
| 1125 | break; |
jjako | 193e8b1 | 2003-11-10 12:31:41 +0000 | [diff] [blame] | 1126 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1127 | case 0: /* Long option with no short option */ |
| 1128 | /* Filename of process id file. */ |
| 1129 | if (strcmp(long_options[option_index].name, "pidfile") |
| 1130 | == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1131 | |
| 1132 | if (update_arg |
| 1133 | ((void *)&(args_info->pidfile_arg), |
| 1134 | &(args_info->pidfile_orig), |
| 1135 | &(args_info->pidfile_given), |
| 1136 | &(local_args_info.pidfile_given), optarg, |
| 1137 | 0, "./sgsnemu.pid", ARG_STRING, |
| 1138 | check_ambiguity, override, 0, 0, "pidfile", |
| 1139 | '-', additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1140 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1141 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1142 | } |
| 1143 | /* Directory of nonvolatile data. */ |
| 1144 | else if (strcmp |
| 1145 | (long_options[option_index].name, |
| 1146 | "statedir") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1147 | |
| 1148 | if (update_arg |
| 1149 | ((void *)&(args_info->statedir_arg), |
| 1150 | &(args_info->statedir_orig), |
| 1151 | &(args_info->statedir_given), |
| 1152 | &(local_args_info.statedir_given), optarg, |
| 1153 | 0, "./", ARG_STRING, check_ambiguity, |
| 1154 | override, 0, 0, "statedir", '-', |
| 1155 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1156 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1157 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1158 | } |
| 1159 | /* DNS Server to use. */ |
| 1160 | else if (strcmp(long_options[option_index].name, "dns") |
| 1161 | == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1162 | |
| 1163 | if (update_arg((void *)&(args_info->dns_arg), |
| 1164 | &(args_info->dns_orig), |
| 1165 | &(args_info->dns_given), |
| 1166 | &(local_args_info.dns_given), |
| 1167 | optarg, 0, 0, ARG_STRING, |
| 1168 | check_ambiguity, override, 0, 0, |
| 1169 | "dns", '-', additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1170 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1171 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1172 | } |
| 1173 | /* Number of contexts. */ |
| 1174 | else if (strcmp |
| 1175 | (long_options[option_index].name, |
| 1176 | "contexts") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1177 | |
| 1178 | if (update_arg |
| 1179 | ((void *)&(args_info->contexts_arg), |
| 1180 | &(args_info->contexts_orig), |
| 1181 | &(args_info->contexts_given), |
| 1182 | &(local_args_info.contexts_given), optarg, |
| 1183 | 0, "1", ARG_INT, check_ambiguity, override, |
| 1184 | 0, 0, "contexts", '-', additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1185 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1186 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1187 | } |
| 1188 | /* Exit after timelimit seconds. */ |
| 1189 | else if (strcmp |
| 1190 | (long_options[option_index].name, |
| 1191 | "timelimit") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1192 | |
| 1193 | if (update_arg |
| 1194 | ((void *)&(args_info->timelimit_arg), |
| 1195 | &(args_info->timelimit_orig), |
| 1196 | &(args_info->timelimit_given), |
| 1197 | &(local_args_info.timelimit_given), optarg, |
| 1198 | 0, "0", ARG_INT, check_ambiguity, override, |
| 1199 | 0, 0, "timelimit", '-', additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1200 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1201 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1202 | } |
| 1203 | /* GTP version to use. */ |
| 1204 | else if (strcmp |
| 1205 | (long_options[option_index].name, |
| 1206 | "gtpversion") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1207 | |
| 1208 | if (update_arg |
| 1209 | ((void *)&(args_info->gtpversion_arg), |
| 1210 | &(args_info->gtpversion_orig), |
| 1211 | &(args_info->gtpversion_given), |
| 1212 | &(local_args_info.gtpversion_given), |
| 1213 | optarg, 0, "1", ARG_INT, check_ambiguity, |
| 1214 | override, 0, 0, "gtpversion", '-', |
| 1215 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1216 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1217 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1218 | } |
| 1219 | /* Selection mode. */ |
| 1220 | else if (strcmp |
| 1221 | (long_options[option_index].name, |
| 1222 | "selmode") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1223 | |
| 1224 | if (update_arg |
| 1225 | ((void *)&(args_info->selmode_arg), |
| 1226 | &(args_info->selmode_orig), |
| 1227 | &(args_info->selmode_given), |
| 1228 | &(local_args_info.selmode_given), optarg, |
| 1229 | 0, "0x01", ARG_INT, check_ambiguity, |
| 1230 | override, 0, 0, "selmode", '-', |
| 1231 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1232 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1233 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1234 | } |
| 1235 | /* Radio Access Technology Type. */ |
| 1236 | else if (strcmp |
| 1237 | (long_options[option_index].name, |
| 1238 | "rattype") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1239 | |
| 1240 | if (update_arg |
| 1241 | ((void *)&(args_info->rattype_arg), |
| 1242 | &(args_info->rattype_orig), |
| 1243 | &(args_info->rattype_given), |
| 1244 | &(local_args_info.rattype_given), optarg, |
| 1245 | 0, "1", ARG_INT, check_ambiguity, override, |
| 1246 | 0, 0, "rattype", '-', additional_error)) |
| 1247 | goto failure; |
| 1248 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1249 | } |
| 1250 | /* User Location Information. */ |
| 1251 | else if (strcmp |
| 1252 | (long_options[option_index].name, |
| 1253 | "userloc") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1254 | |
| 1255 | if (update_arg |
| 1256 | ((void *)&(args_info->userloc_arg), |
| 1257 | &(args_info->userloc_orig), |
| 1258 | &(args_info->userloc_given), |
| 1259 | &(local_args_info.userloc_given), optarg, |
| 1260 | 0, "02509946241207", ARG_STRING, |
| 1261 | check_ambiguity, override, 0, 0, "userloc", |
| 1262 | '-', additional_error)) |
| 1263 | goto failure; |
| 1264 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1265 | } |
| 1266 | /* Routing Area Information. */ |
| 1267 | else if (strcmp(long_options[option_index].name, "rai") |
| 1268 | == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1269 | |
| 1270 | if (update_arg((void *)&(args_info->rai_arg), |
| 1271 | &(args_info->rai_orig), |
| 1272 | &(args_info->rai_given), |
| 1273 | &(local_args_info.rai_given), |
| 1274 | optarg, 0, "02509946241207", |
| 1275 | ARG_STRING, check_ambiguity, |
| 1276 | override, 0, 0, "rai", '-', |
| 1277 | additional_error)) |
| 1278 | goto failure; |
| 1279 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1280 | } |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1281 | /* MS Time Zone. */ |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1282 | else if (strcmp(long_options[option_index].name, "mstz") |
| 1283 | == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1284 | |
| 1285 | if (update_arg((void *)&(args_info->mstz_arg), |
| 1286 | &(args_info->mstz_orig), |
| 1287 | &(args_info->mstz_given), |
| 1288 | &(local_args_info.mstz_given), |
| 1289 | optarg, 0, "0", ARG_STRING, |
| 1290 | check_ambiguity, override, 0, 0, |
| 1291 | "mstz", '-', additional_error)) |
| 1292 | goto failure; |
| 1293 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1294 | } |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1295 | /* IMEI(SV) International Mobile Equipment Identity (and Software Version). */ |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1296 | else if (strcmp |
| 1297 | (long_options[option_index].name, |
| 1298 | "imeisv") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1299 | |
| 1300 | if (update_arg((void *)&(args_info->imeisv_arg), |
| 1301 | &(args_info->imeisv_orig), |
| 1302 | &(args_info->imeisv_given), |
| 1303 | &(local_args_info.imeisv_given), |
| 1304 | optarg, 0, "2143658709214365", |
| 1305 | ARG_STRING, check_ambiguity, |
| 1306 | override, 0, 0, "imeisv", '-', |
| 1307 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1308 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1309 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1310 | } |
| 1311 | /* Do not send recovery. */ |
| 1312 | else if (strcmp |
| 1313 | (long_options[option_index].name, |
| 1314 | "norecovery") == 0) { |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1315 | |
| 1316 | if (update_arg |
| 1317 | ((void *)&(args_info->norecovery_flag), 0, |
| 1318 | &(args_info->norecovery_given), |
| 1319 | &(local_args_info.norecovery_given), |
| 1320 | optarg, 0, 0, ARG_FLAG, check_ambiguity, |
| 1321 | override, 1, 0, "norecovery", '-', |
| 1322 | additional_error)) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1323 | goto failure; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1324 | |
| 1325 | } |
| 1326 | /* NSAPI. */ |
| 1327 | else if (strcmp |
| 1328 | (long_options[option_index].name, |
| 1329 | "nsapi") == 0) { |
| 1330 | |
| 1331 | if (update_arg((void *)&(args_info->nsapi_arg), |
| 1332 | &(args_info->nsapi_orig), |
| 1333 | &(args_info->nsapi_given), |
| 1334 | &(local_args_info.nsapi_given), |
| 1335 | optarg, 0, "0", ARG_INT, |
| 1336 | check_ambiguity, override, 0, 0, |
| 1337 | "nsapi", '-', additional_error)) |
| 1338 | goto failure; |
| 1339 | |
| 1340 | } |
| 1341 | /* Requested quality of service Extension 1. */ |
| 1342 | else if (strcmp |
| 1343 | (long_options[option_index].name, |
| 1344 | "qose1") == 0) { |
| 1345 | |
| 1346 | if (update_arg((void *)&(args_info->qose1_arg), |
| 1347 | &(args_info->qose1_orig), |
| 1348 | &(args_info->qose1_given), |
| 1349 | &(local_args_info.qose1_given), |
| 1350 | optarg, 0, "0x9396404074f9ffff", |
| 1351 | ARG_INT, check_ambiguity, |
| 1352 | override, 0, 0, "qose1", '-', |
| 1353 | additional_error)) |
| 1354 | goto failure; |
| 1355 | |
| 1356 | } |
| 1357 | /* Requested quality of service Extension 2. */ |
| 1358 | else if (strcmp |
| 1359 | (long_options[option_index].name, |
| 1360 | "qose2") == 0) { |
| 1361 | |
| 1362 | if (update_arg((void *)&(args_info->qose2_arg), |
| 1363 | &(args_info->qose2_orig), |
| 1364 | &(args_info->qose2_given), |
| 1365 | &(local_args_info.qose2_given), |
| 1366 | optarg, 0, "0x11", ARG_INT, |
| 1367 | check_ambiguity, override, 0, 0, |
| 1368 | "qose2", '-', additional_error)) |
| 1369 | goto failure; |
| 1370 | |
| 1371 | } |
| 1372 | /* Requested quality of service Extension 3. */ |
| 1373 | else if (strcmp |
| 1374 | (long_options[option_index].name, |
| 1375 | "qose3") == 0) { |
| 1376 | |
| 1377 | if (update_arg((void *)&(args_info->qose3_arg), |
| 1378 | &(args_info->qose3_orig), |
| 1379 | &(args_info->qose3_given), |
| 1380 | &(local_args_info.qose3_given), |
| 1381 | optarg, 0, "0x0101", ARG_INT, |
| 1382 | check_ambiguity, override, 0, 0, |
| 1383 | "qose3", '-', additional_error)) |
| 1384 | goto failure; |
| 1385 | |
| 1386 | } |
| 1387 | /* Requested quality of service Extension 4. */ |
| 1388 | else if (strcmp |
| 1389 | (long_options[option_index].name, |
| 1390 | "qose4") == 0) { |
| 1391 | |
| 1392 | if (update_arg((void *)&(args_info->qose4_arg), |
| 1393 | &(args_info->qose4_orig), |
| 1394 | &(args_info->qose4_given), |
| 1395 | &(local_args_info.qose4_given), |
| 1396 | optarg, 0, "0x4040", ARG_INT, |
| 1397 | check_ambiguity, override, 0, 0, |
| 1398 | "qose4", '-', additional_error)) |
| 1399 | goto failure; |
| 1400 | |
| 1401 | } |
| 1402 | /* Charging characteristics. */ |
| 1403 | else if (strcmp |
| 1404 | (long_options[option_index].name, |
| 1405 | "charging") == 0) { |
| 1406 | |
| 1407 | if (update_arg |
| 1408 | ((void *)&(args_info->charging_arg), |
| 1409 | &(args_info->charging_orig), |
| 1410 | &(args_info->charging_given), |
| 1411 | &(local_args_info.charging_given), optarg, |
| 1412 | 0, "0x0800", ARG_INT, check_ambiguity, |
| 1413 | override, 0, 0, "charging", '-', |
| 1414 | additional_error)) |
| 1415 | goto failure; |
| 1416 | |
| 1417 | } |
| 1418 | /* Create local network interface. */ |
| 1419 | else if (strcmp |
| 1420 | (long_options[option_index].name, |
| 1421 | "createif") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1422 | args_info->createif_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1423 | |
| 1424 | if (update_arg |
| 1425 | ((void *)&(args_info->createif_flag), 0, |
| 1426 | &(args_info->createif_given), |
| 1427 | &(local_args_info.createif_given), optarg, |
| 1428 | 0, 0, ARG_FLAG, check_ambiguity, override, |
| 1429 | 1, 0, "createif", '-', additional_error)) |
| 1430 | goto failure; |
| 1431 | |
| 1432 | } |
| 1433 | /* Create default route. */ |
| 1434 | else if (strcmp |
| 1435 | (long_options[option_index].name, |
| 1436 | "defaultroute") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1437 | args_info->createif_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1438 | |
| 1439 | if (update_arg |
| 1440 | ((void *)&(args_info->defaultroute_flag), 0, |
| 1441 | &(args_info->defaultroute_given), |
| 1442 | &(local_args_info.defaultroute_given), |
| 1443 | optarg, 0, 0, ARG_FLAG, check_ambiguity, |
| 1444 | override, 1, 0, "defaultroute", '-', |
| 1445 | additional_error)) |
| 1446 | goto failure; |
| 1447 | |
| 1448 | } |
| 1449 | /* Script to run after link-up. */ |
| 1450 | else if (strcmp(long_options[option_index].name, "ipup") |
| 1451 | == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1452 | args_info->createif_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1453 | |
| 1454 | if (update_arg((void *)&(args_info->ipup_arg), |
| 1455 | &(args_info->ipup_orig), |
| 1456 | &(args_info->ipup_given), |
| 1457 | &(local_args_info.ipup_given), |
| 1458 | optarg, 0, 0, ARG_STRING, |
| 1459 | check_ambiguity, override, 0, 0, |
| 1460 | "ipup", '-', additional_error)) |
| 1461 | goto failure; |
| 1462 | |
| 1463 | } |
| 1464 | /* Script to run after link-down. */ |
| 1465 | else if (strcmp |
| 1466 | (long_options[option_index].name, |
| 1467 | "ipdown") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1468 | args_info->createif_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1469 | |
| 1470 | if (update_arg((void *)&(args_info->ipdown_arg), |
| 1471 | &(args_info->ipdown_orig), |
| 1472 | &(args_info->ipdown_given), |
| 1473 | &(local_args_info.ipdown_given), |
| 1474 | optarg, 0, 0, ARG_STRING, |
| 1475 | check_ambiguity, override, 0, 0, |
| 1476 | "ipdown", '-', additional_error)) |
| 1477 | goto failure; |
| 1478 | |
| 1479 | } |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 1480 | /* Name of the local network interface. */ |
| 1481 | else if (strcmp |
| 1482 | (long_options[option_index].name, |
| 1483 | "tun-device") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1484 | args_info->createif_mode_counter += 1; |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 1485 | |
| 1486 | if (update_arg |
| 1487 | ((void *)&(args_info->tun_device_arg), |
| 1488 | &(args_info->tun_device_orig), |
| 1489 | &(args_info->tun_device_given), |
| 1490 | &(local_args_info.tun_device_given), |
| 1491 | optarg, 0, 0, ARG_STRING, check_ambiguity, |
| 1492 | override, 0, 0, "tun-device", '-', |
| 1493 | additional_error)) |
| 1494 | goto failure; |
| 1495 | |
| 1496 | } |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1497 | /* Ping remote host. */ |
| 1498 | else if (strcmp |
| 1499 | (long_options[option_index].name, |
| 1500 | "pinghost") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1501 | args_info->pinghost_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1502 | |
| 1503 | if (update_arg |
| 1504 | ((void *)&(args_info->pinghost_arg), |
| 1505 | &(args_info->pinghost_orig), |
| 1506 | &(args_info->pinghost_given), |
| 1507 | &(local_args_info.pinghost_given), optarg, |
| 1508 | 0, 0, ARG_STRING, check_ambiguity, |
| 1509 | override, 0, 0, "pinghost", '-', |
| 1510 | additional_error)) |
| 1511 | goto failure; |
| 1512 | |
| 1513 | } |
| 1514 | /* Number of ping req per second. */ |
| 1515 | else if (strcmp |
| 1516 | (long_options[option_index].name, |
| 1517 | "pingrate") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1518 | args_info->pinghost_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1519 | |
| 1520 | if (update_arg |
| 1521 | ((void *)&(args_info->pingrate_arg), |
| 1522 | &(args_info->pingrate_orig), |
| 1523 | &(args_info->pingrate_given), |
| 1524 | &(local_args_info.pingrate_given), optarg, |
| 1525 | 0, "1", ARG_INT, check_ambiguity, override, |
| 1526 | 0, 0, "pingrate", '-', additional_error)) |
| 1527 | goto failure; |
| 1528 | |
| 1529 | } |
| 1530 | /* Number of ping data bytes. */ |
| 1531 | else if (strcmp |
| 1532 | (long_options[option_index].name, |
| 1533 | "pingsize") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1534 | args_info->pinghost_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1535 | |
| 1536 | if (update_arg |
| 1537 | ((void *)&(args_info->pingsize_arg), |
| 1538 | &(args_info->pingsize_orig), |
| 1539 | &(args_info->pingsize_given), |
| 1540 | &(local_args_info.pingsize_given), optarg, |
| 1541 | 0, "56", ARG_INT, check_ambiguity, |
| 1542 | override, 0, 0, "pingsize", '-', |
| 1543 | additional_error)) |
| 1544 | goto failure; |
| 1545 | |
| 1546 | } |
| 1547 | /* Number of ping req to send. */ |
| 1548 | else if (strcmp |
| 1549 | (long_options[option_index].name, |
| 1550 | "pingcount") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1551 | args_info->pinghost_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1552 | |
| 1553 | if (update_arg |
| 1554 | ((void *)&(args_info->pingcount_arg), |
| 1555 | &(args_info->pingcount_orig), |
| 1556 | &(args_info->pingcount_given), |
| 1557 | &(local_args_info.pingcount_given), optarg, |
| 1558 | 0, "0", ARG_INT, check_ambiguity, override, |
| 1559 | 0, 0, "pingcount", '-', additional_error)) |
| 1560 | goto failure; |
| 1561 | |
| 1562 | } |
| 1563 | /* Do not print ping packet info. */ |
| 1564 | else if (strcmp |
| 1565 | (long_options[option_index].name, |
| 1566 | "pingquiet") == 0) { |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1567 | args_info->pinghost_mode_counter += 1; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1568 | |
| 1569 | if (update_arg |
| 1570 | ((void *)&(args_info->pingquiet_flag), 0, |
| 1571 | &(args_info->pingquiet_given), |
| 1572 | &(local_args_info.pingquiet_given), optarg, |
| 1573 | 0, 0, ARG_FLAG, check_ambiguity, override, |
| 1574 | 1, 0, "pingquiet", '-', additional_error)) |
| 1575 | goto failure; |
| 1576 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1577 | } |
Harald Welte | fbb9c7f | 2017-09-24 11:50:20 +0800 | [diff] [blame] | 1578 | /* Don't transmit G-PDU sequence nums. */ |
| 1579 | else if (strcmp |
| 1580 | (long_options[option_index].name, |
| 1581 | "no-tx-gpdu-seq") == 0) { |
| 1582 | |
| 1583 | if (update_arg |
| 1584 | ((void *)&(args_info->no_tx_gpdu_seq_flag), |
| 1585 | 0, &(args_info->no_tx_gpdu_seq_given), |
| 1586 | &(local_args_info.no_tx_gpdu_seq_given), |
| 1587 | optarg, 0, 0, ARG_FLAG, check_ambiguity, |
| 1588 | override, 1, 0, "no-tx-gpdu-seq", '-', |
| 1589 | additional_error)) |
| 1590 | goto failure; |
| 1591 | |
| 1592 | } |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1593 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1594 | break; |
| 1595 | case '?': /* Invalid option. */ |
| 1596 | /* `getopt_long' already printed an error message. */ |
| 1597 | goto failure; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1598 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1599 | default: /* bug: option not considered. */ |
| 1600 | fprintf(stderr, "%s: option unknown: %c%s\n", |
| 1601 | CMDLINE_PARSER_PACKAGE, c, |
| 1602 | (additional_error ? additional_error : "")); |
| 1603 | abort(); |
| 1604 | } /* switch */ |
| 1605 | } /* while */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1606 | |
Viktor Tsymbalyuk | ab4db10 | 2018-01-30 14:40:12 +0200 | [diff] [blame] | 1607 | if (args_info->createif_mode_counter |
| 1608 | && args_info->pinghost_mode_counter) { |
| 1609 | int createif_given[] = |
| 1610 | { args_info->createif_given, args_info->net_given, |
| 1611 | args_info->defaultroute_given, args_info->ipup_given, |
| 1612 | args_info->ipdown_given, args_info->tun_device_given, -1 |
| 1613 | }; |
| 1614 | const char *createif_desc[] = |
| 1615 | { "--createif", "--net", "--defaultroute", "--ipup", |
| 1616 | "--ipdown", "--tun-device", 0 |
| 1617 | }; |
| 1618 | int pinghost_given[] = |
| 1619 | { args_info->pinghost_given, args_info->pingrate_given, |
| 1620 | args_info->pingsize_given, args_info->pingcount_given, |
| 1621 | args_info->pingquiet_given, -1 |
| 1622 | }; |
| 1623 | const char *pinghost_desc[] = |
| 1624 | { "--pinghost", "--pingrate", "--pingsize", "--pingcount", |
| 1625 | "--pingquiet", 0 |
| 1626 | }; |
| 1627 | error_occurred += |
| 1628 | check_modes(createif_given, createif_desc, pinghost_given, |
| 1629 | pinghost_desc); |
| 1630 | } |
| 1631 | |
Harald Welte | 73abc38 | 2017-10-10 08:50:11 +0800 | [diff] [blame] | 1632 | if (check_required) { |
| 1633 | error_occurred += |
| 1634 | cmdline_parser_required2(args_info, argv[0], |
| 1635 | additional_error); |
| 1636 | } |
| 1637 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1638 | cmdline_parser_release(&local_args_info); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1639 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1640 | if (error_occurred) |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1641 | return (EXIT_FAILURE); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1642 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1643 | return 0; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1644 | |
| 1645 | failure: |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1646 | |
| 1647 | cmdline_parser_release(&local_args_info); |
| 1648 | return (EXIT_FAILURE); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1651 | #ifndef CONFIG_FILE_LINE_SIZE |
| 1652 | #define CONFIG_FILE_LINE_SIZE 2048 |
| 1653 | #endif |
| 1654 | #define ADDITIONAL_ERROR " in configuration file " |
| 1655 | |
| 1656 | #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) |
| 1657 | /* 3 is for "--" and "=" */ |
| 1658 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1659 | static int _cmdline_parser_configfile(const char *filename, int *my_argc) |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1660 | { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1661 | FILE *file; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1662 | char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE + 1]; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1663 | char linebuf[CONFIG_FILE_LINE_SIZE]; |
| 1664 | int line_num = 0; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1665 | int result = 0, equal; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1666 | char *fopt, *farg; |
| 1667 | char *str_index; |
| 1668 | size_t len, next_token; |
| 1669 | char delimiter; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1670 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1671 | if ((file = fopen(filename, "r")) == 0) { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1672 | fprintf(stderr, "%s: Error opening configuration file '%s'\n", |
| 1673 | CMDLINE_PARSER_PACKAGE, filename); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1674 | return EXIT_FAILURE; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1675 | } |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1676 | |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1677 | while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1678 | ++line_num; |
| 1679 | my_argv[0] = '\0'; |
| 1680 | len = strlen(linebuf); |
| 1681 | if (len > (CONFIG_FILE_LINE_BUFFER_SIZE - 1)) { |
| 1682 | fprintf(stderr, |
| 1683 | "%s:%s:%d: Line too long in configuration file\n", |
| 1684 | CMDLINE_PARSER_PACKAGE, filename, line_num); |
| 1685 | result = EXIT_FAILURE; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1686 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1687 | } |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1688 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1689 | /* find first non-whitespace character in the line */ |
| 1690 | next_token = strspn(linebuf, " \t\r\n"); |
| 1691 | str_index = linebuf + next_token; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1692 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1693 | if (str_index[0] == '\0' || str_index[0] == '#') |
| 1694 | continue; /* empty line or comment line is skipped */ |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1695 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1696 | fopt = str_index; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1697 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1698 | /* truncate fopt at the end of the first non-valid character */ |
| 1699 | next_token = strcspn(fopt, " \t\r\n="); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1700 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1701 | if (fopt[next_token] == '\0') { /* the line is over */ |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1702 | farg = 0; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1703 | equal = 0; |
| 1704 | goto noarg; |
| 1705 | } |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1706 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1707 | /* remember if equal sign is present */ |
| 1708 | equal = (fopt[next_token] == '='); |
| 1709 | fopt[next_token++] = '\0'; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1710 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1711 | /* advance pointers to the next token after the end of fopt */ |
| 1712 | next_token += strspn(fopt + next_token, " \t\r\n"); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1713 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1714 | /* check for the presence of equal sign, and if so, skip it */ |
| 1715 | if (!equal) |
| 1716 | if ((equal = (fopt[next_token] == '='))) { |
| 1717 | next_token++; |
| 1718 | next_token += |
| 1719 | strspn(fopt + next_token, " \t\r\n"); |
| 1720 | } |
| 1721 | str_index += next_token; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1722 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1723 | /* find argument */ |
| 1724 | farg = str_index; |
| 1725 | if (farg[0] == '\"' || farg[0] == '\'') { /* quoted argument */ |
| 1726 | str_index = strchr(++farg, str_index[0]); /* skip opening quote */ |
| 1727 | if (!str_index) { |
| 1728 | fprintf |
| 1729 | (stderr, |
| 1730 | "%s:%s:%d: unterminated string in configuration file\n", |
| 1731 | CMDLINE_PARSER_PACKAGE, filename, |
| 1732 | line_num); |
| 1733 | result = EXIT_FAILURE; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1734 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1735 | } |
| 1736 | } else { /* read up the remaining part up to a delimiter */ |
| 1737 | next_token = strcspn(farg, " \t\r\n#\'\""); |
| 1738 | str_index += next_token; |
| 1739 | } |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1740 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1741 | /* truncate farg at the delimiter and store it for further check */ |
| 1742 | delimiter = *str_index, *str_index++ = '\0'; |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1743 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1744 | /* everything but comment is illegal at the end of line */ |
| 1745 | if (delimiter != '\0' && delimiter != '#') { |
| 1746 | str_index += strspn(str_index, " \t\r\n"); |
| 1747 | if (*str_index != '\0' && *str_index != '#') { |
| 1748 | fprintf |
| 1749 | (stderr, |
| 1750 | "%s:%s:%d: malformed string in configuration file\n", |
| 1751 | CMDLINE_PARSER_PACKAGE, filename, |
| 1752 | line_num); |
| 1753 | result = EXIT_FAILURE; |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1754 | break; |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1755 | } |
| 1756 | } |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1757 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1758 | noarg: |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1759 | if (!strcmp(fopt, "include")) { |
| 1760 | if (farg && *farg) { |
| 1761 | result = |
| 1762 | _cmdline_parser_configfile(farg, my_argc); |
| 1763 | } else { |
| 1764 | fprintf(stderr, |
| 1765 | "%s:%s:%d: include requires a filename argument.\n", |
| 1766 | CMDLINE_PARSER_PACKAGE, filename, |
| 1767 | line_num); |
| 1768 | } |
| 1769 | continue; |
| 1770 | } |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1771 | len = strlen(fopt); |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1772 | strcat(my_argv, len > 1 ? "--" : "-"); |
| 1773 | strcat(my_argv, fopt); |
| 1774 | if (len > 1 && ((farg && *farg) || equal)) |
| 1775 | strcat(my_argv, "="); |
| 1776 | if (farg && *farg) |
| 1777 | strcat(my_argv, farg); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1778 | ++(*my_argc); |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1779 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1780 | cmd_line_list_tmp = |
| 1781 | (struct line_list *)malloc(sizeof(struct line_list)); |
| 1782 | cmd_line_list_tmp->next = cmd_line_list; |
| 1783 | cmd_line_list = cmd_line_list_tmp; |
| 1784 | cmd_line_list->string_arg = gengetopt_strdup(my_argv); |
| 1785 | } /* while */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1786 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1787 | if (file) |
| 1788 | fclose(file); |
Harald Welte | f621498 | 2017-09-24 10:23:24 +0800 | [diff] [blame] | 1789 | return result; |
| 1790 | } |
| 1791 | |
| 1792 | int |
| 1793 | cmdline_parser_configfile(const char *filename, |
| 1794 | struct gengetopt_args_info *args_info, |
| 1795 | int override, int initialize, int check_required) |
| 1796 | { |
| 1797 | struct cmdline_parser_params params; |
| 1798 | |
| 1799 | params.override = override; |
| 1800 | params.initialize = initialize; |
| 1801 | params.check_required = check_required; |
| 1802 | params.check_ambiguity = 0; |
| 1803 | params.print_errors = 1; |
| 1804 | |
| 1805 | return cmdline_parser_config_file(filename, args_info, ¶ms); |
| 1806 | } |
| 1807 | |
| 1808 | int |
| 1809 | cmdline_parser_config_file(const char *filename, |
| 1810 | struct gengetopt_args_info *args_info, |
| 1811 | struct cmdline_parser_params *params) |
| 1812 | { |
| 1813 | int i, result; |
| 1814 | int my_argc = 1; |
| 1815 | char **my_argv_arg; |
| 1816 | char *additional_error; |
| 1817 | |
| 1818 | /* store the program name */ |
| 1819 | cmd_line_list_tmp = |
| 1820 | (struct line_list *)malloc(sizeof(struct line_list)); |
| 1821 | cmd_line_list_tmp->next = cmd_line_list; |
| 1822 | cmd_line_list = cmd_line_list_tmp; |
| 1823 | cmd_line_list->string_arg = gengetopt_strdup(CMDLINE_PARSER_PACKAGE); |
| 1824 | |
| 1825 | result = _cmdline_parser_configfile(filename, &my_argc); |
| 1826 | |
| 1827 | if (result != EXIT_FAILURE) { |
| 1828 | my_argv_arg = (char **)malloc((my_argc + 1) * sizeof(char *)); |
| 1829 | cmd_line_list_tmp = cmd_line_list; |
| 1830 | |
| 1831 | for (i = my_argc - 1; i >= 0; --i) { |
| 1832 | my_argv_arg[i] = cmd_line_list_tmp->string_arg; |
| 1833 | cmd_line_list_tmp = cmd_line_list_tmp->next; |
| 1834 | } |
| 1835 | |
| 1836 | my_argv_arg[my_argc] = 0; |
| 1837 | |
| 1838 | additional_error = |
| 1839 | (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + |
| 1840 | 1); |
| 1841 | strcpy(additional_error, ADDITIONAL_ERROR); |
| 1842 | strcat(additional_error, filename); |
| 1843 | result = |
| 1844 | cmdline_parser_internal(my_argc, my_argv_arg, args_info, |
| 1845 | params, additional_error); |
| 1846 | |
| 1847 | free(additional_error); |
| 1848 | free(my_argv_arg); |
| 1849 | } |
Harald Welte | 1b3e577 | 2010-05-04 11:13:56 +0200 | [diff] [blame] | 1850 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 1851 | free_cmd_list(); |
| 1852 | if (result == EXIT_FAILURE) { |
| 1853 | cmdline_parser_free(args_info); |
| 1854 | exit(EXIT_FAILURE); |
| 1855 | } |
| 1856 | |
| 1857 | return result; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1858 | } |