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