flowreplay_opts.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (flowreplay_opts.c)
  4. *
  5. * It has been AutoGen-ed Monday August 7, 2006 at 09:28:39 PM PDT
  6. * From the definitions flowreplay_opts.def
  7. * and the template file options
  8. */
  9. #include <stdio.h>
  10. #include <limits.h>
  11. #define OPTION_CODE_COMPILE 1
  12. #include "flowreplay_opts.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. tSCC zCopyright[] =
  17. "flowreplay copyright (c) 2004-2005 Aaron Turner, all rights reserved";
  18. tSCC zCopyrightNotice[] =
  19. "flowreplay is free software copyrighted by Aaron Turner.\n\n\
  20. Redistribution and use in source and binary forms, with or without\n\
  21. modification, are permitted provided that the following conditions\n\
  22. are met:\n\
  23. 1. Redistributions of source code must retain the above copyright\n\
  24. notice, this list of conditions and the following disclaimer.\n\
  25. 2. Redistributions in binary form must reproduce the above copyright\n\
  26. notice, this list of conditions and the following disclaimer in the\n\
  27. documentation and/or other materials provided with the distribution.\n\
  28. 3. Neither the name ``Aaron Turner'' nor the name of any other\n\
  29. contributor may be used to endorse or promote products derived\n\
  30. from this software without specific prior written permission.\n\n\
  31. flowreplay IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS\n\
  32. OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n\
  33. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\
  34. ARE DISCLAIMED. IN NO EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS\n\
  35. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n\
  36. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n\
  37. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n\
  38. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n\
  39. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n\
  40. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n\
  41. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
  42. extern tUsageProc optionUsage;
  43. /*
  44. * global included definitions
  45. */
  46. #include "defines.h"
  47. #include "flowreplay.h"
  48. #include "common.h"
  49. #include "config.h"
  50. extern char pcap_version[];
  51. extern flowreplay_opt_t options;
  52. #ifndef NULL
  53. # define NULL 0
  54. #endif
  55. #ifndef EXIT_SUCCESS
  56. # define EXIT_SUCCESS 0
  57. #endif
  58. #ifndef EXIT_FAILURE
  59. # define EXIT_FAILURE 1
  60. #endif
  61. /*
  62. * Dbug option description:
  63. */
  64. tSCC zDbugText[] =
  65. "Enable debugging output";
  66. tSCC zDbug_NAME[] = "DBUG";
  67. tSCC zDbug_Name[] = "dbug";
  68. #define zDbugDefaultArg ((const char*)0)
  69. #define DBUG_FLAGS (OPTST_DISABLED \
  70. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  71. /*
  72. * Verbose option description:
  73. */
  74. #ifdef HAVE_TCPDUMP
  75. tSCC zVerboseText[] =
  76. "Print decoded packets via tcpdump to STDOUT";
  77. tSCC zVerbose_NAME[] = "VERBOSE";
  78. tSCC zVerbose_Name[] = "verbose";
  79. #define VERBOSE_FLAGS (OPTST_DISABLED)
  80. #else /* disable Verbose */
  81. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  82. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  83. #define zVerboseText NULL
  84. #define zVerbose_NAME NULL
  85. #define zVerbose_Name NULL
  86. #endif /* HAVE_TCPDUMP */
  87. /*
  88. * Decode option description with
  89. * "Must also have options" and "Incompatible options":
  90. */
  91. #ifdef HAVE_TCPDUMP
  92. tSCC zDecodeText[] =
  93. "Arguments passed to tcpdump decoder";
  94. tSCC zDecode_NAME[] = "DECODE";
  95. tSCC zDecode_Name[] = "decode";
  96. static const int
  97. aDecodeMustList[] = {
  98. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  99. #define DECODE_FLAGS (OPTST_DISABLED \
  100. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  101. #else /* disable Decode */
  102. #define VALUE_OPT_DECODE NO_EQUIVALENT
  103. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  104. #define aDecodeMustList NULL
  105. #define zDecodeText NULL
  106. #define zDecode_NAME NULL
  107. #define zDecode_Name NULL
  108. #endif /* HAVE_TCPDUMP */
  109. /*
  110. * Mode option description:
  111. */
  112. tSCC zModeText[] =
  113. "Replay mode";
  114. tSCC zMode_NAME[] = "MODE";
  115. tSCC zMode_Name[] = "mode";
  116. #define MODE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  117. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  118. /*
  119. * Wait option description:
  120. */
  121. tSCC zWaitText[] =
  122. "Number of sec.usec to wait between client's turn to send";
  123. tSCC zWait_NAME[] = "WAIT";
  124. tSCC zWait_Name[] = "wait";
  125. #define WAIT_FLAGS (OPTST_DISABLED \
  126. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  127. /*
  128. * Targetip option description:
  129. */
  130. tSCC zTargetipText[] =
  131. "Target host to connect to";
  132. tSCC zTargetip_NAME[] = "TARGETIP";
  133. tSCC zTargetip_Name[] = "targetip";
  134. #define TARGETIP_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  135. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  136. /*
  137. * Filter option description:
  138. */
  139. tSCC zFilterText[] =
  140. "BPF filter to limit which flows are replayed";
  141. tSCC zFilter_NAME[] = "FILTER";
  142. tSCC zFilter_Name[] = "filter";
  143. #define FILTER_FLAGS (OPTST_DISABLED \
  144. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  145. /*
  146. * Clientnet option description:
  147. */
  148. tSCC zClientnetText[] =
  149. "Client network(s)";
  150. tSCC zClientnet_NAME[] = "CLIENTNET";
  151. tSCC zClientnet_Name[] = "clientnet";
  152. #define CLIENTNET_FLAGS (OPTST_DISABLED \
  153. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  154. /*
  155. * Servernet option description:
  156. */
  157. tSCC zServernetText[] =
  158. "Server network(s)";
  159. tSCC zServernet_NAME[] = "SERVERNET";
  160. tSCC zServernet_Name[] = "servernet";
  161. #define SERVERNET_FLAGS (OPTST_DISABLED \
  162. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  163. /*
  164. * Nosyn option description:
  165. */
  166. tSCC zNosynText[] =
  167. "Disable Syn packet requirement to start connections";
  168. tSCC zNosyn_NAME[] = "NOSYN";
  169. tSCC zNosyn_Name[] = "nosyn";
  170. #define NOSYN_FLAGS (OPTST_DISABLED)
  171. /*
  172. * Slimit option description:
  173. */
  174. tSCC zSlimitText[] =
  175. "Service limit to proto/port";
  176. tSCC zSlimit_NAME[] = "SLIMIT";
  177. tSCC zSlimit_Name[] = "slimit";
  178. #define SLIMIT_FLAGS (OPTST_DISABLED \
  179. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  180. /*
  181. * Version option description:
  182. */
  183. tSCC zVersionText[] =
  184. "Print version information";
  185. tSCC zVersion_NAME[] = "VERSION";
  186. tSCC zVersion_Name[] = "version";
  187. #define VERSION_FLAGS (OPTST_DISABLED)
  188. /*
  189. * Less_Help option description:
  190. */
  191. tSCC zLess_HelpText[] =
  192. "Display less usage information and exit";
  193. tSCC zLess_Help_NAME[] = "LESS_HELP";
  194. tSCC zLess_Help_Name[] = "less-help";
  195. #define LESS_HELP_FLAGS (OPTST_DISABLED)
  196. /*
  197. * Help/More_Help option descriptions:
  198. */
  199. tSCC zHelpText[] = "Display usage information and exit";
  200. tSCC zHelp_Name[] = "help";
  201. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  202. tSCC zMore_Help_Name[] = "more-help";
  203. /*
  204. * Save/Load_Opts option description:
  205. */
  206. tSCC zSave_OptsText[] = "Save the option state to a config file";
  207. tSCC zSave_Opts_Name[] = "save-opts";
  208. tSCC zLoad_OptsText[] = "Load options from a config file";
  209. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  210. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  211. tSCC zNotLoad_Opts_Pfx[] = "no";
  212. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  213. /*
  214. * Declare option callback procedures
  215. */
  216. extern tOptProc
  217. optionPagedUsage;
  218. static tOptProc
  219. doOptClientnet, doOptDbug, doOptLess_Help, doOptMode,
  220. doOptNosyn, doOptServernet, doOptSlimit, doOptTargetip,
  221. doOptVersion, doOptWait, doUsageOpt;
  222. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  223. *
  224. * Define the Flowreplay Option Descriptions.
  225. */
  226. static tOptDesc optDesc[ OPTION_CT ] = {
  227. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  228. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  229. /* equivalenced to */ NO_EQUIVALENT,
  230. /* min, max, act ct */ 0, 1, 0,
  231. /* opt state flags */ DBUG_FLAGS, 0,
  232. /* last opt argumnt */ zDbugDefaultArg,
  233. /* arg list/cookie */ NULL,
  234. /* must/cannot opts */ NULL, NULL,
  235. /* option proc */ doOptDbug,
  236. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  237. /* disablement strs */ NULL, NULL },
  238. { /* entry idx, value */ 1, VALUE_OPT_VERBOSE,
  239. /* equiv idx, value */ 1, VALUE_OPT_VERBOSE,
  240. /* equivalenced to */ NO_EQUIVALENT,
  241. /* min, max, act ct */ 0, 1, 0,
  242. /* opt state flags */ VERBOSE_FLAGS, 0,
  243. /* last opt argumnt */ NULL,
  244. /* arg list/cookie */ NULL,
  245. /* must/cannot opts */ NULL, NULL,
  246. /* option proc */ NULL,
  247. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  248. /* disablement strs */ NULL, NULL },
  249. { /* entry idx, value */ 2, VALUE_OPT_DECODE,
  250. /* equiv idx, value */ 2, VALUE_OPT_DECODE,
  251. /* equivalenced to */ NO_EQUIVALENT,
  252. /* min, max, act ct */ 0, 1, 0,
  253. /* opt state flags */ DECODE_FLAGS, 0,
  254. /* last opt argumnt */ NULL,
  255. /* arg list/cookie */ NULL,
  256. /* must/cannot opts */ aDecodeMustList, NULL,
  257. /* option proc */ NULL,
  258. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  259. /* disablement strs */ NULL, NULL },
  260. { /* entry idx, value */ 3, VALUE_OPT_MODE,
  261. /* equiv idx, value */ 3, VALUE_OPT_MODE,
  262. /* equivalenced to */ NO_EQUIVALENT,
  263. /* min, max, act ct */ 1, 1, 0,
  264. /* opt state flags */ MODE_FLAGS, 0,
  265. /* last opt argumnt */ NULL,
  266. /* arg list/cookie */ NULL,
  267. /* must/cannot opts */ NULL, NULL,
  268. /* option proc */ doOptMode,
  269. /* desc, NAME, name */ zModeText, zMode_NAME, zMode_Name,
  270. /* disablement strs */ NULL, NULL },
  271. { /* entry idx, value */ 4, VALUE_OPT_WAIT,
  272. /* equiv idx, value */ 4, VALUE_OPT_WAIT,
  273. /* equivalenced to */ NO_EQUIVALENT,
  274. /* min, max, act ct */ 0, 1, 0,
  275. /* opt state flags */ WAIT_FLAGS, 0,
  276. /* last opt argumnt */ NULL,
  277. /* arg list/cookie */ NULL,
  278. /* must/cannot opts */ NULL, NULL,
  279. /* option proc */ doOptWait,
  280. /* desc, NAME, name */ zWaitText, zWait_NAME, zWait_Name,
  281. /* disablement strs */ NULL, NULL },
  282. { /* entry idx, value */ 5, VALUE_OPT_TARGETIP,
  283. /* equiv idx, value */ 5, VALUE_OPT_TARGETIP,
  284. /* equivalenced to */ NO_EQUIVALENT,
  285. /* min, max, act ct */ 1, 1, 0,
  286. /* opt state flags */ TARGETIP_FLAGS, 0,
  287. /* last opt argumnt */ NULL,
  288. /* arg list/cookie */ NULL,
  289. /* must/cannot opts */ NULL, NULL,
  290. /* option proc */ doOptTargetip,
  291. /* desc, NAME, name */ zTargetipText, zTargetip_NAME, zTargetip_Name,
  292. /* disablement strs */ NULL, NULL },
  293. { /* entry idx, value */ 6, VALUE_OPT_FILTER,
  294. /* equiv idx, value */ 6, VALUE_OPT_FILTER,
  295. /* equivalenced to */ NO_EQUIVALENT,
  296. /* min, max, act ct */ 0, 1, 0,
  297. /* opt state flags */ FILTER_FLAGS, 0,
  298. /* last opt argumnt */ NULL,
  299. /* arg list/cookie */ NULL,
  300. /* must/cannot opts */ NULL, NULL,
  301. /* option proc */ NULL,
  302. /* desc, NAME, name */ zFilterText, zFilter_NAME, zFilter_Name,
  303. /* disablement strs */ NULL, NULL },
  304. { /* entry idx, value */ 7, VALUE_OPT_CLIENTNET,
  305. /* equiv idx, value */ 7, VALUE_OPT_CLIENTNET,
  306. /* equivalenced to */ NO_EQUIVALENT,
  307. /* min, max, act ct */ 0, 1, 0,
  308. /* opt state flags */ CLIENTNET_FLAGS, 0,
  309. /* last opt argumnt */ NULL,
  310. /* arg list/cookie */ NULL,
  311. /* must/cannot opts */ NULL, NULL,
  312. /* option proc */ doOptClientnet,
  313. /* desc, NAME, name */ zClientnetText, zClientnet_NAME, zClientnet_Name,
  314. /* disablement strs */ NULL, NULL },
  315. { /* entry idx, value */ 8, VALUE_OPT_SERVERNET,
  316. /* equiv idx, value */ 8, VALUE_OPT_SERVERNET,
  317. /* equivalenced to */ NO_EQUIVALENT,
  318. /* min, max, act ct */ 0, 1, 0,
  319. /* opt state flags */ SERVERNET_FLAGS, 0,
  320. /* last opt argumnt */ NULL,
  321. /* arg list/cookie */ NULL,
  322. /* must/cannot opts */ NULL, NULL,
  323. /* option proc */ doOptServernet,
  324. /* desc, NAME, name */ zServernetText, zServernet_NAME, zServernet_Name,
  325. /* disablement strs */ NULL, NULL },
  326. { /* entry idx, value */ 9, VALUE_OPT_NOSYN,
  327. /* equiv idx, value */ 9, VALUE_OPT_NOSYN,
  328. /* equivalenced to */ NO_EQUIVALENT,
  329. /* min, max, act ct */ 0, 1, 0,
  330. /* opt state flags */ NOSYN_FLAGS, 0,
  331. /* last opt argumnt */ NULL,
  332. /* arg list/cookie */ NULL,
  333. /* must/cannot opts */ NULL, NULL,
  334. /* option proc */ doOptNosyn,
  335. /* desc, NAME, name */ zNosynText, zNosyn_NAME, zNosyn_Name,
  336. /* disablement strs */ NULL, NULL },
  337. { /* entry idx, value */ 10, VALUE_OPT_SLIMIT,
  338. /* equiv idx, value */ 10, VALUE_OPT_SLIMIT,
  339. /* equivalenced to */ NO_EQUIVALENT,
  340. /* min, max, act ct */ 0, 1, 0,
  341. /* opt state flags */ SLIMIT_FLAGS, 0,
  342. /* last opt argumnt */ NULL,
  343. /* arg list/cookie */ NULL,
  344. /* must/cannot opts */ NULL, NULL,
  345. /* option proc */ doOptSlimit,
  346. /* desc, NAME, name */ zSlimitText, zSlimit_NAME, zSlimit_Name,
  347. /* disablement strs */ NULL, NULL },
  348. { /* entry idx, value */ 11, VALUE_OPT_VERSION,
  349. /* equiv idx, value */ 11, VALUE_OPT_VERSION,
  350. /* equivalenced to */ NO_EQUIVALENT,
  351. /* min, max, act ct */ 0, 1, 0,
  352. /* opt state flags */ VERSION_FLAGS, 0,
  353. /* last opt argumnt */ NULL,
  354. /* arg list/cookie */ NULL,
  355. /* must/cannot opts */ NULL, NULL,
  356. /* option proc */ doOptVersion,
  357. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  358. /* disablement strs */ NULL, NULL },
  359. { /* entry idx, value */ 12, VALUE_OPT_LESS_HELP,
  360. /* equiv idx, value */ 12, VALUE_OPT_LESS_HELP,
  361. /* equivalenced to */ NO_EQUIVALENT,
  362. /* min, max, act ct */ 0, 1, 0,
  363. /* opt state flags */ LESS_HELP_FLAGS, 0,
  364. /* last opt argumnt */ NULL,
  365. /* arg list/cookie */ NULL,
  366. /* must/cannot opts */ NULL, NULL,
  367. /* option proc */ doOptLess_Help,
  368. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  369. /* disablement strs */ NULL, NULL },
  370. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  371. /* equiv idx value */ NO_EQUIVALENT, 0,
  372. /* equivalenced to */ NO_EQUIVALENT,
  373. /* min, max, act ct */ 0, 1, 0,
  374. /* opt state flags */ OPTST_IMM, 0,
  375. /* last opt argumnt */ NULL,
  376. /* arg list/cookie */ NULL,
  377. /* must/cannot opts */ NULL, NULL,
  378. /* option proc */ doUsageOpt,
  379. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  380. /* disablement strs */ NULL, NULL },
  381. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  382. /* equiv idx value */ NO_EQUIVALENT, 0,
  383. /* equivalenced to */ NO_EQUIVALENT,
  384. /* min, max, act ct */ 0, 1, 0,
  385. /* opt state flags */ OPTST_IMM, 0,
  386. /* last opt argumnt */ NULL,
  387. /* arg list/cookie */ NULL,
  388. /* must/cannot opts */ NULL, NULL,
  389. /* option proc */ optionPagedUsage,
  390. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  391. /* disablement strs */ NULL, NULL },
  392. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  393. /* equiv idx value */ NO_EQUIVALENT, 0,
  394. /* equivalenced to */ NO_EQUIVALENT,
  395. /* min, max, act ct */ 0, 1, 0,
  396. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  397. | OPTST_ARG_OPTIONAL, 0,
  398. /* last opt argumnt */ NULL,
  399. /* arg list/cookie */ NULL,
  400. /* must/cannot opts */ NULL, NULL,
  401. /* option proc */ NULL,
  402. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  403. /* disablement strs */ NULL, NULL },
  404. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  405. /* equiv idx value */ NO_EQUIVALENT, 0,
  406. /* equivalenced to */ NO_EQUIVALENT,
  407. /* min, max, act ct */ 0, NOLIMIT, 0,
  408. /* opt state flags */ OPTST_DISABLE_IMM | \
  409. OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
  410. /* last opt argumnt */ NULL,
  411. /* arg list/cookie */ NULL,
  412. /* must/cannot opts */ NULL, NULL,
  413. /* option proc */ optionLoadOpt,
  414. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  415. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  416. };
  417. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  418. *
  419. * Define the Flowreplay Option Environment
  420. */
  421. tSCC zPROGNAME[] = "FLOWREPLAY";
  422. tSCC zUsageTitle[] =
  423. "flowreplay (flowreplay) - Connect to servers based on network traffic stored in pcap files\n\
  424. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... <pcap_file(s)>\n";
  425. tSCC zRcName[] = ".flowreplayrc";
  426. tSCC* apzHomeList[] = {
  427. "$$/",
  428. NULL };
  429. #define zBugsAddr NULL
  430. tSCC zExplain[] = "\n\
  431. flowreplay is a tool for using network traffic stored in pcap(3) files as\n\
  432. the basis for replaying connections to servers.\n";
  433. tSCC zDetail[] = "\n\
  434. Please note that flowreplay is currently in *alpha*. As such, it is still\n\
  435. very much a work in progress and currently will not work for most uses. If\n\
  436. you have the skill and interest to help make flowreplay work better, please\n\
  437. contact Aaron Turner.\n";
  438. #define zFullVersion NULL
  439. /* extracted from optcode near line 321 */
  440. #if defined(ENABLE_NLS)
  441. # define OPTPROC_BASE OPTPROC_TRANSLATE
  442. static tOptionXlateProc translate_option_strings;
  443. #else
  444. # define OPTPROC_BASE OPTPROC_NONE
  445. # define translate_option_strings NULL
  446. #endif /* ENABLE_NLS */
  447. tOptions flowreplayOptions = {
  448. OPTIONS_STRUCT_VERSION,
  449. 0, NULL, /* original argc + argv */
  450. ( OPTPROC_BASE
  451. + OPTPROC_ERRSTOP
  452. + OPTPROC_SHORTOPT
  453. + OPTPROC_LONGOPT
  454. + OPTPROC_NO_REQ_OPT
  455. + OPTPROC_ARGS_REQ
  456. + OPTPROC_GNUUSAGE
  457. + OPTPROC_HAS_IMMED ),
  458. 0, NULL, /* current option index, current option */
  459. NULL, NULL, zPROGNAME,
  460. zRcName, zCopyright, zCopyrightNotice,
  461. zFullVersion, apzHomeList, zUsageTitle,
  462. zExplain, zDetail, optDesc,
  463. zBugsAddr, /* address to send bugs to */
  464. NULL, NULL, /* extensions/saved state */
  465. optionUsage, /* usage procedure */
  466. translate_option_strings, /* translation procedure */
  467. /*
  468. * Indexes to special options
  469. */
  470. { INDEX_OPT_MORE_HELP,
  471. INDEX_OPT_SAVE_OPTS,
  472. NO_EQUIVALENT /* index of '-#' option */,
  473. 4 /* index of default opt */
  474. },
  475. OPTION_CT, 13 /* user option count */
  476. };
  477. /*
  478. * Create the static procedure(s) declared above.
  479. */
  480. static void
  481. doUsageOpt(
  482. tOptions* pOptions,
  483. tOptDesc* pOptDesc )
  484. {
  485. USAGE( EXIT_SUCCESS );
  486. }
  487. /* * * * * * *
  488. *
  489. * For the dbug option.
  490. */
  491. static void
  492. doOptDbug(
  493. tOptions* pOptions,
  494. tOptDesc* pOptDesc )
  495. {
  496. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  497. { 0, 5 } };
  498. long val;
  499. int ix;
  500. const char* pzIndent = "\t\t\t\t ";
  501. extern FILE* option_usage_fp;
  502. if (pOptDesc == NULL) /* usage is requesting range list
  503. option_usage_fp has already been set */
  504. goto emit_ranges;
  505. val = atoi( pOptDesc->pzLastArg );
  506. for (ix = 0; ix < 1; ix++) {
  507. if (val < rng[ix].rmin)
  508. continue; /* ranges need not be ordered. */
  509. if (val == rng[ix].rmin)
  510. goto valid_return;
  511. if (rng[ix].rmax == INT_MIN)
  512. continue;
  513. if (val <= rng[ix].rmax)
  514. goto valid_return;
  515. }
  516. option_usage_fp = stderr;
  517. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  518. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  519. pzIndent = "\t";
  520. emit_ranges:
  521. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  522. pzIndent, rng[0].rmin, rng[0].rmax );
  523. if (pOptDesc == NULL)
  524. return;
  525. USAGE( EXIT_FAILURE );
  526. /* NOTREACHED */
  527. return;
  528. valid_return:
  529. pOptDesc->pzLastArg = (char*)val;
  530. }
  531. /* * * * * * *
  532. *
  533. * For the mode option.
  534. */
  535. static void
  536. doOptMode(
  537. tOptions* pOptions,
  538. tOptDesc* pOptDesc )
  539. {
  540. if (strcasecmp(OPT_ARG(MODE), "send") == 0) {
  541. options.sendmode = MODE_SEND;
  542. } else if (strcasecmp(OPT_ARG(MODE), "wait") == 0) {
  543. options.sendmode = MODE_WAIT;
  544. } else if (strcasecmp(OPT_ARG(MODE), "bytes") == 0) {
  545. options.sendmode = MODE_BYTES;
  546. } else if (strcasecmp(OPT_ARG(MODE), "user") == 0) {
  547. options.sendmode = MODE_USER;
  548. } else {
  549. errx(1, "Invalid --mode: %s", OPT_ARG(MODE));
  550. }
  551. }
  552. /* * * * * * *
  553. *
  554. * For the wait option.
  555. */
  556. static void
  557. doOptWait(
  558. tOptions* pOptions,
  559. tOptDesc* pOptDesc )
  560. {
  561. float2timer(atof(OPT_ARG(WAIT)), &options.timeout);
  562. }
  563. /* * * * * * *
  564. *
  565. * For the targetip option.
  566. */
  567. static void
  568. doOptTargetip(
  569. tOptions* pOptions,
  570. tOptDesc* pOptDesc )
  571. {
  572. #ifdef INET_ATON
  573. if (inet_aton(OPT_ARG(TARGETIP), &options.targetaddr) == 0)
  574. errx(1, "Invalid target IP address: %s", OPT_ARG(TARGETIP));
  575. #else
  576. if ((options.targetaddr.s_addr = inet_addr(OPT_ARG(TARGETIP))) == -1)
  577. errx(1, "Invalid target IP address: %s", OPT_ARG(TARGETIP));
  578. #endif
  579. }
  580. /* * * * * * *
  581. *
  582. * For the clientnet option.
  583. */
  584. static void
  585. doOptClientnet(
  586. tOptions* pOptions,
  587. tOptDesc* pOptDesc )
  588. {
  589. char *cidr = safe_strdup(OPT_ARG(CLIENTNET));
  590. if (!parse_cidr(&options.clients, cidr, ","))
  591. errx(1, "Unable to parse CIDR: %s", OPT_ARG(CLIENTNET));
  592. free(cidr);
  593. }
  594. /* * * * * * *
  595. *
  596. * For the servernet option.
  597. */
  598. static void
  599. doOptServernet(
  600. tOptions* pOptions,
  601. tOptDesc* pOptDesc )
  602. {
  603. char *cidr = safe_strdup(OPT_ARG(SERVERNET));
  604. if (!parse_cidr(&options.servers, cidr, ","))
  605. errx(1, "Unable to parse CIDR: %s", OPT_ARG(SERVERNET));
  606. free(cidr);
  607. }
  608. /* * * * * * *
  609. *
  610. * For the nosyn option.
  611. */
  612. static void
  613. doOptNosyn(
  614. tOptions* pOptions,
  615. tOptDesc* pOptDesc )
  616. {
  617. options.nosyn = 1;
  618. }
  619. /* * * * * * *
  620. *
  621. * For the slimit option.
  622. */
  623. static void
  624. doOptSlimit(
  625. tOptions* pOptions,
  626. tOptDesc* pOptDesc )
  627. {
  628. char *p_parse = NULL, *myarg;
  629. myarg = safe_strdup(OPT_ARG(SLIMIT));
  630. p_parse = strtok(myarg, "/");
  631. if (strcasecmp(p_parse, "TCP") == 0) {
  632. options.proto = IPPROTO_TCP;
  633. } else if (strcasecmp(p_parse, "UDP") == 0) {
  634. options.proto = IPPROTO_UDP;
  635. } else {
  636. errx(1, "Unsupported protocol: %s", p_parse);
  637. }
  638. /* if port is specified, set it */
  639. if ((p_parse = strtok(NULL, "/")))
  640. options.port = htons(atoi(p_parse));
  641. }
  642. /* * * * * * *
  643. *
  644. * For the version option.
  645. */
  646. static void
  647. doOptVersion(
  648. tOptions* pOptions,
  649. tOptDesc* pOptDesc )
  650. {
  651. fprintf(stderr, "flowreplay version: %s (build %s)", VERSION, svn_version());
  652. #ifdef DEBUG
  653. fprintf(stderr, " (debug)");
  654. #endif
  655. fprintf(stderr, "\n");
  656. fprintf(stderr, "Copyright 2001-2006 by Aaron Turner <aturner at synfin dot net>\n");
  657. #ifdef HAVE_LIBNET
  658. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  659. #else
  660. fprintf(stderr, "Not compiled with libnet.\n");
  661. #endif
  662. fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
  663. #ifdef ENABLE_64BITS
  664. fprintf(stderr, "64 bit packet counters: enabled\n");
  665. #else
  666. fprintf(stderr, "64 bit packet counters: disabled\n");
  667. #endif
  668. #ifdef HAVE_TCPDUMP
  669. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  670. #else
  671. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  672. #endif
  673. exit(0);
  674. }
  675. /* * * * * * *
  676. *
  677. * For the less-help option.
  678. */
  679. static void
  680. doOptLess_Help(
  681. tOptions* pOptions,
  682. tOptDesc* pOptDesc )
  683. {
  684. USAGE(EXIT_FAILURE);
  685. }
  686. /* extracted from optcode near line 418 */
  687. #if ENABLE_NLS
  688. #include <stdio.h>
  689. #include <string.h>
  690. #include <unistd.h>
  691. #include <autoopts/usage-txt.h>
  692. static char*
  693. AO_gettext( const char* pz )
  694. {
  695. char* pzRes;
  696. if (pz == NULL)
  697. return NULL;
  698. pzRes = _(pz);
  699. if (pzRes == pz)
  700. return pzRes;
  701. pzRes = strdup( pzRes );
  702. if (pzRes == NULL) {
  703. fputs( _("No memory for duping translated strings\n"), stderr );
  704. exit( EXIT_FAILURE );
  705. }
  706. return pzRes;
  707. }
  708. /*
  709. * This invokes the translation code (e.g. gettext(3)).
  710. */
  711. static void
  712. translate_option_strings( void )
  713. {
  714. /*
  715. * Guard against re-translation. It won't work. The strings will have
  716. * been changed by the first pass through this code. One shot only.
  717. */
  718. if (option_usage_text.field_ct == 0)
  719. return;
  720. /*
  721. * Do the translations. The first pointer follows the field count field.
  722. * The field count field is the size of a pointer.
  723. */
  724. {
  725. char** ppz = (char**)(void*)&(option_usage_text);
  726. int ix = option_usage_text.field_ct;
  727. do {
  728. ppz++;
  729. *ppz = AO_gettext(*ppz);
  730. } while (--ix > 0);
  731. }
  732. option_usage_text.field_ct = 0;
  733. {
  734. tOptDesc* pOD = flowreplayOptions.pOptDesc;
  735. int ix = flowreplayOptions.optCt;
  736. for (;;) {
  737. pOD->pzText = AO_gettext(pOD->pzText);
  738. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  739. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  740. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  741. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  742. if (--ix <= 0)
  743. break;
  744. pOD++;
  745. }
  746. }
  747. flowreplayOptions.pzCopyright = AO_gettext(flowreplayOptions.pzCopyright);
  748. flowreplayOptions.pzCopyNotice = AO_gettext(flowreplayOptions.pzCopyNotice);
  749. flowreplayOptions.pzFullVersion = AO_gettext(flowreplayOptions.pzFullVersion);
  750. flowreplayOptions.pzUsageTitle = AO_gettext(flowreplayOptions.pzUsageTitle);
  751. flowreplayOptions.pzExplain = AO_gettext(flowreplayOptions.pzExplain);
  752. flowreplayOptions.pzDetail = AO_gettext(flowreplayOptions.pzDetail);
  753. }
  754. #endif /* ENABLE_NLS */
  755. #ifdef __cplusplus
  756. }
  757. #endif