tcpreplay_opts.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (tcpreplay_opts.c)
  4. *
  5. * It has been AutoGen-ed Thursday July 28, 2005 at 09:57:13 PM PDT
  6. * From the definitions tcpreplay_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 "tcpreplay_opts.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. tSCC zCopyright[] =
  17. "tcpreplay copyright (c) 2000-2005 Aaron Turner, all rights reserved";
  18. tSCC zCopyrightNotice[] =
  19. "tcpreplay 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. tcpreplay 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 "tcpreplay.h"
  48. #include "common.h"
  49. extern char pcap_version[];
  50. extern tcpreplay_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. * Cachefile option description:
  110. */
  111. tSCC zCachefileText[] =
  112. "Split traffic via a tcppep cache file";
  113. tSCC zCachefile_NAME[] = "CACHEFILE";
  114. tSCC zCachefile_Name[] = "cachefile";
  115. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  116. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  117. /*
  118. * Intf1 option description:
  119. */
  120. tSCC zIntf1Text[] =
  121. "Server/primary traffic output interface";
  122. tSCC zIntf1_NAME[] = "INTF1";
  123. tSCC zIntf1_Name[] = "intf1";
  124. #define INTF1_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  125. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  126. /*
  127. * Intf2 option description with
  128. * "Must also have options" and "Incompatible options":
  129. */
  130. tSCC zIntf2Text[] =
  131. "Client/secondary traffic output interface";
  132. tSCC zIntf2_NAME[] = "INTF2";
  133. tSCC zIntf2_Name[] = "intf2";
  134. static const int
  135. aIntf2MustList[] = {
  136. INDEX_OPT_CACHEFILE, NO_EQUIVALENT };
  137. #define INTF2_FLAGS (OPTST_DISABLED \
  138. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  139. /*
  140. * Loop option description:
  141. */
  142. tSCC zLoopText[] =
  143. "Loop through the capture file X times";
  144. tSCC zLoop_NAME[] = "LOOP";
  145. tSCC zLoop_Name[] = "loop";
  146. #define zLoopDefaultArg ((tCC*)1)
  147. #define LOOP_FLAGS (OPTST_DISABLED \
  148. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  149. /*
  150. * Pktlen option description:
  151. */
  152. tSCC zPktlenText[] =
  153. "Override the snaplen and use the actual packet len";
  154. tSCC zPktlen_NAME[] = "PKTLEN";
  155. tSCC zPktlen_Name[] = "pktlen";
  156. #define PKTLEN_FLAGS (OPTST_DISABLED)
  157. /*
  158. * Multiplier option description with
  159. * "Must also have options" and "Incompatible options":
  160. */
  161. tSCC zMultiplierText[] =
  162. "Modify replay speed to a given multiple";
  163. tSCC zMultiplier_NAME[] = "MULTIPLIER";
  164. tSCC zMultiplier_Name[] = "multiplier";
  165. static const int
  166. aMultiplierCantList[] = {
  167. INDEX_OPT_PPS,
  168. INDEX_OPT_MBPS,
  169. INDEX_OPT_ONEATATIME,
  170. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  171. #define MULTIPLIER_FLAGS (OPTST_DISABLED \
  172. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  173. /*
  174. * Pps option description with
  175. * "Must also have options" and "Incompatible options":
  176. */
  177. tSCC zPpsText[] =
  178. "Replay packets at a given packets/sec";
  179. tSCC zPps_NAME[] = "PPS";
  180. tSCC zPps_Name[] = "pps";
  181. static const int
  182. aPpsCantList[] = {
  183. INDEX_OPT_MULTIPLIER,
  184. INDEX_OPT_MBPS,
  185. INDEX_OPT_ONEATATIME,
  186. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  187. #define PPS_FLAGS (OPTST_DISABLED \
  188. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  189. /*
  190. * Mbps option description with
  191. * "Must also have options" and "Incompatible options":
  192. */
  193. tSCC zMbpsText[] =
  194. "Replay packets at a given Mbps";
  195. tSCC zMbps_NAME[] = "MBPS";
  196. tSCC zMbps_Name[] = "mbps";
  197. static const int
  198. aMbpsCantList[] = {
  199. INDEX_OPT_MULTIPLIER,
  200. INDEX_OPT_PPS,
  201. INDEX_OPT_ONEATATIME,
  202. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  203. #define MBPS_FLAGS (OPTST_DISABLED \
  204. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  205. /*
  206. * Topspeed option description with
  207. * "Must also have options" and "Incompatible options":
  208. */
  209. tSCC zTopspeedText[] =
  210. "Replay packets as fast as possible";
  211. tSCC zTopspeed_NAME[] = "TOPSPEED";
  212. tSCC zTopspeed_Name[] = "topspeed";
  213. static const int
  214. aTopspeedCantList[] = {
  215. INDEX_OPT_MBPS,
  216. INDEX_OPT_MULTIPLIER,
  217. INDEX_OPT_PPS,
  218. INDEX_OPT_ONEATATIME, NO_EQUIVALENT };
  219. #define TOPSPEED_FLAGS (OPTST_DISABLED)
  220. /*
  221. * Oneatatime option description with
  222. * "Must also have options" and "Incompatible options":
  223. */
  224. tSCC zOneatatimeText[] =
  225. "Replay one packet at a time for each user input";
  226. tSCC zOneatatime_NAME[] = "ONEATATIME";
  227. tSCC zOneatatime_Name[] = "oneatatime";
  228. static const int
  229. aOneatatimeCantList[] = {
  230. INDEX_OPT_MBPS,
  231. INDEX_OPT_PPS,
  232. INDEX_OPT_MULTIPLIER,
  233. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  234. #define ONEATATIME_FLAGS (OPTST_DISABLED)
  235. /*
  236. * Pid option description:
  237. */
  238. tSCC zPidText[] =
  239. "Print the PID of tcpreplay at startup";
  240. tSCC zPid_NAME[] = "PID";
  241. tSCC zPid_Name[] = "pid";
  242. #define PID_FLAGS (OPTST_DISABLED)
  243. /*
  244. * Version option description:
  245. */
  246. tSCC zVersionText[] =
  247. "Print version information";
  248. tSCC zVersion_NAME[] = "VERSION";
  249. tSCC zVersion_Name[] = "version";
  250. #define VERSION_FLAGS (OPTST_DISABLED)
  251. /*
  252. * Less_Help option description:
  253. */
  254. tSCC zLess_HelpText[] =
  255. "Display less usage information and exit";
  256. tSCC zLess_Help_NAME[] = "LESS_HELP";
  257. tSCC zLess_Help_Name[] = "less-help";
  258. #define LESS_HELP_FLAGS (OPTST_DISABLED)
  259. /*
  260. * Help/More_Help option descriptions:
  261. */
  262. tSCC zHelpText[] = "Display usage information and exit";
  263. tSCC zHelp_Name[] = "help";
  264. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  265. tSCC zMore_Help_Name[] = "more-help";
  266. /*
  267. * Save/Load_Opts option description:
  268. */
  269. tSCC zSave_OptsText[] = "Save the option state to a config file";
  270. tSCC zSave_Opts_Name[] = "save-opts";
  271. tSCC zLoad_OptsText[] = "Load options from a config file";
  272. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  273. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  274. tSCC zNotLoad_Opts_Pfx[] = "no";
  275. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  276. /*
  277. * Declare option callback procedures
  278. */
  279. extern tOptProc
  280. optionNumericVal, optionPagedUsage;
  281. static tOptProc
  282. doOptDbug, doOptLess_Help, doOptLoop, doOptPid,
  283. doOptVersion, doUsageOpt;
  284. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  285. *
  286. * Define the Tcpreplay Option Descriptions.
  287. */
  288. static tOptDesc optDesc[ OPTION_CT ] = {
  289. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  290. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  291. /* equivalenced to */ NO_EQUIVALENT,
  292. /* min, max, act ct */ 0, 1, 0,
  293. /* opt state flags */ DBUG_FLAGS, 0,
  294. /* last opt argumnt */ zDbugDefaultArg,
  295. /* arg list/cookie */ NULL,
  296. /* must/cannot opts */ NULL, NULL,
  297. /* option proc */ doOptDbug,
  298. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  299. /* disablement strs */ NULL, NULL },
  300. { /* entry idx, value */ 1, VALUE_OPT_VERBOSE,
  301. /* equiv idx, value */ 1, VALUE_OPT_VERBOSE,
  302. /* equivalenced to */ NO_EQUIVALENT,
  303. /* min, max, act ct */ 0, 1, 0,
  304. /* opt state flags */ VERBOSE_FLAGS, 0,
  305. /* last opt argumnt */ NULL,
  306. /* arg list/cookie */ NULL,
  307. /* must/cannot opts */ NULL, NULL,
  308. /* option proc */ NULL,
  309. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  310. /* disablement strs */ NULL, NULL },
  311. { /* entry idx, value */ 2, VALUE_OPT_DECODE,
  312. /* equiv idx, value */ 2, VALUE_OPT_DECODE,
  313. /* equivalenced to */ NO_EQUIVALENT,
  314. /* min, max, act ct */ 0, 1, 0,
  315. /* opt state flags */ DECODE_FLAGS, 0,
  316. /* last opt argumnt */ NULL,
  317. /* arg list/cookie */ NULL,
  318. /* must/cannot opts */ aDecodeMustList, NULL,
  319. /* option proc */ NULL,
  320. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  321. /* disablement strs */ NULL, NULL },
  322. { /* entry idx, value */ 3, VALUE_OPT_CACHEFILE,
  323. /* equiv idx, value */ 3, VALUE_OPT_CACHEFILE,
  324. /* equivalenced to */ NO_EQUIVALENT,
  325. /* min, max, act ct */ 0, 1, 0,
  326. /* opt state flags */ CACHEFILE_FLAGS, 0,
  327. /* last opt argumnt */ NULL,
  328. /* arg list/cookie */ NULL,
  329. /* must/cannot opts */ NULL, NULL,
  330. /* option proc */ NULL,
  331. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  332. /* disablement strs */ NULL, NULL },
  333. { /* entry idx, value */ 4, VALUE_OPT_INTF1,
  334. /* equiv idx, value */ 4, VALUE_OPT_INTF1,
  335. /* equivalenced to */ NO_EQUIVALENT,
  336. /* min, max, act ct */ 1, 1, 0,
  337. /* opt state flags */ INTF1_FLAGS, 0,
  338. /* last opt argumnt */ NULL,
  339. /* arg list/cookie */ NULL,
  340. /* must/cannot opts */ NULL, NULL,
  341. /* option proc */ NULL,
  342. /* desc, NAME, name */ zIntf1Text, zIntf1_NAME, zIntf1_Name,
  343. /* disablement strs */ NULL, NULL },
  344. { /* entry idx, value */ 5, VALUE_OPT_INTF2,
  345. /* equiv idx, value */ 5, VALUE_OPT_INTF2,
  346. /* equivalenced to */ NO_EQUIVALENT,
  347. /* min, max, act ct */ 0, 1, 0,
  348. /* opt state flags */ INTF2_FLAGS, 0,
  349. /* last opt argumnt */ NULL,
  350. /* arg list/cookie */ NULL,
  351. /* must/cannot opts */ aIntf2MustList, NULL,
  352. /* option proc */ NULL,
  353. /* desc, NAME, name */ zIntf2Text, zIntf2_NAME, zIntf2_Name,
  354. /* disablement strs */ NULL, NULL },
  355. { /* entry idx, value */ 6, VALUE_OPT_LOOP,
  356. /* equiv idx, value */ 6, VALUE_OPT_LOOP,
  357. /* equivalenced to */ NO_EQUIVALENT,
  358. /* min, max, act ct */ 0, 1, 0,
  359. /* opt state flags */ LOOP_FLAGS, 0,
  360. /* last opt argumnt */ zLoopDefaultArg,
  361. /* arg list/cookie */ NULL,
  362. /* must/cannot opts */ NULL, NULL,
  363. /* option proc */ doOptLoop,
  364. /* desc, NAME, name */ zLoopText, zLoop_NAME, zLoop_Name,
  365. /* disablement strs */ NULL, NULL },
  366. { /* entry idx, value */ 7, VALUE_OPT_PKTLEN,
  367. /* equiv idx, value */ 7, VALUE_OPT_PKTLEN,
  368. /* equivalenced to */ NO_EQUIVALENT,
  369. /* min, max, act ct */ 0, 1, 0,
  370. /* opt state flags */ PKTLEN_FLAGS, 0,
  371. /* last opt argumnt */ NULL,
  372. /* arg list/cookie */ NULL,
  373. /* must/cannot opts */ NULL, NULL,
  374. /* option proc */ NULL,
  375. /* desc, NAME, name */ zPktlenText, zPktlen_NAME, zPktlen_Name,
  376. /* disablement strs */ NULL, NULL },
  377. { /* entry idx, value */ 8, VALUE_OPT_MULTIPLIER,
  378. /* equiv idx, value */ 8, VALUE_OPT_MULTIPLIER,
  379. /* equivalenced to */ NO_EQUIVALENT,
  380. /* min, max, act ct */ 0, 1, 0,
  381. /* opt state flags */ MULTIPLIER_FLAGS, 0,
  382. /* last opt argumnt */ NULL,
  383. /* arg list/cookie */ NULL,
  384. /* must/cannot opts */ NULL, aMultiplierCantList,
  385. /* option proc */ NULL,
  386. /* desc, NAME, name */ zMultiplierText, zMultiplier_NAME, zMultiplier_Name,
  387. /* disablement strs */ NULL, NULL },
  388. { /* entry idx, value */ 9, VALUE_OPT_PPS,
  389. /* equiv idx, value */ 9, VALUE_OPT_PPS,
  390. /* equivalenced to */ NO_EQUIVALENT,
  391. /* min, max, act ct */ 0, 1, 0,
  392. /* opt state flags */ PPS_FLAGS, 0,
  393. /* last opt argumnt */ NULL,
  394. /* arg list/cookie */ NULL,
  395. /* must/cannot opts */ NULL, aPpsCantList,
  396. /* option proc */ optionNumericVal,
  397. /* desc, NAME, name */ zPpsText, zPps_NAME, zPps_Name,
  398. /* disablement strs */ NULL, NULL },
  399. { /* entry idx, value */ 10, VALUE_OPT_MBPS,
  400. /* equiv idx, value */ 10, VALUE_OPT_MBPS,
  401. /* equivalenced to */ NO_EQUIVALENT,
  402. /* min, max, act ct */ 0, 1, 0,
  403. /* opt state flags */ MBPS_FLAGS, 0,
  404. /* last opt argumnt */ NULL,
  405. /* arg list/cookie */ NULL,
  406. /* must/cannot opts */ NULL, aMbpsCantList,
  407. /* option proc */ NULL,
  408. /* desc, NAME, name */ zMbpsText, zMbps_NAME, zMbps_Name,
  409. /* disablement strs */ NULL, NULL },
  410. { /* entry idx, value */ 11, VALUE_OPT_TOPSPEED,
  411. /* equiv idx, value */ 11, VALUE_OPT_TOPSPEED,
  412. /* equivalenced to */ NO_EQUIVALENT,
  413. /* min, max, act ct */ 0, 1, 0,
  414. /* opt state flags */ TOPSPEED_FLAGS, 0,
  415. /* last opt argumnt */ NULL,
  416. /* arg list/cookie */ NULL,
  417. /* must/cannot opts */ NULL, aTopspeedCantList,
  418. /* option proc */ NULL,
  419. /* desc, NAME, name */ zTopspeedText, zTopspeed_NAME, zTopspeed_Name,
  420. /* disablement strs */ NULL, NULL },
  421. { /* entry idx, value */ 12, VALUE_OPT_ONEATATIME,
  422. /* equiv idx, value */ 12, VALUE_OPT_ONEATATIME,
  423. /* equivalenced to */ NO_EQUIVALENT,
  424. /* min, max, act ct */ 0, 1, 0,
  425. /* opt state flags */ ONEATATIME_FLAGS, 0,
  426. /* last opt argumnt */ NULL,
  427. /* arg list/cookie */ NULL,
  428. /* must/cannot opts */ NULL, aOneatatimeCantList,
  429. /* option proc */ NULL,
  430. /* desc, NAME, name */ zOneatatimeText, zOneatatime_NAME, zOneatatime_Name,
  431. /* disablement strs */ NULL, NULL },
  432. { /* entry idx, value */ 13, VALUE_OPT_PID,
  433. /* equiv idx, value */ 13, VALUE_OPT_PID,
  434. /* equivalenced to */ NO_EQUIVALENT,
  435. /* min, max, act ct */ 0, 1, 0,
  436. /* opt state flags */ PID_FLAGS, 0,
  437. /* last opt argumnt */ NULL,
  438. /* arg list/cookie */ NULL,
  439. /* must/cannot opts */ NULL, NULL,
  440. /* option proc */ doOptPid,
  441. /* desc, NAME, name */ zPidText, zPid_NAME, zPid_Name,
  442. /* disablement strs */ NULL, NULL },
  443. { /* entry idx, value */ 14, VALUE_OPT_VERSION,
  444. /* equiv idx, value */ 14, VALUE_OPT_VERSION,
  445. /* equivalenced to */ NO_EQUIVALENT,
  446. /* min, max, act ct */ 0, 1, 0,
  447. /* opt state flags */ VERSION_FLAGS, 0,
  448. /* last opt argumnt */ NULL,
  449. /* arg list/cookie */ NULL,
  450. /* must/cannot opts */ NULL, NULL,
  451. /* option proc */ doOptVersion,
  452. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  453. /* disablement strs */ NULL, NULL },
  454. { /* entry idx, value */ 15, VALUE_OPT_LESS_HELP,
  455. /* equiv idx, value */ 15, VALUE_OPT_LESS_HELP,
  456. /* equivalenced to */ NO_EQUIVALENT,
  457. /* min, max, act ct */ 0, 1, 0,
  458. /* opt state flags */ LESS_HELP_FLAGS, 0,
  459. /* last opt argumnt */ NULL,
  460. /* arg list/cookie */ NULL,
  461. /* must/cannot opts */ NULL, NULL,
  462. /* option proc */ doOptLess_Help,
  463. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  464. /* disablement strs */ NULL, NULL },
  465. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  466. /* equiv idx value */ NO_EQUIVALENT, 0,
  467. /* equivalenced to */ NO_EQUIVALENT,
  468. /* min, max, act ct */ 0, 1, 0,
  469. /* opt state flags */ OPTST_IMM, 0,
  470. /* last opt argumnt */ NULL,
  471. /* arg list/cookie */ NULL,
  472. /* must/cannot opts */ NULL, NULL,
  473. /* option proc */ doUsageOpt,
  474. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  475. /* disablement strs */ NULL, NULL },
  476. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  477. /* equiv idx value */ NO_EQUIVALENT, 0,
  478. /* equivalenced to */ NO_EQUIVALENT,
  479. /* min, max, act ct */ 0, 1, 0,
  480. /* opt state flags */ OPTST_IMM, 0,
  481. /* last opt argumnt */ NULL,
  482. /* arg list/cookie */ NULL,
  483. /* must/cannot opts */ NULL, NULL,
  484. /* option proc */ optionPagedUsage,
  485. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  486. /* disablement strs */ NULL, NULL },
  487. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  488. /* equiv idx value */ NO_EQUIVALENT, 0,
  489. /* equivalenced to */ NO_EQUIVALENT,
  490. /* min, max, act ct */ 0, 1, 0,
  491. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  492. | OPTST_ARG_OPTIONAL, 0,
  493. /* last opt argumnt */ NULL,
  494. /* arg list/cookie */ NULL,
  495. /* must/cannot opts */ NULL, NULL,
  496. /* option proc */ NULL,
  497. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  498. /* disablement strs */ NULL, NULL },
  499. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  500. /* equiv idx value */ NO_EQUIVALENT, 0,
  501. /* equivalenced to */ NO_EQUIVALENT,
  502. /* min, max, act ct */ 0, NOLIMIT, 0,
  503. /* opt state flags */ OPTST_DISABLE_IMM | \
  504. OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
  505. /* last opt argumnt */ NULL,
  506. /* arg list/cookie */ NULL,
  507. /* must/cannot opts */ NULL, NULL,
  508. /* option proc */ optionLoadOpt,
  509. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  510. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  511. };
  512. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  513. *
  514. * Define the Tcpreplay Option Environment
  515. */
  516. tSCC zPROGNAME[] = "TCPREPLAY";
  517. tSCC zUsageTitle[] =
  518. "tcpreplay - Replay network traffic stored in pcap files\n\
  519. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... <pcap_file(s)>\n";
  520. tSCC zRcName[] = ".tcpreplayrc";
  521. tSCC* apzHomeList[] = {
  522. "$$/",
  523. NULL };
  524. #define zBugsAddr NULL
  525. tSCC zExplain[] = "\n\
  526. tcpreplay is a tool for replaying network traffic from files saved with\n\
  527. tcpdump or other tools which write pcap(3) files.\n";
  528. tSCC zDetail[] = "\n\
  529. The basic operation of tcpreplay is to resend all packets from the\n\
  530. input file(s) at the speed at which they were recorded, or a specified \n\
  531. data rate, up to as fast as the hardware is capable.\n\n\
  532. Optionally, the traffic can be split between two interfaces, written to\n\
  533. files, filtered and edited in various ways, providing the means to test\n\
  534. firewalls, NIDS and other network devices.\n";
  535. #define zFullVersion NULL
  536. /* extracted from /usr/local/share/autogen/optcode.tpl near line 309 */
  537. #if defined(ENABLE_NLS)
  538. # define OPTPROC_BASE OPTPROC_TRANSLATE
  539. static tOptionXlateProc translate_option_strings;
  540. #else
  541. # define OPTPROC_BASE OPTPROC_NONE
  542. # define translate_option_strings NULL
  543. #endif /* ENABLE_NLS */
  544. tOptions tcpreplayOptions = {
  545. OPTIONS_STRUCT_VERSION,
  546. 0, NULL, /* original argc + argv */
  547. ( OPTPROC_BASE
  548. + OPTPROC_ERRSTOP
  549. + OPTPROC_SHORTOPT
  550. + OPTPROC_LONGOPT
  551. + OPTPROC_NO_REQ_OPT
  552. + OPTPROC_ARGS_REQ
  553. + OPTPROC_GNUUSAGE
  554. + OPTPROC_HAS_IMMED ),
  555. 0, NULL, /* current option index, current option */
  556. NULL, NULL, zPROGNAME,
  557. zRcName, zCopyright, zCopyrightNotice,
  558. zFullVersion, apzHomeList, zUsageTitle,
  559. zExplain, zDetail, optDesc,
  560. zBugsAddr, /* address to send bugs to */
  561. NULL, NULL, /* extensions/saved state */
  562. optionUsage, /* usage procedure */
  563. translate_option_strings, /* translation procedure */
  564. /*
  565. * Indexes to special options
  566. */
  567. { INDEX_OPT_MORE_HELP,
  568. INDEX_OPT_SAVE_OPTS,
  569. NO_EQUIVALENT /* index of '-#' option */,
  570. NO_EQUIVALENT /* index of default opt */
  571. },
  572. OPTION_CT, 16 /* user option count */
  573. };
  574. /*
  575. * Create the static procedure(s) declared above.
  576. */
  577. static void
  578. doUsageOpt(
  579. tOptions* pOptions,
  580. tOptDesc* pOptDesc )
  581. {
  582. USAGE( EXIT_SUCCESS );
  583. }
  584. /* * * * * * *
  585. *
  586. * For the dbug option.
  587. */
  588. static void
  589. doOptDbug(
  590. tOptions* pOptions,
  591. tOptDesc* pOptDesc )
  592. {
  593. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  594. { 0, 5 } };
  595. long val;
  596. int ix;
  597. tCC* pzIndent = "\t\t\t\t ";
  598. extern FILE* option_usage_fp;
  599. if (pOptDesc == NULL) /* usage is requesting range list
  600. option_usage_fp has already been set */
  601. goto emit_ranges;
  602. val = atoi( pOptDesc->pzLastArg );
  603. for (ix = 0; ix < 1; ix++) {
  604. if (val < rng[ix].rmin)
  605. continue; /* ranges need not be ordered. */
  606. if (val == rng[ix].rmin)
  607. goto valid_return;
  608. if (rng[ix].rmax == INT_MIN)
  609. continue;
  610. if (val <= rng[ix].rmax)
  611. goto valid_return;
  612. }
  613. option_usage_fp = stderr;
  614. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  615. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  616. pzIndent = "\t";
  617. emit_ranges:
  618. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  619. pzIndent, rng[0].rmin, rng[0].rmax );
  620. if (pOptDesc == NULL)
  621. return;
  622. USAGE( EXIT_FAILURE );
  623. /* NOTREACHED */
  624. return;
  625. valid_return:
  626. pOptDesc->pzLastArg = (char*)val;
  627. }
  628. /* * * * * * *
  629. *
  630. * For the loop option.
  631. */
  632. static void
  633. doOptLoop(
  634. tOptions* pOptions,
  635. tOptDesc* pOptDesc )
  636. {
  637. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  638. { 0, INT_MAX } };
  639. long val;
  640. int ix;
  641. tCC* pzIndent = "\t\t\t\t ";
  642. extern FILE* option_usage_fp;
  643. if (pOptDesc == NULL) /* usage is requesting range list
  644. option_usage_fp has already been set */
  645. goto emit_ranges;
  646. val = atoi( pOptDesc->pzLastArg );
  647. for (ix = 0; ix < 1; ix++) {
  648. if (val < rng[ix].rmin)
  649. continue; /* ranges need not be ordered. */
  650. if (val == rng[ix].rmin)
  651. goto valid_return;
  652. if (rng[ix].rmax == INT_MIN)
  653. continue;
  654. if (val <= rng[ix].rmax)
  655. goto valid_return;
  656. }
  657. option_usage_fp = stderr;
  658. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  659. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  660. pzIndent = "\t";
  661. emit_ranges:
  662. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  663. pzIndent, rng[0].rmin, rng[0].rmax );
  664. if (pOptDesc == NULL)
  665. return;
  666. USAGE( EXIT_FAILURE );
  667. /* NOTREACHED */
  668. return;
  669. valid_return:
  670. pOptDesc->pzLastArg = (char*)val;
  671. }
  672. /* * * * * * *
  673. *
  674. * For the pid option.
  675. */
  676. static void
  677. doOptPid(
  678. tOptions* pOptions,
  679. tOptDesc* pOptDesc )
  680. {
  681. fprintf(stderr, "PID: %hu\n", getpid());
  682. }
  683. /* * * * * * *
  684. *
  685. * For the version option.
  686. */
  687. static void
  688. doOptVersion(
  689. tOptions* pOptions,
  690. tOptDesc* pOptDesc )
  691. {
  692. fprintf(stderr, "tcpreplay version: %s (build %s)", VERSION, svn_version());
  693. #ifdef DEBUG
  694. fprintf(stderr, " (debug)");
  695. #endif
  696. fprintf(stderr, "\n");
  697. fprintf(stderr, "Copyright 2001-2005 by Aaron Turner <aturner@pobox.com>\n");
  698. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  699. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  700. fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
  701. #ifdef ENABLE_64BITS
  702. fprintf(stderr, "64 bit packet counters: enabled\n");
  703. #else
  704. fprintf(stderr, "64 bit packet counters: disabled\n");
  705. #endif
  706. #ifdef HAVE_TCPDUMP
  707. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  708. #else
  709. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  710. #endif
  711. exit(0);
  712. }
  713. /* * * * * * *
  714. *
  715. * For the less-help option.
  716. */
  717. static void
  718. doOptLess_Help(
  719. tOptions* pOptions,
  720. tOptDesc* pOptDesc )
  721. {
  722. USAGE(EXIT_FAILURE);
  723. }
  724. /* extracted from /usr/local/share/autogen/optcode.tpl near line 396 */
  725. #if ENABLE_NLS
  726. #include <string.h>
  727. #include <stdio.h>
  728. #include <autoopts/usage-txt.h>
  729. static char*
  730. AO_gettext( const char* pz )
  731. {
  732. char* pzRes;
  733. if (pz == NULL)
  734. return NULL;
  735. pzRes = _(pz);
  736. if (pzRes == pz)
  737. return pzRes;
  738. pzRes = strdup( pzRes );
  739. if (pzRes == NULL) {
  740. fputs( _("No memory for duping translated strings\n"), stderr );
  741. exit( EXIT_FAILURE );
  742. }
  743. return pzRes;
  744. }
  745. /*
  746. * This invokes the translation code (e.g. gettext(3)).
  747. */
  748. static void
  749. translate_option_strings( void )
  750. {
  751. /*
  752. * Guard against re-translation. It won't work. The strings will have
  753. * been changed by the first pass through this code. One shot only.
  754. */
  755. if (option_usage_text.field_ct == 0)
  756. return;
  757. /*
  758. * Do the translations. The first pointer follows the field count field.
  759. * The field count field is the size of a pointer.
  760. */
  761. {
  762. char** ppz = (char**)(void*)&(option_usage_text);
  763. int ix = option_usage_text.field_ct;
  764. do {
  765. ppz++;
  766. *ppz = AO_gettext(*ppz);
  767. } while (--ix > 0);
  768. }
  769. option_usage_text.field_ct = 0;
  770. {
  771. tOptDesc* pOD = tcpreplayOptions.pOptDesc;
  772. int ix = tcpreplayOptions.optCt;
  773. for (;;) {
  774. pOD->pzText = AO_gettext(pOD->pzText);
  775. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  776. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  777. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  778. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  779. if (--ix <= 0)
  780. break;
  781. pOD++;
  782. }
  783. }
  784. tcpreplayOptions.pzCopyright = AO_gettext(tcpreplayOptions.pzCopyright);
  785. tcpreplayOptions.pzCopyNotice = AO_gettext(tcpreplayOptions.pzCopyNotice);
  786. tcpreplayOptions.pzFullVersion = AO_gettext(tcpreplayOptions.pzFullVersion);
  787. tcpreplayOptions.pzUsageTitle = AO_gettext(tcpreplayOptions.pzUsageTitle);
  788. tcpreplayOptions.pzExplain = AO_gettext(tcpreplayOptions.pzExplain);
  789. tcpreplayOptions.pzDetail = AO_gettext(tcpreplayOptions.pzDetail);
  790. }
  791. #endif /* ENABLE_NLS */
  792. #ifdef __cplusplus
  793. }
  794. #endif