flowreplay_opts.c 29 KB

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