tcpreplay_opts.c 29 KB

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