flowreplay_opts.c 25 KB

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