zopt.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959
  1. /*
  2. File autogenerated by gengetopt version 2.22.6
  3. generated with the following command:
  4. gengetopt -C --no-help --no-version --unamed-opts=SUBNETS -i /home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/zopt.ggo -F /home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/zopt
  5. The developers of gengetopt consider the fixed text that goes in all
  6. gengetopt output files to be in the public domain:
  7. we make no copyright claims on it.
  8. */
  9. /* If we use autoconf. */
  10. #ifdef HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #ifndef FIX_UNUSED
  17. #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
  18. #endif
  19. #include <getopt.h>
  20. #include "/home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/zopt.h"
  21. const char *gengetopt_args_info_purpose = "A fast Internet-wide scanner.";
  22. const char *gengetopt_args_info_usage = "Usage: zmap [OPTIONS]... [SUBNETS]...";
  23. const char *gengetopt_args_info_versiontext = "";
  24. const char *gengetopt_args_info_description = "";
  25. const char *gengetopt_args_info_help[] = {
  26. "Basic arguments:",
  27. " -p, --target-port=port port number to scan (for TCP and UDP scans)",
  28. " -o, --output-file=name Output file",
  29. " -b, --blacklist-file=path File of subnets to exclude, in CIDR notation,\n e.g. 192.168.0.0/16",
  30. " -w, --whitelist-file=path File of subnets to constrain scan to, in CIDR\n notation, e.g. 192.168.0.0/16",
  31. "\nScan options:",
  32. " -r, --rate=pps Set send rate in packets/sec",
  33. " -B, --bandwidth=bps Set send rate in bits/second (supports suffixes\n G, M and K)",
  34. " -n, --max-targets=n Cap number of targets to probe (as a number or\n a percentage of the address space)",
  35. " -t, --max-runtime=ses Cap length of time for sending packets",
  36. " -N, --max-results=n Cap number of results to return",
  37. " -P, --probes=n Number of probes to send to each IP\n (default=`1')",
  38. " -c, --cooldown-time=secs How long to continue receiving after sending\n last probe (default=`8')",
  39. " -e, --seed=n Seed used to select address permutation",
  40. " --retries=n Max number of times to try to send packet if\n send fails (default=`10')",
  41. " -d, --dryrun Don't actually send packets",
  42. " --shards=N Set the total number of shards (default=`1')",
  43. " --shard=n Set which shard this scan is (0 indexed)\n (default=`0')",
  44. "\nNetwork options:",
  45. " -s, --source-port=port|range Source port(s) for scan packets",
  46. " -S, --source-ip=ip|range Source address(es) for scan packets",
  47. " -G, --gateway-mac=addr Specify gateway MAC address",
  48. " --source-mac=addr Source MAC address",
  49. " -i, --interface=name Specify network interface to use",
  50. " -X, --vpn Sends IP packets instead of Ethernet (for VPNs)",
  51. "\nProbe Modules:",
  52. " -M, --probe-module=name Select probe module (default=`tcp_synscan')",
  53. " --probe-args=args Arguments to pass to probe module",
  54. " --list-probe-modules List available probe modules",
  55. "\nData Output:",
  56. " -f, --output-fields=fields Fields that should be output in result set",
  57. " -O, --output-module=name Select output module (default=`default')",
  58. " --output-args=args Arguments to pass to output module",
  59. " --output-filter=filter Specify a filter over the response fields to\n limit what responses get sent to the output\n module",
  60. " --list-output-modules List available output modules",
  61. " --list-output-fields List all fields that can be output by selected\n probe module",
  62. "\nLogging and Metadata:",
  63. " -v, --verbosity=n Level of log detail (0-5) (default=`3')",
  64. " -l, --log-file=name Write log entries to file",
  65. " -L, --log-directory=directory Write log entries to a timestamped file in this\n directory",
  66. " -m, --metadata-file=name Output file for scan metadata (JSON)",
  67. " -u, --status-updates-file=name\n Write scan progress updates to CSV file",
  68. " -q, --quiet Do not print status updates",
  69. " --disable-syslog Disables logging messages to syslog",
  70. " --notes=notes Inject user-specified notes into scan metadata",
  71. " --user-metadata=json Inject user-specified JSON metadata into scan\n metadata",
  72. "\nAdditional options:",
  73. " --marker_encoding=INT Marker to be used to encode destination\n address/checksum (TCP probe module)\n (default=`0')",
  74. " --use_markervalue=INT Use markervalue instead of target IP address\n for encoding (default=`0')",
  75. " --markervalue=STRING Value to be used instead of target IP address\n for encoding (default=`0')",
  76. " --markerbits_value=INT Amount of Bits of the IP address (32 Bit total)\n to be encoded (TCP probe module)\n (default=`0')",
  77. " --markerbits_checksum=INT Amount of Bits of the checksum (32 Bit total)\n to be encoded (TCP probe module)\n (default=`0')",
  78. " --markerbits_dst_small=INT\n Anti-Mitigation (TraCINg): just use destination\n port for encoding. (default=`0')",
  79. " --disable_monitor=INT Disable monitor output. This is intended for\n small scan groups (<100000) (default=`0')",
  80. " -C, --config=filename Read a configuration file, which can specify\n any of these options\n (default=`/etc/zmap/zmap.conf')",
  81. " --max-sendto-failures=n Maximum NIC sendto failures before scan is\n aborted (default=`-1')",
  82. " --min-hitrate=n Minimum hitrate that scan can hit before scan\n is aborted (default=`0.0')",
  83. " -T, --sender-threads=n Threads used to send packets (default=`1')",
  84. " --cores=STRING Comma-separated list of cores to pin to",
  85. " --ignore-invalid-hosts Ignore invalid hosts in whitelist/blacklist\n file",
  86. " -h, --help Print help and exit",
  87. " -V, --version Print version and exit",
  88. "\nExamples:\n zmap -p 80 (scan the Internet for hosts on tcp/80 and output to stdout)\n zmap -N 5 -B 10M -p 80 (find 5 HTTP servers, scanning at 10 Mb/s)\n zmap -p 80 10.0.0.0/8 192.168.0.0/16 -o (scan both subnets on tcp/80)\n zmap -p 80 1.2.3.4 10.0.0.3 (scan 1.2.3.4, 10.0.0.3 on tcp/80)",
  89. 0
  90. };
  91. typedef enum {ARG_NO
  92. , ARG_STRING
  93. , ARG_INT
  94. , ARG_FLOAT
  95. , ARG_LONGLONG
  96. } cmdline_parser_arg_type;
  97. static
  98. void clear_given (struct gengetopt_args_info *args_info);
  99. static
  100. void clear_args (struct gengetopt_args_info *args_info);
  101. static int
  102. cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
  103. struct cmdline_parser_params *params, const char *additional_error);
  104. struct line_list
  105. {
  106. char * string_arg;
  107. struct line_list * next;
  108. };
  109. static struct line_list *cmd_line_list = 0;
  110. static struct line_list *cmd_line_list_tmp = 0;
  111. static void
  112. free_cmd_list(void)
  113. {
  114. /* free the list of a previous call */
  115. if (cmd_line_list)
  116. {
  117. while (cmd_line_list) {
  118. cmd_line_list_tmp = cmd_line_list;
  119. cmd_line_list = cmd_line_list->next;
  120. free (cmd_line_list_tmp->string_arg);
  121. free (cmd_line_list_tmp);
  122. }
  123. }
  124. }
  125. static char *
  126. gengetopt_strdup (const char *s);
  127. static
  128. void clear_given (struct gengetopt_args_info *args_info)
  129. {
  130. args_info->target_port_given = 0 ;
  131. args_info->output_file_given = 0 ;
  132. args_info->blacklist_file_given = 0 ;
  133. args_info->whitelist_file_given = 0 ;
  134. args_info->rate_given = 0 ;
  135. args_info->bandwidth_given = 0 ;
  136. args_info->max_targets_given = 0 ;
  137. args_info->max_runtime_given = 0 ;
  138. args_info->max_results_given = 0 ;
  139. args_info->probes_given = 0 ;
  140. args_info->cooldown_time_given = 0 ;
  141. args_info->seed_given = 0 ;
  142. args_info->retries_given = 0 ;
  143. args_info->dryrun_given = 0 ;
  144. args_info->shards_given = 0 ;
  145. args_info->shard_given = 0 ;
  146. args_info->source_port_given = 0 ;
  147. args_info->source_ip_given = 0 ;
  148. args_info->gateway_mac_given = 0 ;
  149. args_info->source_mac_given = 0 ;
  150. args_info->interface_given = 0 ;
  151. args_info->vpn_given = 0 ;
  152. args_info->probe_module_given = 0 ;
  153. args_info->probe_args_given = 0 ;
  154. args_info->list_probe_modules_given = 0 ;
  155. args_info->output_fields_given = 0 ;
  156. args_info->output_module_given = 0 ;
  157. args_info->output_args_given = 0 ;
  158. args_info->output_filter_given = 0 ;
  159. args_info->list_output_modules_given = 0 ;
  160. args_info->list_output_fields_given = 0 ;
  161. args_info->verbosity_given = 0 ;
  162. args_info->log_file_given = 0 ;
  163. args_info->log_directory_given = 0 ;
  164. args_info->metadata_file_given = 0 ;
  165. args_info->status_updates_file_given = 0 ;
  166. args_info->quiet_given = 0 ;
  167. args_info->disable_syslog_given = 0 ;
  168. args_info->notes_given = 0 ;
  169. args_info->user_metadata_given = 0 ;
  170. args_info->marker_encoding_given = 0 ;
  171. args_info->use_markervalue_given = 0 ;
  172. args_info->markervalue_given = 0 ;
  173. args_info->markerbits_value_given = 0 ;
  174. args_info->markerbits_checksum_given = 0 ;
  175. args_info->markerbits_dst_small_given = 0 ;
  176. args_info->disable_monitor_given = 0 ;
  177. args_info->config_given = 0 ;
  178. args_info->max_sendto_failures_given = 0 ;
  179. args_info->min_hitrate_given = 0 ;
  180. args_info->sender_threads_given = 0 ;
  181. args_info->cores_given = 0 ;
  182. args_info->ignore_invalid_hosts_given = 0 ;
  183. args_info->help_given = 0 ;
  184. args_info->version_given = 0 ;
  185. }
  186. static
  187. void clear_args (struct gengetopt_args_info *args_info)
  188. {
  189. FIX_UNUSED (args_info);
  190. args_info->target_port_orig = NULL;
  191. args_info->output_file_arg = NULL;
  192. args_info->output_file_orig = NULL;
  193. args_info->blacklist_file_arg = NULL;
  194. args_info->blacklist_file_orig = NULL;
  195. args_info->whitelist_file_arg = NULL;
  196. args_info->whitelist_file_orig = NULL;
  197. args_info->rate_orig = NULL;
  198. args_info->bandwidth_arg = NULL;
  199. args_info->bandwidth_orig = NULL;
  200. args_info->max_targets_arg = NULL;
  201. args_info->max_targets_orig = NULL;
  202. args_info->max_runtime_orig = NULL;
  203. args_info->max_results_orig = NULL;
  204. args_info->probes_arg = 1;
  205. args_info->probes_orig = NULL;
  206. args_info->cooldown_time_arg = 8;
  207. args_info->cooldown_time_orig = NULL;
  208. args_info->seed_orig = NULL;
  209. args_info->retries_arg = 10;
  210. args_info->retries_orig = NULL;
  211. args_info->shards_arg = 1;
  212. args_info->shards_orig = NULL;
  213. args_info->shard_arg = 0;
  214. args_info->shard_orig = NULL;
  215. args_info->source_port_arg = NULL;
  216. args_info->source_port_orig = NULL;
  217. args_info->source_ip_arg = NULL;
  218. args_info->source_ip_orig = NULL;
  219. args_info->gateway_mac_arg = NULL;
  220. args_info->gateway_mac_orig = NULL;
  221. args_info->source_mac_arg = NULL;
  222. args_info->source_mac_orig = NULL;
  223. args_info->interface_arg = NULL;
  224. args_info->interface_orig = NULL;
  225. args_info->probe_module_arg = gengetopt_strdup ("tcp_synscan");
  226. args_info->probe_module_orig = NULL;
  227. args_info->probe_args_arg = NULL;
  228. args_info->probe_args_orig = NULL;
  229. args_info->output_fields_arg = NULL;
  230. args_info->output_fields_orig = NULL;
  231. args_info->output_module_arg = gengetopt_strdup ("default");
  232. args_info->output_module_orig = NULL;
  233. args_info->output_args_arg = NULL;
  234. args_info->output_args_orig = NULL;
  235. args_info->output_filter_arg = NULL;
  236. args_info->output_filter_orig = NULL;
  237. args_info->verbosity_arg = 3;
  238. args_info->verbosity_orig = NULL;
  239. args_info->log_file_arg = NULL;
  240. args_info->log_file_orig = NULL;
  241. args_info->log_directory_arg = NULL;
  242. args_info->log_directory_orig = NULL;
  243. args_info->metadata_file_arg = NULL;
  244. args_info->metadata_file_orig = NULL;
  245. args_info->status_updates_file_arg = NULL;
  246. args_info->status_updates_file_orig = NULL;
  247. args_info->notes_arg = NULL;
  248. args_info->notes_orig = NULL;
  249. args_info->user_metadata_arg = NULL;
  250. args_info->user_metadata_orig = NULL;
  251. args_info->marker_encoding_arg = 0;
  252. args_info->marker_encoding_orig = NULL;
  253. args_info->use_markervalue_arg = 0;
  254. args_info->use_markervalue_orig = NULL;
  255. args_info->markervalue_arg = gengetopt_strdup ("0");
  256. args_info->markervalue_orig = NULL;
  257. args_info->markerbits_value_arg = 0;
  258. args_info->markerbits_value_orig = NULL;
  259. args_info->markerbits_checksum_arg = 0;
  260. args_info->markerbits_checksum_orig = NULL;
  261. args_info->markerbits_dst_small_arg = 0;
  262. args_info->markerbits_dst_small_orig = NULL;
  263. args_info->disable_monitor_arg = 0;
  264. args_info->disable_monitor_orig = NULL;
  265. args_info->config_arg = gengetopt_strdup ("/etc/zmap/zmap.conf");
  266. args_info->config_orig = NULL;
  267. args_info->max_sendto_failures_arg = -1;
  268. args_info->max_sendto_failures_orig = NULL;
  269. args_info->min_hitrate_arg = 0.0;
  270. args_info->min_hitrate_orig = NULL;
  271. args_info->sender_threads_arg = 1;
  272. args_info->sender_threads_orig = NULL;
  273. args_info->cores_arg = NULL;
  274. args_info->cores_orig = NULL;
  275. }
  276. static
  277. void init_args_info(struct gengetopt_args_info *args_info)
  278. {
  279. args_info->target_port_help = gengetopt_args_info_help[1] ;
  280. args_info->output_file_help = gengetopt_args_info_help[2] ;
  281. args_info->blacklist_file_help = gengetopt_args_info_help[3] ;
  282. args_info->whitelist_file_help = gengetopt_args_info_help[4] ;
  283. args_info->rate_help = gengetopt_args_info_help[6] ;
  284. args_info->bandwidth_help = gengetopt_args_info_help[7] ;
  285. args_info->max_targets_help = gengetopt_args_info_help[8] ;
  286. args_info->max_runtime_help = gengetopt_args_info_help[9] ;
  287. args_info->max_results_help = gengetopt_args_info_help[10] ;
  288. args_info->probes_help = gengetopt_args_info_help[11] ;
  289. args_info->cooldown_time_help = gengetopt_args_info_help[12] ;
  290. args_info->seed_help = gengetopt_args_info_help[13] ;
  291. args_info->retries_help = gengetopt_args_info_help[14] ;
  292. args_info->dryrun_help = gengetopt_args_info_help[15] ;
  293. args_info->shards_help = gengetopt_args_info_help[16] ;
  294. args_info->shard_help = gengetopt_args_info_help[17] ;
  295. args_info->source_port_help = gengetopt_args_info_help[19] ;
  296. args_info->source_ip_help = gengetopt_args_info_help[20] ;
  297. args_info->gateway_mac_help = gengetopt_args_info_help[21] ;
  298. args_info->source_mac_help = gengetopt_args_info_help[22] ;
  299. args_info->interface_help = gengetopt_args_info_help[23] ;
  300. args_info->vpn_help = gengetopt_args_info_help[24] ;
  301. args_info->probe_module_help = gengetopt_args_info_help[26] ;
  302. args_info->probe_args_help = gengetopt_args_info_help[27] ;
  303. args_info->list_probe_modules_help = gengetopt_args_info_help[28] ;
  304. args_info->output_fields_help = gengetopt_args_info_help[30] ;
  305. args_info->output_module_help = gengetopt_args_info_help[31] ;
  306. args_info->output_args_help = gengetopt_args_info_help[32] ;
  307. args_info->output_filter_help = gengetopt_args_info_help[33] ;
  308. args_info->list_output_modules_help = gengetopt_args_info_help[34] ;
  309. args_info->list_output_fields_help = gengetopt_args_info_help[35] ;
  310. args_info->verbosity_help = gengetopt_args_info_help[37] ;
  311. args_info->log_file_help = gengetopt_args_info_help[38] ;
  312. args_info->log_directory_help = gengetopt_args_info_help[39] ;
  313. args_info->metadata_file_help = gengetopt_args_info_help[40] ;
  314. args_info->status_updates_file_help = gengetopt_args_info_help[41] ;
  315. args_info->quiet_help = gengetopt_args_info_help[42] ;
  316. args_info->disable_syslog_help = gengetopt_args_info_help[43] ;
  317. args_info->notes_help = gengetopt_args_info_help[44] ;
  318. args_info->user_metadata_help = gengetopt_args_info_help[45] ;
  319. args_info->marker_encoding_help = gengetopt_args_info_help[47] ;
  320. args_info->use_markervalue_help = gengetopt_args_info_help[48] ;
  321. args_info->markervalue_help = gengetopt_args_info_help[49] ;
  322. args_info->markerbits_value_help = gengetopt_args_info_help[50] ;
  323. args_info->markerbits_checksum_help = gengetopt_args_info_help[51] ;
  324. args_info->markerbits_dst_small_help = gengetopt_args_info_help[52] ;
  325. args_info->disable_monitor_help = gengetopt_args_info_help[53] ;
  326. args_info->config_help = gengetopt_args_info_help[54] ;
  327. args_info->max_sendto_failures_help = gengetopt_args_info_help[55] ;
  328. args_info->min_hitrate_help = gengetopt_args_info_help[56] ;
  329. args_info->sender_threads_help = gengetopt_args_info_help[57] ;
  330. args_info->cores_help = gengetopt_args_info_help[58] ;
  331. args_info->ignore_invalid_hosts_help = gengetopt_args_info_help[59] ;
  332. args_info->help_help = gengetopt_args_info_help[60] ;
  333. args_info->version_help = gengetopt_args_info_help[61] ;
  334. }
  335. void
  336. cmdline_parser_print_version (void)
  337. {
  338. printf ("%s %s\n",
  339. (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
  340. CMDLINE_PARSER_VERSION);
  341. if (strlen(gengetopt_args_info_versiontext) > 0)
  342. printf("\n%s\n", gengetopt_args_info_versiontext);
  343. }
  344. static void print_help_common(void) {
  345. cmdline_parser_print_version ();
  346. if (strlen(gengetopt_args_info_purpose) > 0)
  347. printf("\n%s\n", gengetopt_args_info_purpose);
  348. if (strlen(gengetopt_args_info_usage) > 0)
  349. printf("\n%s\n", gengetopt_args_info_usage);
  350. printf("\n");
  351. if (strlen(gengetopt_args_info_description) > 0)
  352. printf("%s\n\n", gengetopt_args_info_description);
  353. }
  354. void
  355. cmdline_parser_print_help (void)
  356. {
  357. int i = 0;
  358. print_help_common();
  359. while (gengetopt_args_info_help[i])
  360. printf("%s\n", gengetopt_args_info_help[i++]);
  361. }
  362. void
  363. cmdline_parser_init (struct gengetopt_args_info *args_info)
  364. {
  365. clear_given (args_info);
  366. clear_args (args_info);
  367. init_args_info (args_info);
  368. args_info->inputs = 0;
  369. args_info->inputs_num = 0;
  370. }
  371. void
  372. cmdline_parser_params_init(struct cmdline_parser_params *params)
  373. {
  374. if (params)
  375. {
  376. params->override = 0;
  377. params->initialize = 1;
  378. params->check_required = 1;
  379. params->check_ambiguity = 0;
  380. params->print_errors = 1;
  381. }
  382. }
  383. struct cmdline_parser_params *
  384. cmdline_parser_params_create(void)
  385. {
  386. struct cmdline_parser_params *params =
  387. (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
  388. cmdline_parser_params_init(params);
  389. return params;
  390. }
  391. static void
  392. free_string_field (char **s)
  393. {
  394. if (*s)
  395. {
  396. free (*s);
  397. *s = 0;
  398. }
  399. }
  400. static void
  401. cmdline_parser_release (struct gengetopt_args_info *args_info)
  402. {
  403. unsigned int i;
  404. free_string_field (&(args_info->target_port_orig));
  405. free_string_field (&(args_info->output_file_arg));
  406. free_string_field (&(args_info->output_file_orig));
  407. free_string_field (&(args_info->blacklist_file_arg));
  408. free_string_field (&(args_info->blacklist_file_orig));
  409. free_string_field (&(args_info->whitelist_file_arg));
  410. free_string_field (&(args_info->whitelist_file_orig));
  411. free_string_field (&(args_info->rate_orig));
  412. free_string_field (&(args_info->bandwidth_arg));
  413. free_string_field (&(args_info->bandwidth_orig));
  414. free_string_field (&(args_info->max_targets_arg));
  415. free_string_field (&(args_info->max_targets_orig));
  416. free_string_field (&(args_info->max_runtime_orig));
  417. free_string_field (&(args_info->max_results_orig));
  418. free_string_field (&(args_info->probes_orig));
  419. free_string_field (&(args_info->cooldown_time_orig));
  420. free_string_field (&(args_info->seed_orig));
  421. free_string_field (&(args_info->retries_orig));
  422. free_string_field (&(args_info->shards_orig));
  423. free_string_field (&(args_info->shard_orig));
  424. free_string_field (&(args_info->source_port_arg));
  425. free_string_field (&(args_info->source_port_orig));
  426. free_string_field (&(args_info->source_ip_arg));
  427. free_string_field (&(args_info->source_ip_orig));
  428. free_string_field (&(args_info->gateway_mac_arg));
  429. free_string_field (&(args_info->gateway_mac_orig));
  430. free_string_field (&(args_info->source_mac_arg));
  431. free_string_field (&(args_info->source_mac_orig));
  432. free_string_field (&(args_info->interface_arg));
  433. free_string_field (&(args_info->interface_orig));
  434. free_string_field (&(args_info->probe_module_arg));
  435. free_string_field (&(args_info->probe_module_orig));
  436. free_string_field (&(args_info->probe_args_arg));
  437. free_string_field (&(args_info->probe_args_orig));
  438. free_string_field (&(args_info->output_fields_arg));
  439. free_string_field (&(args_info->output_fields_orig));
  440. free_string_field (&(args_info->output_module_arg));
  441. free_string_field (&(args_info->output_module_orig));
  442. free_string_field (&(args_info->output_args_arg));
  443. free_string_field (&(args_info->output_args_orig));
  444. free_string_field (&(args_info->output_filter_arg));
  445. free_string_field (&(args_info->output_filter_orig));
  446. free_string_field (&(args_info->verbosity_orig));
  447. free_string_field (&(args_info->log_file_arg));
  448. free_string_field (&(args_info->log_file_orig));
  449. free_string_field (&(args_info->log_directory_arg));
  450. free_string_field (&(args_info->log_directory_orig));
  451. free_string_field (&(args_info->metadata_file_arg));
  452. free_string_field (&(args_info->metadata_file_orig));
  453. free_string_field (&(args_info->status_updates_file_arg));
  454. free_string_field (&(args_info->status_updates_file_orig));
  455. free_string_field (&(args_info->notes_arg));
  456. free_string_field (&(args_info->notes_orig));
  457. free_string_field (&(args_info->user_metadata_arg));
  458. free_string_field (&(args_info->user_metadata_orig));
  459. free_string_field (&(args_info->marker_encoding_orig));
  460. free_string_field (&(args_info->use_markervalue_orig));
  461. free_string_field (&(args_info->markervalue_arg));
  462. free_string_field (&(args_info->markervalue_orig));
  463. free_string_field (&(args_info->markerbits_value_orig));
  464. free_string_field (&(args_info->markerbits_checksum_orig));
  465. free_string_field (&(args_info->markerbits_dst_small_orig));
  466. free_string_field (&(args_info->disable_monitor_orig));
  467. free_string_field (&(args_info->config_arg));
  468. free_string_field (&(args_info->config_orig));
  469. free_string_field (&(args_info->max_sendto_failures_orig));
  470. free_string_field (&(args_info->min_hitrate_orig));
  471. free_string_field (&(args_info->sender_threads_orig));
  472. free_string_field (&(args_info->cores_arg));
  473. free_string_field (&(args_info->cores_orig));
  474. for (i = 0; i < args_info->inputs_num; ++i)
  475. free (args_info->inputs [i]);
  476. if (args_info->inputs_num)
  477. free (args_info->inputs);
  478. clear_given (args_info);
  479. }
  480. static void
  481. write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
  482. {
  483. FIX_UNUSED (values);
  484. if (arg) {
  485. fprintf(outfile, "%s=\"%s\"\n", opt, arg);
  486. } else {
  487. fprintf(outfile, "%s\n", opt);
  488. }
  489. }
  490. int
  491. cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
  492. {
  493. int i = 0;
  494. if (!outfile)
  495. {
  496. fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
  497. return EXIT_FAILURE;
  498. }
  499. if (args_info->target_port_given)
  500. write_into_file(outfile, "target-port", args_info->target_port_orig, 0);
  501. if (args_info->output_file_given)
  502. write_into_file(outfile, "output-file", args_info->output_file_orig, 0);
  503. if (args_info->blacklist_file_given)
  504. write_into_file(outfile, "blacklist-file", args_info->blacklist_file_orig, 0);
  505. if (args_info->whitelist_file_given)
  506. write_into_file(outfile, "whitelist-file", args_info->whitelist_file_orig, 0);
  507. if (args_info->rate_given)
  508. write_into_file(outfile, "rate", args_info->rate_orig, 0);
  509. if (args_info->bandwidth_given)
  510. write_into_file(outfile, "bandwidth", args_info->bandwidth_orig, 0);
  511. if (args_info->max_targets_given)
  512. write_into_file(outfile, "max-targets", args_info->max_targets_orig, 0);
  513. if (args_info->max_runtime_given)
  514. write_into_file(outfile, "max-runtime", args_info->max_runtime_orig, 0);
  515. if (args_info->max_results_given)
  516. write_into_file(outfile, "max-results", args_info->max_results_orig, 0);
  517. if (args_info->probes_given)
  518. write_into_file(outfile, "probes", args_info->probes_orig, 0);
  519. if (args_info->cooldown_time_given)
  520. write_into_file(outfile, "cooldown-time", args_info->cooldown_time_orig, 0);
  521. if (args_info->seed_given)
  522. write_into_file(outfile, "seed", args_info->seed_orig, 0);
  523. if (args_info->retries_given)
  524. write_into_file(outfile, "retries", args_info->retries_orig, 0);
  525. if (args_info->dryrun_given)
  526. write_into_file(outfile, "dryrun", 0, 0 );
  527. if (args_info->shards_given)
  528. write_into_file(outfile, "shards", args_info->shards_orig, 0);
  529. if (args_info->shard_given)
  530. write_into_file(outfile, "shard", args_info->shard_orig, 0);
  531. if (args_info->source_port_given)
  532. write_into_file(outfile, "source-port", args_info->source_port_orig, 0);
  533. if (args_info->source_ip_given)
  534. write_into_file(outfile, "source-ip", args_info->source_ip_orig, 0);
  535. if (args_info->gateway_mac_given)
  536. write_into_file(outfile, "gateway-mac", args_info->gateway_mac_orig, 0);
  537. if (args_info->source_mac_given)
  538. write_into_file(outfile, "source-mac", args_info->source_mac_orig, 0);
  539. if (args_info->interface_given)
  540. write_into_file(outfile, "interface", args_info->interface_orig, 0);
  541. if (args_info->vpn_given)
  542. write_into_file(outfile, "vpn", 0, 0 );
  543. if (args_info->probe_module_given)
  544. write_into_file(outfile, "probe-module", args_info->probe_module_orig, 0);
  545. if (args_info->probe_args_given)
  546. write_into_file(outfile, "probe-args", args_info->probe_args_orig, 0);
  547. if (args_info->list_probe_modules_given)
  548. write_into_file(outfile, "list-probe-modules", 0, 0 );
  549. if (args_info->output_fields_given)
  550. write_into_file(outfile, "output-fields", args_info->output_fields_orig, 0);
  551. if (args_info->output_module_given)
  552. write_into_file(outfile, "output-module", args_info->output_module_orig, 0);
  553. if (args_info->output_args_given)
  554. write_into_file(outfile, "output-args", args_info->output_args_orig, 0);
  555. if (args_info->output_filter_given)
  556. write_into_file(outfile, "output-filter", args_info->output_filter_orig, 0);
  557. if (args_info->list_output_modules_given)
  558. write_into_file(outfile, "list-output-modules", 0, 0 );
  559. if (args_info->list_output_fields_given)
  560. write_into_file(outfile, "list-output-fields", 0, 0 );
  561. if (args_info->verbosity_given)
  562. write_into_file(outfile, "verbosity", args_info->verbosity_orig, 0);
  563. if (args_info->log_file_given)
  564. write_into_file(outfile, "log-file", args_info->log_file_orig, 0);
  565. if (args_info->log_directory_given)
  566. write_into_file(outfile, "log-directory", args_info->log_directory_orig, 0);
  567. if (args_info->metadata_file_given)
  568. write_into_file(outfile, "metadata-file", args_info->metadata_file_orig, 0);
  569. if (args_info->status_updates_file_given)
  570. write_into_file(outfile, "status-updates-file", args_info->status_updates_file_orig, 0);
  571. if (args_info->quiet_given)
  572. write_into_file(outfile, "quiet", 0, 0 );
  573. if (args_info->disable_syslog_given)
  574. write_into_file(outfile, "disable-syslog", 0, 0 );
  575. if (args_info->notes_given)
  576. write_into_file(outfile, "notes", args_info->notes_orig, 0);
  577. if (args_info->user_metadata_given)
  578. write_into_file(outfile, "user-metadata", args_info->user_metadata_orig, 0);
  579. if (args_info->marker_encoding_given)
  580. write_into_file(outfile, "marker_encoding", args_info->marker_encoding_orig, 0);
  581. if (args_info->use_markervalue_given)
  582. write_into_file(outfile, "use_markervalue", args_info->use_markervalue_orig, 0);
  583. if (args_info->markervalue_given)
  584. write_into_file(outfile, "markervalue", args_info->markervalue_orig, 0);
  585. if (args_info->markerbits_value_given)
  586. write_into_file(outfile, "markerbits_value", args_info->markerbits_value_orig, 0);
  587. if (args_info->markerbits_checksum_given)
  588. write_into_file(outfile, "markerbits_checksum", args_info->markerbits_checksum_orig, 0);
  589. if (args_info->markerbits_dst_small_given)
  590. write_into_file(outfile, "markerbits_dst_small", args_info->markerbits_dst_small_orig, 0);
  591. if (args_info->disable_monitor_given)
  592. write_into_file(outfile, "disable_monitor", args_info->disable_monitor_orig, 0);
  593. if (args_info->config_given)
  594. write_into_file(outfile, "config", args_info->config_orig, 0);
  595. if (args_info->max_sendto_failures_given)
  596. write_into_file(outfile, "max-sendto-failures", args_info->max_sendto_failures_orig, 0);
  597. if (args_info->min_hitrate_given)
  598. write_into_file(outfile, "min-hitrate", args_info->min_hitrate_orig, 0);
  599. if (args_info->sender_threads_given)
  600. write_into_file(outfile, "sender-threads", args_info->sender_threads_orig, 0);
  601. if (args_info->cores_given)
  602. write_into_file(outfile, "cores", args_info->cores_orig, 0);
  603. if (args_info->ignore_invalid_hosts_given)
  604. write_into_file(outfile, "ignore-invalid-hosts", 0, 0 );
  605. if (args_info->help_given)
  606. write_into_file(outfile, "help", 0, 0 );
  607. if (args_info->version_given)
  608. write_into_file(outfile, "version", 0, 0 );
  609. i = EXIT_SUCCESS;
  610. return i;
  611. }
  612. int
  613. cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
  614. {
  615. FILE *outfile;
  616. int i = 0;
  617. outfile = fopen(filename, "w");
  618. if (!outfile)
  619. {
  620. fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
  621. return EXIT_FAILURE;
  622. }
  623. i = cmdline_parser_dump(outfile, args_info);
  624. fclose (outfile);
  625. return i;
  626. }
  627. void
  628. cmdline_parser_free (struct gengetopt_args_info *args_info)
  629. {
  630. cmdline_parser_release (args_info);
  631. }
  632. /** @brief replacement of strdup, which is not standard */
  633. char *
  634. gengetopt_strdup (const char *s)
  635. {
  636. char *result = 0;
  637. if (!s)
  638. return result;
  639. result = (char*)malloc(strlen(s) + 1);
  640. if (result == (char*)0)
  641. return (char*)0;
  642. strcpy(result, s);
  643. return result;
  644. }
  645. int
  646. cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
  647. {
  648. return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
  649. }
  650. int
  651. cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
  652. struct cmdline_parser_params *params)
  653. {
  654. int result;
  655. result = cmdline_parser_internal (argc, argv, args_info, params, 0);
  656. if (result == EXIT_FAILURE)
  657. {
  658. cmdline_parser_free (args_info);
  659. exit (EXIT_FAILURE);
  660. }
  661. return result;
  662. }
  663. int
  664. cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
  665. {
  666. int result;
  667. struct cmdline_parser_params params;
  668. params.override = override;
  669. params.initialize = initialize;
  670. params.check_required = check_required;
  671. params.check_ambiguity = 0;
  672. params.print_errors = 1;
  673. result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
  674. if (result == EXIT_FAILURE)
  675. {
  676. cmdline_parser_free (args_info);
  677. exit (EXIT_FAILURE);
  678. }
  679. return result;
  680. }
  681. int
  682. cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
  683. {
  684. FIX_UNUSED (args_info);
  685. FIX_UNUSED (prog_name);
  686. return EXIT_SUCCESS;
  687. }
  688. static char *package_name = 0;
  689. /**
  690. * @brief updates an option
  691. * @param field the generic pointer to the field to update
  692. * @param orig_field the pointer to the orig field
  693. * @param field_given the pointer to the number of occurrence of this option
  694. * @param prev_given the pointer to the number of occurrence already seen
  695. * @param value the argument for this option (if null no arg was specified)
  696. * @param possible_values the possible values for this option (if specified)
  697. * @param default_value the default value (in case the option only accepts fixed values)
  698. * @param arg_type the type of this option
  699. * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
  700. * @param override @see cmdline_parser_params.override
  701. * @param no_free whether to free a possible previous value
  702. * @param multiple_option whether this is a multiple option
  703. * @param long_opt the corresponding long option
  704. * @param short_opt the corresponding short option (or '-' if none)
  705. * @param additional_error possible further error specification
  706. */
  707. static
  708. int update_arg(void *field, char **orig_field,
  709. unsigned int *field_given, unsigned int *prev_given,
  710. char *value, const char *possible_values[],
  711. const char *default_value,
  712. cmdline_parser_arg_type arg_type,
  713. int check_ambiguity, int override,
  714. int no_free, int multiple_option,
  715. const char *long_opt, char short_opt,
  716. const char *additional_error)
  717. {
  718. char *stop_char = 0;
  719. const char *val = value;
  720. int found;
  721. char **string_field;
  722. FIX_UNUSED (field);
  723. stop_char = 0;
  724. found = 0;
  725. if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
  726. {
  727. if (short_opt != '-')
  728. fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
  729. package_name, long_opt, short_opt,
  730. (additional_error ? additional_error : ""));
  731. else
  732. fprintf (stderr, "%s: `--%s' option given more than once%s\n",
  733. package_name, long_opt,
  734. (additional_error ? additional_error : ""));
  735. return 1; /* failure */
  736. }
  737. FIX_UNUSED (default_value);
  738. if (field_given && *field_given && ! override)
  739. return 0;
  740. if (prev_given)
  741. (*prev_given)++;
  742. if (field_given)
  743. (*field_given)++;
  744. if (possible_values)
  745. val = possible_values[found];
  746. switch(arg_type) {
  747. case ARG_INT:
  748. if (val) *((int *)field) = strtol (val, &stop_char, 0);
  749. break;
  750. case ARG_FLOAT:
  751. if (val) *((float *)field) = (float)strtod (val, &stop_char);
  752. break;
  753. case ARG_LONGLONG:
  754. #if defined(HAVE_LONG_LONG) || defined(HAVE_LONG_LONG_INT)
  755. if (val) *((long long int*)field) = (long long int) strtoll (val, &stop_char, 0);
  756. #else
  757. if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);
  758. #endif
  759. break;
  760. case ARG_STRING:
  761. if (val) {
  762. string_field = (char **)field;
  763. if (!no_free && *string_field)
  764. free (*string_field); /* free previous string */
  765. *string_field = gengetopt_strdup (val);
  766. }
  767. break;
  768. default:
  769. break;
  770. };
  771. /* check numeric conversion */
  772. switch(arg_type) {
  773. case ARG_INT:
  774. case ARG_FLOAT:
  775. case ARG_LONGLONG:
  776. if (val && !(stop_char && *stop_char == '\0')) {
  777. fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
  778. return 1; /* failure */
  779. }
  780. break;
  781. default:
  782. ;
  783. };
  784. /* store the original value */
  785. switch(arg_type) {
  786. case ARG_NO:
  787. break;
  788. default:
  789. if (value && orig_field) {
  790. if (no_free) {
  791. *orig_field = value;
  792. } else {
  793. if (*orig_field)
  794. free (*orig_field); /* free previous string */
  795. *orig_field = gengetopt_strdup (value);
  796. }
  797. }
  798. };
  799. return 0; /* OK */
  800. }
  801. int
  802. cmdline_parser_internal (
  803. int argc, char **argv, struct gengetopt_args_info *args_info,
  804. struct cmdline_parser_params *params, const char *additional_error)
  805. {
  806. int c; /* Character of the parsed option. */
  807. int error_occurred = 0;
  808. struct gengetopt_args_info local_args_info;
  809. int override;
  810. int initialize;
  811. int check_required;
  812. int check_ambiguity;
  813. package_name = argv[0];
  814. override = params->override;
  815. initialize = params->initialize;
  816. check_required = params->check_required;
  817. check_ambiguity = params->check_ambiguity;
  818. if (initialize)
  819. cmdline_parser_init (args_info);
  820. cmdline_parser_init (&local_args_info);
  821. optarg = 0;
  822. optind = 0;
  823. opterr = params->print_errors;
  824. optopt = '?';
  825. while (1)
  826. {
  827. int option_index = 0;
  828. static struct option long_options[] = {
  829. { "target-port", 1, NULL, 'p' },
  830. { "output-file", 1, NULL, 'o' },
  831. { "blacklist-file", 1, NULL, 'b' },
  832. { "whitelist-file", 1, NULL, 'w' },
  833. { "rate", 1, NULL, 'r' },
  834. { "bandwidth", 1, NULL, 'B' },
  835. { "max-targets", 1, NULL, 'n' },
  836. { "max-runtime", 1, NULL, 't' },
  837. { "max-results", 1, NULL, 'N' },
  838. { "probes", 1, NULL, 'P' },
  839. { "cooldown-time", 1, NULL, 'c' },
  840. { "seed", 1, NULL, 'e' },
  841. { "retries", 1, NULL, 0 },
  842. { "dryrun", 0, NULL, 'd' },
  843. { "shards", 1, NULL, 0 },
  844. { "shard", 1, NULL, 0 },
  845. { "source-port", 1, NULL, 's' },
  846. { "source-ip", 1, NULL, 'S' },
  847. { "gateway-mac", 1, NULL, 'G' },
  848. { "source-mac", 1, NULL, 0 },
  849. { "interface", 1, NULL, 'i' },
  850. { "vpn", 0, NULL, 'X' },
  851. { "probe-module", 1, NULL, 'M' },
  852. { "probe-args", 1, NULL, 0 },
  853. { "list-probe-modules", 0, NULL, 0 },
  854. { "output-fields", 1, NULL, 'f' },
  855. { "output-module", 1, NULL, 'O' },
  856. { "output-args", 1, NULL, 0 },
  857. { "output-filter", 1, NULL, 0 },
  858. { "list-output-modules", 0, NULL, 0 },
  859. { "list-output-fields", 0, NULL, 0 },
  860. { "verbosity", 1, NULL, 'v' },
  861. { "log-file", 1, NULL, 'l' },
  862. { "log-directory", 1, NULL, 'L' },
  863. { "metadata-file", 1, NULL, 'm' },
  864. { "status-updates-file", 1, NULL, 'u' },
  865. { "quiet", 0, NULL, 'q' },
  866. { "disable-syslog", 0, NULL, 0 },
  867. { "notes", 1, NULL, 0 },
  868. { "user-metadata", 1, NULL, 0 },
  869. { "marker_encoding", 1, NULL, 0 },
  870. { "use_markervalue", 1, NULL, 0 },
  871. { "markervalue", 1, NULL, 0 },
  872. { "markerbits_value", 1, NULL, 0 },
  873. { "markerbits_checksum", 1, NULL, 0 },
  874. { "markerbits_dst_small", 1, NULL, 0 },
  875. { "disable_monitor", 1, NULL, 0 },
  876. { "config", 1, NULL, 'C' },
  877. { "max-sendto-failures", 1, NULL, 0 },
  878. { "min-hitrate", 1, NULL, 0 },
  879. { "sender-threads", 1, NULL, 'T' },
  880. { "cores", 1, NULL, 0 },
  881. { "ignore-invalid-hosts", 0, NULL, 0 },
  882. { "help", 0, NULL, 'h' },
  883. { "version", 0, NULL, 'V' },
  884. { 0, 0, 0, 0 }
  885. };
  886. c = getopt_long (argc, argv, "p:o:b:w:r:B:n:t:N:P:c:e:ds:S:G:i:XM:f:O:v:l:L:m:u:qC:T:hV", long_options, &option_index);
  887. if (c == -1) break; /* Exit from `while (1)' loop. */
  888. switch (c)
  889. {
  890. case 'p': /* port number to scan (for TCP and UDP scans). */
  891. if (update_arg( (void *)&(args_info->target_port_arg),
  892. &(args_info->target_port_orig), &(args_info->target_port_given),
  893. &(local_args_info.target_port_given), optarg, 0, 0, ARG_INT,
  894. check_ambiguity, override, 0, 0,
  895. "target-port", 'p',
  896. additional_error))
  897. goto failure;
  898. break;
  899. case 'o': /* Output file. */
  900. if (update_arg( (void *)&(args_info->output_file_arg),
  901. &(args_info->output_file_orig), &(args_info->output_file_given),
  902. &(local_args_info.output_file_given), optarg, 0, 0, ARG_STRING,
  903. check_ambiguity, override, 0, 0,
  904. "output-file", 'o',
  905. additional_error))
  906. goto failure;
  907. break;
  908. case 'b': /* File of subnets to exclude, in CIDR notation, e.g. 192.168.0.0/16. */
  909. if (update_arg( (void *)&(args_info->blacklist_file_arg),
  910. &(args_info->blacklist_file_orig), &(args_info->blacklist_file_given),
  911. &(local_args_info.blacklist_file_given), optarg, 0, 0, ARG_STRING,
  912. check_ambiguity, override, 0, 0,
  913. "blacklist-file", 'b',
  914. additional_error))
  915. goto failure;
  916. break;
  917. case 'w': /* File of subnets to constrain scan to, in CIDR notation, e.g. 192.168.0.0/16. */
  918. if (update_arg( (void *)&(args_info->whitelist_file_arg),
  919. &(args_info->whitelist_file_orig), &(args_info->whitelist_file_given),
  920. &(local_args_info.whitelist_file_given), optarg, 0, 0, ARG_STRING,
  921. check_ambiguity, override, 0, 0,
  922. "whitelist-file", 'w',
  923. additional_error))
  924. goto failure;
  925. break;
  926. case 'r': /* Set send rate in packets/sec. */
  927. if (update_arg( (void *)&(args_info->rate_arg),
  928. &(args_info->rate_orig), &(args_info->rate_given),
  929. &(local_args_info.rate_given), optarg, 0, 0, ARG_INT,
  930. check_ambiguity, override, 0, 0,
  931. "rate", 'r',
  932. additional_error))
  933. goto failure;
  934. break;
  935. case 'B': /* Set send rate in bits/second (supports suffixes G, M and K). */
  936. if (update_arg( (void *)&(args_info->bandwidth_arg),
  937. &(args_info->bandwidth_orig), &(args_info->bandwidth_given),
  938. &(local_args_info.bandwidth_given), optarg, 0, 0, ARG_STRING,
  939. check_ambiguity, override, 0, 0,
  940. "bandwidth", 'B',
  941. additional_error))
  942. goto failure;
  943. break;
  944. case 'n': /* Cap number of targets to probe (as a number or a percentage of the address space). */
  945. if (update_arg( (void *)&(args_info->max_targets_arg),
  946. &(args_info->max_targets_orig), &(args_info->max_targets_given),
  947. &(local_args_info.max_targets_given), optarg, 0, 0, ARG_STRING,
  948. check_ambiguity, override, 0, 0,
  949. "max-targets", 'n',
  950. additional_error))
  951. goto failure;
  952. break;
  953. case 't': /* Cap length of time for sending packets. */
  954. if (update_arg( (void *)&(args_info->max_runtime_arg),
  955. &(args_info->max_runtime_orig), &(args_info->max_runtime_given),
  956. &(local_args_info.max_runtime_given), optarg, 0, 0, ARG_INT,
  957. check_ambiguity, override, 0, 0,
  958. "max-runtime", 't',
  959. additional_error))
  960. goto failure;
  961. break;
  962. case 'N': /* Cap number of results to return. */
  963. if (update_arg( (void *)&(args_info->max_results_arg),
  964. &(args_info->max_results_orig), &(args_info->max_results_given),
  965. &(local_args_info.max_results_given), optarg, 0, 0, ARG_INT,
  966. check_ambiguity, override, 0, 0,
  967. "max-results", 'N',
  968. additional_error))
  969. goto failure;
  970. break;
  971. case 'P': /* Number of probes to send to each IP. */
  972. if (update_arg( (void *)&(args_info->probes_arg),
  973. &(args_info->probes_orig), &(args_info->probes_given),
  974. &(local_args_info.probes_given), optarg, 0, "1", ARG_INT,
  975. check_ambiguity, override, 0, 0,
  976. "probes", 'P',
  977. additional_error))
  978. goto failure;
  979. break;
  980. case 'c': /* How long to continue receiving after sending last probe. */
  981. if (update_arg( (void *)&(args_info->cooldown_time_arg),
  982. &(args_info->cooldown_time_orig), &(args_info->cooldown_time_given),
  983. &(local_args_info.cooldown_time_given), optarg, 0, "8", ARG_INT,
  984. check_ambiguity, override, 0, 0,
  985. "cooldown-time", 'c',
  986. additional_error))
  987. goto failure;
  988. break;
  989. case 'e': /* Seed used to select address permutation. */
  990. if (update_arg( (void *)&(args_info->seed_arg),
  991. &(args_info->seed_orig), &(args_info->seed_given),
  992. &(local_args_info.seed_given), optarg, 0, 0, ARG_LONGLONG,
  993. check_ambiguity, override, 0, 0,
  994. "seed", 'e',
  995. additional_error))
  996. goto failure;
  997. break;
  998. case 'd': /* Don't actually send packets. */
  999. if (update_arg( 0 ,
  1000. 0 , &(args_info->dryrun_given),
  1001. &(local_args_info.dryrun_given), optarg, 0, 0, ARG_NO,
  1002. check_ambiguity, override, 0, 0,
  1003. "dryrun", 'd',
  1004. additional_error))
  1005. goto failure;
  1006. break;
  1007. case 's': /* Source port(s) for scan packets. */
  1008. if (update_arg( (void *)&(args_info->source_port_arg),
  1009. &(args_info->source_port_orig), &(args_info->source_port_given),
  1010. &(local_args_info.source_port_given), optarg, 0, 0, ARG_STRING,
  1011. check_ambiguity, override, 0, 0,
  1012. "source-port", 's',
  1013. additional_error))
  1014. goto failure;
  1015. break;
  1016. case 'S': /* Source address(es) for scan packets. */
  1017. if (update_arg( (void *)&(args_info->source_ip_arg),
  1018. &(args_info->source_ip_orig), &(args_info->source_ip_given),
  1019. &(local_args_info.source_ip_given), optarg, 0, 0, ARG_STRING,
  1020. check_ambiguity, override, 0, 0,
  1021. "source-ip", 'S',
  1022. additional_error))
  1023. goto failure;
  1024. break;
  1025. case 'G': /* Specify gateway MAC address. */
  1026. if (update_arg( (void *)&(args_info->gateway_mac_arg),
  1027. &(args_info->gateway_mac_orig), &(args_info->gateway_mac_given),
  1028. &(local_args_info.gateway_mac_given), optarg, 0, 0, ARG_STRING,
  1029. check_ambiguity, override, 0, 0,
  1030. "gateway-mac", 'G',
  1031. additional_error))
  1032. goto failure;
  1033. break;
  1034. case 'i': /* Specify network interface to use. */
  1035. if (update_arg( (void *)&(args_info->interface_arg),
  1036. &(args_info->interface_orig), &(args_info->interface_given),
  1037. &(local_args_info.interface_given), optarg, 0, 0, ARG_STRING,
  1038. check_ambiguity, override, 0, 0,
  1039. "interface", 'i',
  1040. additional_error))
  1041. goto failure;
  1042. break;
  1043. case 'X': /* Sends IP packets instead of Ethernet (for VPNs). */
  1044. if (update_arg( 0 ,
  1045. 0 , &(args_info->vpn_given),
  1046. &(local_args_info.vpn_given), optarg, 0, 0, ARG_NO,
  1047. check_ambiguity, override, 0, 0,
  1048. "vpn", 'X',
  1049. additional_error))
  1050. goto failure;
  1051. break;
  1052. case 'M': /* Select probe module. */
  1053. if (update_arg( (void *)&(args_info->probe_module_arg),
  1054. &(args_info->probe_module_orig), &(args_info->probe_module_given),
  1055. &(local_args_info.probe_module_given), optarg, 0, "tcp_synscan", ARG_STRING,
  1056. check_ambiguity, override, 0, 0,
  1057. "probe-module", 'M',
  1058. additional_error))
  1059. goto failure;
  1060. break;
  1061. case 'f': /* Fields that should be output in result set. */
  1062. if (update_arg( (void *)&(args_info->output_fields_arg),
  1063. &(args_info->output_fields_orig), &(args_info->output_fields_given),
  1064. &(local_args_info.output_fields_given), optarg, 0, 0, ARG_STRING,
  1065. check_ambiguity, override, 0, 0,
  1066. "output-fields", 'f',
  1067. additional_error))
  1068. goto failure;
  1069. break;
  1070. case 'O': /* Select output module. */
  1071. if (update_arg( (void *)&(args_info->output_module_arg),
  1072. &(args_info->output_module_orig), &(args_info->output_module_given),
  1073. &(local_args_info.output_module_given), optarg, 0, "default", ARG_STRING,
  1074. check_ambiguity, override, 0, 0,
  1075. "output-module", 'O',
  1076. additional_error))
  1077. goto failure;
  1078. break;
  1079. case 'v': /* Level of log detail (0-5). */
  1080. if (update_arg( (void *)&(args_info->verbosity_arg),
  1081. &(args_info->verbosity_orig), &(args_info->verbosity_given),
  1082. &(local_args_info.verbosity_given), optarg, 0, "3", ARG_INT,
  1083. check_ambiguity, override, 0, 0,
  1084. "verbosity", 'v',
  1085. additional_error))
  1086. goto failure;
  1087. break;
  1088. case 'l': /* Write log entries to file. */
  1089. if (update_arg( (void *)&(args_info->log_file_arg),
  1090. &(args_info->log_file_orig), &(args_info->log_file_given),
  1091. &(local_args_info.log_file_given), optarg, 0, 0, ARG_STRING,
  1092. check_ambiguity, override, 0, 0,
  1093. "log-file", 'l',
  1094. additional_error))
  1095. goto failure;
  1096. break;
  1097. case 'L': /* Write log entries to a timestamped file in this directory. */
  1098. if (update_arg( (void *)&(args_info->log_directory_arg),
  1099. &(args_info->log_directory_orig), &(args_info->log_directory_given),
  1100. &(local_args_info.log_directory_given), optarg, 0, 0, ARG_STRING,
  1101. check_ambiguity, override, 0, 0,
  1102. "log-directory", 'L',
  1103. additional_error))
  1104. goto failure;
  1105. break;
  1106. case 'm': /* Output file for scan metadata (JSON). */
  1107. if (update_arg( (void *)&(args_info->metadata_file_arg),
  1108. &(args_info->metadata_file_orig), &(args_info->metadata_file_given),
  1109. &(local_args_info.metadata_file_given), optarg, 0, 0, ARG_STRING,
  1110. check_ambiguity, override, 0, 0,
  1111. "metadata-file", 'm',
  1112. additional_error))
  1113. goto failure;
  1114. break;
  1115. case 'u': /* Write scan progress updates to CSV file. */
  1116. if (update_arg( (void *)&(args_info->status_updates_file_arg),
  1117. &(args_info->status_updates_file_orig), &(args_info->status_updates_file_given),
  1118. &(local_args_info.status_updates_file_given), optarg, 0, 0, ARG_STRING,
  1119. check_ambiguity, override, 0, 0,
  1120. "status-updates-file", 'u',
  1121. additional_error))
  1122. goto failure;
  1123. break;
  1124. case 'q': /* Do not print status updates. */
  1125. if (update_arg( 0 ,
  1126. 0 , &(args_info->quiet_given),
  1127. &(local_args_info.quiet_given), optarg, 0, 0, ARG_NO,
  1128. check_ambiguity, override, 0, 0,
  1129. "quiet", 'q',
  1130. additional_error))
  1131. goto failure;
  1132. break;
  1133. case 'C': /* Read a configuration file, which can specify any of these options. */
  1134. if (update_arg( (void *)&(args_info->config_arg),
  1135. &(args_info->config_orig), &(args_info->config_given),
  1136. &(local_args_info.config_given), optarg, 0, "/etc/zmap/zmap.conf", ARG_STRING,
  1137. check_ambiguity, override, 0, 0,
  1138. "config", 'C',
  1139. additional_error))
  1140. goto failure;
  1141. break;
  1142. case 'T': /* Threads used to send packets. */
  1143. if (update_arg( (void *)&(args_info->sender_threads_arg),
  1144. &(args_info->sender_threads_orig), &(args_info->sender_threads_given),
  1145. &(local_args_info.sender_threads_given), optarg, 0, "1", ARG_INT,
  1146. check_ambiguity, override, 0, 0,
  1147. "sender-threads", 'T',
  1148. additional_error))
  1149. goto failure;
  1150. break;
  1151. case 'h': /* Print help and exit. */
  1152. if (update_arg( 0 ,
  1153. 0 , &(args_info->help_given),
  1154. &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
  1155. check_ambiguity, override, 0, 0,
  1156. "help", 'h',
  1157. additional_error))
  1158. goto failure;
  1159. break;
  1160. case 'V': /* Print version and exit. */
  1161. if (update_arg( 0 ,
  1162. 0 , &(args_info->version_given),
  1163. &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
  1164. check_ambiguity, override, 0, 0,
  1165. "version", 'V',
  1166. additional_error))
  1167. goto failure;
  1168. break;
  1169. case 0: /* Long option with no short option */
  1170. /* Max number of times to try to send packet if send fails. */
  1171. if (strcmp (long_options[option_index].name, "retries") == 0)
  1172. {
  1173. if (update_arg( (void *)&(args_info->retries_arg),
  1174. &(args_info->retries_orig), &(args_info->retries_given),
  1175. &(local_args_info.retries_given), optarg, 0, "10", ARG_INT,
  1176. check_ambiguity, override, 0, 0,
  1177. "retries", '-',
  1178. additional_error))
  1179. goto failure;
  1180. }
  1181. /* Set the total number of shards. */
  1182. else if (strcmp (long_options[option_index].name, "shards") == 0)
  1183. {
  1184. if (update_arg( (void *)&(args_info->shards_arg),
  1185. &(args_info->shards_orig), &(args_info->shards_given),
  1186. &(local_args_info.shards_given), optarg, 0, "1", ARG_INT,
  1187. check_ambiguity, override, 0, 0,
  1188. "shards", '-',
  1189. additional_error))
  1190. goto failure;
  1191. }
  1192. /* Set which shard this scan is (0 indexed). */
  1193. else if (strcmp (long_options[option_index].name, "shard") == 0)
  1194. {
  1195. if (update_arg( (void *)&(args_info->shard_arg),
  1196. &(args_info->shard_orig), &(args_info->shard_given),
  1197. &(local_args_info.shard_given), optarg, 0, "0", ARG_INT,
  1198. check_ambiguity, override, 0, 0,
  1199. "shard", '-',
  1200. additional_error))
  1201. goto failure;
  1202. }
  1203. /* Source MAC address. */
  1204. else if (strcmp (long_options[option_index].name, "source-mac") == 0)
  1205. {
  1206. if (update_arg( (void *)&(args_info->source_mac_arg),
  1207. &(args_info->source_mac_orig), &(args_info->source_mac_given),
  1208. &(local_args_info.source_mac_given), optarg, 0, 0, ARG_STRING,
  1209. check_ambiguity, override, 0, 0,
  1210. "source-mac", '-',
  1211. additional_error))
  1212. goto failure;
  1213. }
  1214. /* Arguments to pass to probe module. */
  1215. else if (strcmp (long_options[option_index].name, "probe-args") == 0)
  1216. {
  1217. if (update_arg( (void *)&(args_info->probe_args_arg),
  1218. &(args_info->probe_args_orig), &(args_info->probe_args_given),
  1219. &(local_args_info.probe_args_given), optarg, 0, 0, ARG_STRING,
  1220. check_ambiguity, override, 0, 0,
  1221. "probe-args", '-',
  1222. additional_error))
  1223. goto failure;
  1224. }
  1225. /* List available probe modules. */
  1226. else if (strcmp (long_options[option_index].name, "list-probe-modules") == 0)
  1227. {
  1228. if (update_arg( 0 ,
  1229. 0 , &(args_info->list_probe_modules_given),
  1230. &(local_args_info.list_probe_modules_given), optarg, 0, 0, ARG_NO,
  1231. check_ambiguity, override, 0, 0,
  1232. "list-probe-modules", '-',
  1233. additional_error))
  1234. goto failure;
  1235. }
  1236. /* Arguments to pass to output module. */
  1237. else if (strcmp (long_options[option_index].name, "output-args") == 0)
  1238. {
  1239. if (update_arg( (void *)&(args_info->output_args_arg),
  1240. &(args_info->output_args_orig), &(args_info->output_args_given),
  1241. &(local_args_info.output_args_given), optarg, 0, 0, ARG_STRING,
  1242. check_ambiguity, override, 0, 0,
  1243. "output-args", '-',
  1244. additional_error))
  1245. goto failure;
  1246. }
  1247. /* Specify a filter over the response fields to limit what responses get sent to the output module. */
  1248. else if (strcmp (long_options[option_index].name, "output-filter") == 0)
  1249. {
  1250. if (update_arg( (void *)&(args_info->output_filter_arg),
  1251. &(args_info->output_filter_orig), &(args_info->output_filter_given),
  1252. &(local_args_info.output_filter_given), optarg, 0, 0, ARG_STRING,
  1253. check_ambiguity, override, 0, 0,
  1254. "output-filter", '-',
  1255. additional_error))
  1256. goto failure;
  1257. }
  1258. /* List available output modules. */
  1259. else if (strcmp (long_options[option_index].name, "list-output-modules") == 0)
  1260. {
  1261. if (update_arg( 0 ,
  1262. 0 , &(args_info->list_output_modules_given),
  1263. &(local_args_info.list_output_modules_given), optarg, 0, 0, ARG_NO,
  1264. check_ambiguity, override, 0, 0,
  1265. "list-output-modules", '-',
  1266. additional_error))
  1267. goto failure;
  1268. }
  1269. /* List all fields that can be output by selected probe module. */
  1270. else if (strcmp (long_options[option_index].name, "list-output-fields") == 0)
  1271. {
  1272. if (update_arg( 0 ,
  1273. 0 , &(args_info->list_output_fields_given),
  1274. &(local_args_info.list_output_fields_given), optarg, 0, 0, ARG_NO,
  1275. check_ambiguity, override, 0, 0,
  1276. "list-output-fields", '-',
  1277. additional_error))
  1278. goto failure;
  1279. }
  1280. /* Disables logging messages to syslog. */
  1281. else if (strcmp (long_options[option_index].name, "disable-syslog") == 0)
  1282. {
  1283. if (update_arg( 0 ,
  1284. 0 , &(args_info->disable_syslog_given),
  1285. &(local_args_info.disable_syslog_given), optarg, 0, 0, ARG_NO,
  1286. check_ambiguity, override, 0, 0,
  1287. "disable-syslog", '-',
  1288. additional_error))
  1289. goto failure;
  1290. }
  1291. /* Inject user-specified notes into scan metadata. */
  1292. else if (strcmp (long_options[option_index].name, "notes") == 0)
  1293. {
  1294. if (update_arg( (void *)&(args_info->notes_arg),
  1295. &(args_info->notes_orig), &(args_info->notes_given),
  1296. &(local_args_info.notes_given), optarg, 0, 0, ARG_STRING,
  1297. check_ambiguity, override, 0, 0,
  1298. "notes", '-',
  1299. additional_error))
  1300. goto failure;
  1301. }
  1302. /* Inject user-specified JSON metadata into scan metadata. */
  1303. else if (strcmp (long_options[option_index].name, "user-metadata") == 0)
  1304. {
  1305. if (update_arg( (void *)&(args_info->user_metadata_arg),
  1306. &(args_info->user_metadata_orig), &(args_info->user_metadata_given),
  1307. &(local_args_info.user_metadata_given), optarg, 0, 0, ARG_STRING,
  1308. check_ambiguity, override, 0, 0,
  1309. "user-metadata", '-',
  1310. additional_error))
  1311. goto failure;
  1312. }
  1313. /* Marker to be used to encode destination address/checksum (TCP probe module). */
  1314. else if (strcmp (long_options[option_index].name, "marker_encoding") == 0)
  1315. {
  1316. if (update_arg( (void *)&(args_info->marker_encoding_arg),
  1317. &(args_info->marker_encoding_orig), &(args_info->marker_encoding_given),
  1318. &(local_args_info.marker_encoding_given), optarg, 0, "0", ARG_INT,
  1319. check_ambiguity, override, 0, 0,
  1320. "marker_encoding", '-',
  1321. additional_error))
  1322. goto failure;
  1323. }
  1324. /* Use markervalue instead of target IP address for encoding. */
  1325. else if (strcmp (long_options[option_index].name, "use_markervalue") == 0)
  1326. {
  1327. if (update_arg( (void *)&(args_info->use_markervalue_arg),
  1328. &(args_info->use_markervalue_orig), &(args_info->use_markervalue_given),
  1329. &(local_args_info.use_markervalue_given), optarg, 0, "0", ARG_INT,
  1330. check_ambiguity, override, 0, 0,
  1331. "use_markervalue", '-',
  1332. additional_error))
  1333. goto failure;
  1334. }
  1335. /* Value to be used instead of target IP address for encoding. */
  1336. else if (strcmp (long_options[option_index].name, "markervalue") == 0)
  1337. {
  1338. if (update_arg( (void *)&(args_info->markervalue_arg),
  1339. &(args_info->markervalue_orig), &(args_info->markervalue_given),
  1340. &(local_args_info.markervalue_given), optarg, 0, "0", ARG_STRING,
  1341. check_ambiguity, override, 0, 0,
  1342. "markervalue", '-',
  1343. additional_error))
  1344. goto failure;
  1345. }
  1346. /* Amount of Bits of the IP address (32 Bit total) to be encoded (TCP probe module). */
  1347. else if (strcmp (long_options[option_index].name, "markerbits_value") == 0)
  1348. {
  1349. if (update_arg( (void *)&(args_info->markerbits_value_arg),
  1350. &(args_info->markerbits_value_orig), &(args_info->markerbits_value_given),
  1351. &(local_args_info.markerbits_value_given), optarg, 0, "0", ARG_INT,
  1352. check_ambiguity, override, 0, 0,
  1353. "markerbits_value", '-',
  1354. additional_error))
  1355. goto failure;
  1356. }
  1357. /* Amount of Bits of the checksum (32 Bit total) to be encoded (TCP probe module). */
  1358. else if (strcmp (long_options[option_index].name, "markerbits_checksum") == 0)
  1359. {
  1360. if (update_arg( (void *)&(args_info->markerbits_checksum_arg),
  1361. &(args_info->markerbits_checksum_orig), &(args_info->markerbits_checksum_given),
  1362. &(local_args_info.markerbits_checksum_given), optarg, 0, "0", ARG_INT,
  1363. check_ambiguity, override, 0, 0,
  1364. "markerbits_checksum", '-',
  1365. additional_error))
  1366. goto failure;
  1367. }
  1368. /* Anti-Mitigation (TraCINg): just use destination port for encoding.. */
  1369. else if (strcmp (long_options[option_index].name, "markerbits_dst_small") == 0)
  1370. {
  1371. if (update_arg( (void *)&(args_info->markerbits_dst_small_arg),
  1372. &(args_info->markerbits_dst_small_orig), &(args_info->markerbits_dst_small_given),
  1373. &(local_args_info.markerbits_dst_small_given), optarg, 0, "0", ARG_INT,
  1374. check_ambiguity, override, 0, 0,
  1375. "markerbits_dst_small", '-',
  1376. additional_error))
  1377. goto failure;
  1378. }
  1379. /* Disable monitor output. This is intended for small scan groups (<100000). */
  1380. else if (strcmp (long_options[option_index].name, "disable_monitor") == 0)
  1381. {
  1382. if (update_arg( (void *)&(args_info->disable_monitor_arg),
  1383. &(args_info->disable_monitor_orig), &(args_info->disable_monitor_given),
  1384. &(local_args_info.disable_monitor_given), optarg, 0, "0", ARG_INT,
  1385. check_ambiguity, override, 0, 0,
  1386. "disable_monitor", '-',
  1387. additional_error))
  1388. goto failure;
  1389. }
  1390. /* Maximum NIC sendto failures before scan is aborted. */
  1391. else if (strcmp (long_options[option_index].name, "max-sendto-failures") == 0)
  1392. {
  1393. if (update_arg( (void *)&(args_info->max_sendto_failures_arg),
  1394. &(args_info->max_sendto_failures_orig), &(args_info->max_sendto_failures_given),
  1395. &(local_args_info.max_sendto_failures_given), optarg, 0, "-1", ARG_INT,
  1396. check_ambiguity, override, 0, 0,
  1397. "max-sendto-failures", '-',
  1398. additional_error))
  1399. goto failure;
  1400. }
  1401. /* Minimum hitrate that scan can hit before scan is aborted. */
  1402. else if (strcmp (long_options[option_index].name, "min-hitrate") == 0)
  1403. {
  1404. if (update_arg( (void *)&(args_info->min_hitrate_arg),
  1405. &(args_info->min_hitrate_orig), &(args_info->min_hitrate_given),
  1406. &(local_args_info.min_hitrate_given), optarg, 0, "0.0", ARG_FLOAT,
  1407. check_ambiguity, override, 0, 0,
  1408. "min-hitrate", '-',
  1409. additional_error))
  1410. goto failure;
  1411. }
  1412. /* Comma-separated list of cores to pin to. */
  1413. else if (strcmp (long_options[option_index].name, "cores") == 0)
  1414. {
  1415. if (update_arg( (void *)&(args_info->cores_arg),
  1416. &(args_info->cores_orig), &(args_info->cores_given),
  1417. &(local_args_info.cores_given), optarg, 0, 0, ARG_STRING,
  1418. check_ambiguity, override, 0, 0,
  1419. "cores", '-',
  1420. additional_error))
  1421. goto failure;
  1422. }
  1423. /* Ignore invalid hosts in whitelist/blacklist file. */
  1424. else if (strcmp (long_options[option_index].name, "ignore-invalid-hosts") == 0)
  1425. {
  1426. if (update_arg( 0 ,
  1427. 0 , &(args_info->ignore_invalid_hosts_given),
  1428. &(local_args_info.ignore_invalid_hosts_given), optarg, 0, 0, ARG_NO,
  1429. check_ambiguity, override, 0, 0,
  1430. "ignore-invalid-hosts", '-',
  1431. additional_error))
  1432. goto failure;
  1433. }
  1434. break;
  1435. case '?': /* Invalid option. */
  1436. /* `getopt_long' already printed an error message. */
  1437. goto failure;
  1438. default: /* bug: option not considered. */
  1439. fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
  1440. abort ();
  1441. } /* switch */
  1442. } /* while */
  1443. cmdline_parser_release (&local_args_info);
  1444. if ( error_occurred )
  1445. return (EXIT_FAILURE);
  1446. if (optind < argc)
  1447. {
  1448. int i = 0 ;
  1449. int found_prog_name = 0;
  1450. /* whether program name, i.e., argv[0], is in the remaining args
  1451. (this may happen with some implementations of getopt,
  1452. but surely not with the one included by gengetopt) */
  1453. i = optind;
  1454. while (i < argc)
  1455. if (argv[i++] == argv[0]) {
  1456. found_prog_name = 1;
  1457. break;
  1458. }
  1459. i = 0;
  1460. args_info->inputs_num = argc - optind - found_prog_name;
  1461. args_info->inputs =
  1462. (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
  1463. while (optind < argc)
  1464. if (argv[optind++] != argv[0])
  1465. args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
  1466. }
  1467. return 0;
  1468. failure:
  1469. cmdline_parser_release (&local_args_info);
  1470. return (EXIT_FAILURE);
  1471. }
  1472. #ifndef CONFIG_FILE_LINE_SIZE
  1473. #define CONFIG_FILE_LINE_SIZE 2048
  1474. #endif
  1475. #define ADDITIONAL_ERROR " in configuration file "
  1476. #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
  1477. /* 3 is for "--" and "=" */
  1478. static int
  1479. _cmdline_parser_configfile (const char *filename, int *my_argc)
  1480. {
  1481. FILE* file;
  1482. char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
  1483. char linebuf[CONFIG_FILE_LINE_SIZE];
  1484. int line_num = 0;
  1485. int result = 0, equal;
  1486. char *fopt, *farg;
  1487. char *str_index;
  1488. size_t len, next_token;
  1489. char delimiter;
  1490. if ((file = fopen(filename, "r")) == 0)
  1491. {
  1492. fprintf (stderr, "%s: Error opening configuration file '%s'\n",
  1493. CMDLINE_PARSER_PACKAGE, filename);
  1494. return EXIT_FAILURE;
  1495. }
  1496. while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)
  1497. {
  1498. ++line_num;
  1499. my_argv[0] = '\0';
  1500. len = strlen(linebuf);
  1501. if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
  1502. {
  1503. fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
  1504. CMDLINE_PARSER_PACKAGE, filename, line_num);
  1505. result = EXIT_FAILURE;
  1506. break;
  1507. }
  1508. /* find first non-whitespace character in the line */
  1509. next_token = strspn (linebuf, " \t\r\n");
  1510. str_index = linebuf + next_token;
  1511. if ( str_index[0] == '\0' || str_index[0] == '#')
  1512. continue; /* empty line or comment line is skipped */
  1513. fopt = str_index;
  1514. /* truncate fopt at the end of the first non-valid character */
  1515. next_token = strcspn (fopt, " \t\r\n=");
  1516. if (fopt[next_token] == '\0') /* the line is over */
  1517. {
  1518. farg = 0;
  1519. equal = 0;
  1520. goto noarg;
  1521. }
  1522. /* remember if equal sign is present */
  1523. equal = (fopt[next_token] == '=');
  1524. fopt[next_token++] = '\0';
  1525. /* advance pointers to the next token after the end of fopt */
  1526. next_token += strspn (fopt + next_token, " \t\r\n");
  1527. /* check for the presence of equal sign, and if so, skip it */
  1528. if ( !equal )
  1529. if ((equal = (fopt[next_token] == '=')))
  1530. {
  1531. next_token++;
  1532. next_token += strspn (fopt + next_token, " \t\r\n");
  1533. }
  1534. str_index += next_token;
  1535. /* find argument */
  1536. farg = str_index;
  1537. if ( farg[0] == '\"' || farg[0] == '\'' )
  1538. { /* quoted argument */
  1539. str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
  1540. if (! str_index)
  1541. {
  1542. fprintf
  1543. (stderr,
  1544. "%s:%s:%d: unterminated string in configuration file\n",
  1545. CMDLINE_PARSER_PACKAGE, filename, line_num);
  1546. result = EXIT_FAILURE;
  1547. break;
  1548. }
  1549. }
  1550. else
  1551. { /* read up the remaining part up to a delimiter */
  1552. next_token = strcspn (farg, " \t\r\n#\'\"");
  1553. str_index += next_token;
  1554. }
  1555. /* truncate farg at the delimiter and store it for further check */
  1556. delimiter = *str_index, *str_index++ = '\0';
  1557. /* everything but comment is illegal at the end of line */
  1558. if (delimiter != '\0' && delimiter != '#')
  1559. {
  1560. str_index += strspn(str_index, " \t\r\n");
  1561. if (*str_index != '\0' && *str_index != '#')
  1562. {
  1563. fprintf
  1564. (stderr,
  1565. "%s:%s:%d: malformed string in configuration file\n",
  1566. CMDLINE_PARSER_PACKAGE, filename, line_num);
  1567. result = EXIT_FAILURE;
  1568. break;
  1569. }
  1570. }
  1571. noarg:
  1572. if (!strcmp(fopt,"include")) {
  1573. if (farg && *farg) {
  1574. result = _cmdline_parser_configfile(farg, my_argc);
  1575. } else {
  1576. fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
  1577. CMDLINE_PARSER_PACKAGE, filename, line_num);
  1578. }
  1579. continue;
  1580. }
  1581. len = strlen(fopt);
  1582. strcat (my_argv, len > 1 ? "--" : "-");
  1583. strcat (my_argv, fopt);
  1584. if (len > 1 && ((farg && *farg) || equal))
  1585. strcat (my_argv, "=");
  1586. if (farg && *farg)
  1587. strcat (my_argv, farg);
  1588. ++(*my_argc);
  1589. cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
  1590. cmd_line_list_tmp->next = cmd_line_list;
  1591. cmd_line_list = cmd_line_list_tmp;
  1592. cmd_line_list->string_arg = gengetopt_strdup(my_argv);
  1593. } /* while */
  1594. if (file)
  1595. fclose(file);
  1596. return result;
  1597. }
  1598. int
  1599. cmdline_parser_configfile (
  1600. const char *filename,
  1601. struct gengetopt_args_info *args_info,
  1602. int override, int initialize, int check_required)
  1603. {
  1604. struct cmdline_parser_params params;
  1605. params.override = override;
  1606. params.initialize = initialize;
  1607. params.check_required = check_required;
  1608. params.check_ambiguity = 0;
  1609. params.print_errors = 1;
  1610. return cmdline_parser_config_file (filename, args_info, &params);
  1611. }
  1612. int
  1613. cmdline_parser_config_file (const char *filename,
  1614. struct gengetopt_args_info *args_info,
  1615. struct cmdline_parser_params *params)
  1616. {
  1617. int i, result;
  1618. int my_argc = 1;
  1619. char **my_argv_arg;
  1620. char *additional_error;
  1621. /* store the program name */
  1622. cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
  1623. cmd_line_list_tmp->next = cmd_line_list;
  1624. cmd_line_list = cmd_line_list_tmp;
  1625. cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE);
  1626. result = _cmdline_parser_configfile(filename, &my_argc);
  1627. if (result != EXIT_FAILURE) {
  1628. my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
  1629. cmd_line_list_tmp = cmd_line_list;
  1630. for (i = my_argc - 1; i >= 0; --i) {
  1631. my_argv_arg[i] = cmd_line_list_tmp->string_arg;
  1632. cmd_line_list_tmp = cmd_line_list_tmp->next;
  1633. }
  1634. my_argv_arg[my_argc] = 0;
  1635. additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
  1636. strcpy (additional_error, ADDITIONAL_ERROR);
  1637. strcat (additional_error, filename);
  1638. result =
  1639. cmdline_parser_internal (my_argc, my_argv_arg, args_info,
  1640. params,
  1641. additional_error);
  1642. free (additional_error);
  1643. free (my_argv_arg);
  1644. }
  1645. free_cmd_list();
  1646. if (result == EXIT_FAILURE)
  1647. {
  1648. cmdline_parser_free (args_info);
  1649. exit (EXIT_FAILURE);
  1650. }
  1651. return result;
  1652. }