tcpreplay_opts.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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 June 9, 2008 at 11:05:37 AM PDT
  6. * From the definitions tcpreplay_opts.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 30:0:5 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. * tcpreplay 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. * tcpreplay copyright 2000-2008 Aaron Turner - all rights reserved
  23. *
  24. * tcpreplay 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. * tcpreplay 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 "tcpreplay_opts.h"
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. tSCC zCopyright[] =
  58. "tcpreplay copyright (c) 2000-2008 Aaron Turner, all rights reserved";
  59. tSCC zCopyrightNotice[] =
  60. "tcpreplay 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. tcpreplay 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 "tcpreplay.h"
  89. #include "common.h"
  90. #include "config.h"
  91. #include <stdlib.h>
  92. #include <sys/types.h>
  93. #include <unistd.h>
  94. extern tcpreplay_opt_t options;
  95. #ifndef NULL
  96. # define NULL 0
  97. #endif
  98. #ifndef EXIT_SUCCESS
  99. # define EXIT_SUCCESS 0
  100. #endif
  101. #ifndef EXIT_FAILURE
  102. # define EXIT_FAILURE 1
  103. #endif
  104. /*
  105. * Dbug option description:
  106. */
  107. #ifdef DEBUG
  108. tSCC zDbugText[] =
  109. "Enable debugging output";
  110. tSCC zDbug_NAME[] = "DBUG";
  111. tSCC zDbug_Name[] = "dbug";
  112. #define zDbugDefaultArg ((char const*)0)
  113. #define DBUG_FLAGS (OPTST_DISABLED | OPTST_IMM \
  114. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  115. #else /* disable Dbug */
  116. #define VALUE_OPT_DBUG NO_EQUIVALENT
  117. #define DBUG_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  118. #define zDbugDefaultArg NULL
  119. #define zDbugText NULL
  120. #define zDbug_NAME NULL
  121. #define zDbug_Name NULL
  122. #endif /* DEBUG */
  123. /*
  124. * Quiet option description:
  125. */
  126. tSCC zQuietText[] =
  127. "Quiet mode";
  128. tSCC zQuiet_NAME[] = "QUIET";
  129. tSCC zQuiet_Name[] = "quiet";
  130. #define QUIET_FLAGS (OPTST_DISABLED)
  131. /*
  132. * Timer option description:
  133. */
  134. tSCC zTimerText[] =
  135. "Select packet timing mode: select, ioport, rdtsc, gtod, nano, abstime";
  136. tSCC zTimer_NAME[] = "TIMER";
  137. tSCC zTimer_Name[] = "timer";
  138. tSCC zTimerDefaultArg[] = "gtod";
  139. #define TIMER_FLAGS (OPTST_DISABLED \
  140. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  141. /*
  142. * Sleep_Accel option description:
  143. */
  144. tSCC zSleep_AccelText[] =
  145. "Reduce the amount of time to sleep by specified usec";
  146. tSCC zSleep_Accel_NAME[] = "SLEEP_ACCEL";
  147. tSCC zSleep_Accel_Name[] = "sleep-accel";
  148. #define zSleep_AccelDefaultArg ((char const*)0)
  149. #define SLEEP_ACCEL_FLAGS (OPTST_DISABLED \
  150. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  151. /*
  152. * Rdtsc_Clicks option description:
  153. */
  154. tSCC zRdtsc_ClicksText[] =
  155. "Specify the RDTSC clicks/usec";
  156. tSCC zRdtsc_Clicks_NAME[] = "RDTSC_CLICKS";
  157. tSCC zRdtsc_Clicks_Name[] = "rdtsc-clicks";
  158. #define zRdtsc_ClicksDefaultArg ((char const*)0)
  159. #define RDTSC_CLICKS_FLAGS (OPTST_DISABLED \
  160. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  161. /*
  162. * Verbose option description:
  163. */
  164. #ifdef ENABLE_VERBOSE
  165. tSCC zVerboseText[] =
  166. "Print decoded packets via tcpdump to STDOUT";
  167. tSCC zVerbose_NAME[] = "VERBOSE";
  168. tSCC zVerbose_Name[] = "verbose";
  169. #define VERBOSE_FLAGS (OPTST_DISABLED | OPTST_IMM)
  170. #else /* disable Verbose */
  171. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  172. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  173. #define zVerboseText NULL
  174. #define zVerbose_NAME NULL
  175. #define zVerbose_Name NULL
  176. #endif /* ENABLE_VERBOSE */
  177. /*
  178. * Decode option description with
  179. * "Must also have options" and "Incompatible options":
  180. */
  181. #ifdef ENABLE_VERBOSE
  182. tSCC zDecodeText[] =
  183. "Arguments passed to tcpdump decoder";
  184. tSCC zDecode_NAME[] = "DECODE";
  185. tSCC zDecode_Name[] = "decode";
  186. static const int
  187. aDecodeMustList[] = {
  188. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  189. #define DECODE_FLAGS (OPTST_DISABLED \
  190. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  191. #else /* disable Decode */
  192. #define VALUE_OPT_DECODE NO_EQUIVALENT
  193. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  194. #define aDecodeMustList NULL
  195. #define zDecodeText NULL
  196. #define zDecode_NAME NULL
  197. #define zDecode_Name NULL
  198. #endif /* ENABLE_VERBOSE */
  199. /*
  200. * Enable_File_Cache option description with
  201. * "Must also have options" and "Incompatible options":
  202. */
  203. tSCC zEnable_File_CacheText[] =
  204. "Enable caching of packets to internal memory";
  205. tSCC zEnable_File_Cache_NAME[] = "ENABLE_FILE_CACHE";
  206. tSCC zEnable_File_Cache_Name[] = "enable-file-cache";
  207. static const int
  208. aEnable_File_CacheMustList[] = {
  209. INDEX_OPT_LOOP, NO_EQUIVALENT };
  210. #define ENABLE_FILE_CACHE_FLAGS (OPTST_DISABLED)
  211. /*
  212. * Cachefile option description:
  213. */
  214. tSCC zCachefileText[] =
  215. "Split traffic via a tcpprep cache file";
  216. tSCC zCachefile_NAME[] = "CACHEFILE";
  217. tSCC zCachefile_Name[] = "cachefile";
  218. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  219. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  220. /*
  221. * Intf1 option description:
  222. */
  223. tSCC zIntf1Text[] =
  224. "Server/primary traffic output interface";
  225. tSCC zIntf1_NAME[] = "INTF1";
  226. tSCC zIntf1_Name[] = "intf1";
  227. #define INTF1_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  228. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  229. /*
  230. * Intf2 option description with
  231. * "Must also have options" and "Incompatible options":
  232. */
  233. tSCC zIntf2Text[] =
  234. "Client/secondary traffic output interface";
  235. tSCC zIntf2_NAME[] = "INTF2";
  236. tSCC zIntf2_Name[] = "intf2";
  237. static const int
  238. aIntf2MustList[] = {
  239. INDEX_OPT_CACHEFILE, NO_EQUIVALENT };
  240. #define INTF2_FLAGS (OPTST_DISABLED \
  241. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  242. /*
  243. * Listnics option description:
  244. */
  245. #ifdef ENABLE_PCAP_FINDALLDEVS
  246. tSCC zListnicsText[] =
  247. "List available network interfaces and exit";
  248. tSCC zListnics_NAME[] = "LISTNICS";
  249. tSCC zListnics_Name[] = "listnics";
  250. #define LISTNICS_FLAGS (OPTST_DISABLED | OPTST_IMM)
  251. #else /* disable Listnics */
  252. #define VALUE_OPT_LISTNICS NO_EQUIVALENT
  253. #define LISTNICS_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  254. #define zListnicsText NULL
  255. #define zListnics_NAME NULL
  256. #define zListnics_Name NULL
  257. #endif /* ENABLE_PCAP_FINDALLDEVS */
  258. /*
  259. * Loop option description:
  260. */
  261. tSCC zLoopText[] =
  262. "Loop through the capture file X times";
  263. tSCC zLoop_NAME[] = "LOOP";
  264. tSCC zLoop_Name[] = "loop";
  265. #define zLoopDefaultArg ((char const*)1)
  266. #define LOOP_FLAGS (OPTST_DISABLED \
  267. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  268. /*
  269. * Pktlen option description:
  270. */
  271. tSCC zPktlenText[] =
  272. "Override the snaplen and use the actual packet len";
  273. tSCC zPktlen_NAME[] = "PKTLEN";
  274. tSCC zPktlen_Name[] = "pktlen";
  275. #define PKTLEN_FLAGS (OPTST_DISABLED)
  276. /*
  277. * Limit option description:
  278. */
  279. tSCC zLimitText[] =
  280. "Limit the number of packets to send";
  281. tSCC zLimit_NAME[] = "LIMIT";
  282. tSCC zLimit_Name[] = "limit";
  283. #define zLimitDefaultArg ((char const*)-1)
  284. #define LIMIT_FLAGS (OPTST_DISABLED \
  285. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  286. /*
  287. * Multiplier option description with
  288. * "Must also have options" and "Incompatible options":
  289. */
  290. tSCC zMultiplierText[] =
  291. "Modify replay speed to a given multiple";
  292. tSCC zMultiplier_NAME[] = "MULTIPLIER";
  293. tSCC zMultiplier_Name[] = "multiplier";
  294. static const int
  295. aMultiplierCantList[] = {
  296. INDEX_OPT_PPS,
  297. INDEX_OPT_MBPS,
  298. INDEX_OPT_ONEATATIME,
  299. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  300. #define MULTIPLIER_FLAGS (OPTST_DISABLED \
  301. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  302. /*
  303. * Pps option description with
  304. * "Must also have options" and "Incompatible options":
  305. */
  306. tSCC zPpsText[] =
  307. "Replay packets at a given packets/sec";
  308. tSCC zPps_NAME[] = "PPS";
  309. tSCC zPps_Name[] = "pps";
  310. static const int
  311. aPpsCantList[] = {
  312. INDEX_OPT_MULTIPLIER,
  313. INDEX_OPT_MBPS,
  314. INDEX_OPT_ONEATATIME,
  315. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  316. #define PPS_FLAGS (OPTST_DISABLED \
  317. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  318. /*
  319. * Mbps option description with
  320. * "Must also have options" and "Incompatible options":
  321. */
  322. tSCC zMbpsText[] =
  323. "Replay packets at a given Mbps";
  324. tSCC zMbps_NAME[] = "MBPS";
  325. tSCC zMbps_Name[] = "mbps";
  326. static const int
  327. aMbpsCantList[] = {
  328. INDEX_OPT_MULTIPLIER,
  329. INDEX_OPT_PPS,
  330. INDEX_OPT_ONEATATIME,
  331. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  332. #define MBPS_FLAGS (OPTST_DISABLED \
  333. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  334. /*
  335. * Topspeed option description with
  336. * "Must also have options" and "Incompatible options":
  337. */
  338. tSCC zTopspeedText[] =
  339. "Replay packets as fast as possible";
  340. tSCC zTopspeed_NAME[] = "TOPSPEED";
  341. tSCC zTopspeed_Name[] = "topspeed";
  342. static const int
  343. aTopspeedCantList[] = {
  344. INDEX_OPT_MBPS,
  345. INDEX_OPT_MULTIPLIER,
  346. INDEX_OPT_PPS,
  347. INDEX_OPT_ONEATATIME, NO_EQUIVALENT };
  348. #define TOPSPEED_FLAGS (OPTST_DISABLED)
  349. /*
  350. * Oneatatime option description with
  351. * "Must also have options" and "Incompatible options":
  352. */
  353. tSCC zOneatatimeText[] =
  354. "Replay one packet at a time for each user input";
  355. tSCC zOneatatime_NAME[] = "ONEATATIME";
  356. tSCC zOneatatime_Name[] = "oneatatime";
  357. static const int
  358. aOneatatimeCantList[] = {
  359. INDEX_OPT_MBPS,
  360. INDEX_OPT_PPS,
  361. INDEX_OPT_MULTIPLIER,
  362. INDEX_OPT_TOPSPEED, NO_EQUIVALENT };
  363. #define ONEATATIME_FLAGS (OPTST_DISABLED)
  364. /*
  365. * Pid option description:
  366. */
  367. tSCC zPidText[] =
  368. "Print the PID of tcpreplay at startup";
  369. tSCC zPid_NAME[] = "PID";
  370. tSCC zPid_Name[] = "pid";
  371. #define PID_FLAGS (OPTST_DISABLED)
  372. /*
  373. * Version option description:
  374. */
  375. tSCC zVersionText[] =
  376. "Print version information";
  377. tSCC zVersion_NAME[] = "VERSION";
  378. tSCC zVersion_Name[] = "version";
  379. #define VERSION_FLAGS (OPTST_DISABLED)
  380. /*
  381. * Less_Help option description:
  382. */
  383. tSCC zLess_HelpText[] =
  384. "Display less usage information and exit";
  385. tSCC zLess_Help_NAME[] = "LESS_HELP";
  386. tSCC zLess_Help_Name[] = "less-help";
  387. #define LESS_HELP_FLAGS (OPTST_DISABLED | OPTST_IMM)
  388. /*
  389. * Help/More_Help option descriptions:
  390. */
  391. tSCC zHelpText[] = "Display usage information and exit";
  392. tSCC zHelp_Name[] = "help";
  393. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  394. tSCC zMore_Help_Name[] = "more-help";
  395. /*
  396. * Save/Load_Opts option description:
  397. */
  398. tSCC zSave_OptsText[] = "Save the option state to a config file";
  399. tSCC zSave_Opts_Name[] = "save-opts";
  400. tSCC zLoad_OptsText[] = "Load options from a config file";
  401. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  402. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  403. tSCC zNotLoad_Opts_Pfx[] = "no";
  404. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  405. /*
  406. * Declare option callback procedures
  407. */
  408. #ifdef DEBUG
  409. static tOptProc doOptDbug;
  410. #else /* not DEBUG */
  411. # define doOptDbug NULL
  412. #endif /* def/not DEBUG */
  413. #ifdef ENABLE_PCAP_FINDALLDEVS
  414. static tOptProc doOptListnics;
  415. #else /* not ENABLE_PCAP_FINDALLDEVS */
  416. # define doOptListnics NULL
  417. #endif /* def/not ENABLE_PCAP_FINDALLDEVS */
  418. extern tOptProc
  419. optionNumericVal, optionPagedUsage;
  420. static tOptProc
  421. doOptLess_Help, doOptLimit, doOptLoop, doOptPid,
  422. doOptVersion, doUsageOpt;
  423. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  424. *
  425. * Define the Tcpreplay Option Descriptions.
  426. */
  427. static tOptDesc optDesc[ OPTION_CT ] = {
  428. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  429. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  430. /* equivalenced to */ NO_EQUIVALENT,
  431. /* min, max, act ct */ 0, 1, 0,
  432. /* opt state flags */ DBUG_FLAGS, 0,
  433. /* last opt argumnt */ { zDbugDefaultArg },
  434. /* arg list/cookie */ NULL,
  435. /* must/cannot opts */ NULL, NULL,
  436. /* option proc */ doOptDbug,
  437. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  438. /* disablement strs */ NULL, NULL },
  439. { /* entry idx, value */ 1, VALUE_OPT_QUIET,
  440. /* equiv idx, value */ 1, VALUE_OPT_QUIET,
  441. /* equivalenced to */ NO_EQUIVALENT,
  442. /* min, max, act ct */ 0, 1, 0,
  443. /* opt state flags */ QUIET_FLAGS, 0,
  444. /* last opt argumnt */ { NULL },
  445. /* arg list/cookie */ NULL,
  446. /* must/cannot opts */ NULL, NULL,
  447. /* option proc */ NULL,
  448. /* desc, NAME, name */ zQuietText, zQuiet_NAME, zQuiet_Name,
  449. /* disablement strs */ NULL, NULL },
  450. { /* entry idx, value */ 2, VALUE_OPT_TIMER,
  451. /* equiv idx, value */ 2, VALUE_OPT_TIMER,
  452. /* equivalenced to */ NO_EQUIVALENT,
  453. /* min, max, act ct */ 0, 1, 0,
  454. /* opt state flags */ TIMER_FLAGS, 0,
  455. /* last opt argumnt */ { zTimerDefaultArg },
  456. /* arg list/cookie */ NULL,
  457. /* must/cannot opts */ NULL, NULL,
  458. /* option proc */ NULL,
  459. /* desc, NAME, name */ zTimerText, zTimer_NAME, zTimer_Name,
  460. /* disablement strs */ NULL, NULL },
  461. { /* entry idx, value */ 3, VALUE_OPT_SLEEP_ACCEL,
  462. /* equiv idx, value */ 3, VALUE_OPT_SLEEP_ACCEL,
  463. /* equivalenced to */ NO_EQUIVALENT,
  464. /* min, max, act ct */ 0, 1, 0,
  465. /* opt state flags */ SLEEP_ACCEL_FLAGS, 0,
  466. /* last opt argumnt */ { zSleep_AccelDefaultArg },
  467. /* arg list/cookie */ NULL,
  468. /* must/cannot opts */ NULL, NULL,
  469. /* option proc */ optionNumericVal,
  470. /* desc, NAME, name */ zSleep_AccelText, zSleep_Accel_NAME, zSleep_Accel_Name,
  471. /* disablement strs */ NULL, NULL },
  472. { /* entry idx, value */ 4, VALUE_OPT_RDTSC_CLICKS,
  473. /* equiv idx, value */ 4, VALUE_OPT_RDTSC_CLICKS,
  474. /* equivalenced to */ NO_EQUIVALENT,
  475. /* min, max, act ct */ 0, 1, 0,
  476. /* opt state flags */ RDTSC_CLICKS_FLAGS, 0,
  477. /* last opt argumnt */ { zRdtsc_ClicksDefaultArg },
  478. /* arg list/cookie */ NULL,
  479. /* must/cannot opts */ NULL, NULL,
  480. /* option proc */ optionNumericVal,
  481. /* desc, NAME, name */ zRdtsc_ClicksText, zRdtsc_Clicks_NAME, zRdtsc_Clicks_Name,
  482. /* disablement strs */ NULL, NULL },
  483. { /* entry idx, value */ 5, VALUE_OPT_VERBOSE,
  484. /* equiv idx, value */ 5, VALUE_OPT_VERBOSE,
  485. /* equivalenced to */ NO_EQUIVALENT,
  486. /* min, max, act ct */ 0, 1, 0,
  487. /* opt state flags */ VERBOSE_FLAGS, 0,
  488. /* last opt argumnt */ { NULL },
  489. /* arg list/cookie */ NULL,
  490. /* must/cannot opts */ NULL, NULL,
  491. /* option proc */ NULL,
  492. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  493. /* disablement strs */ NULL, NULL },
  494. { /* entry idx, value */ 6, VALUE_OPT_DECODE,
  495. /* equiv idx, value */ 6, VALUE_OPT_DECODE,
  496. /* equivalenced to */ NO_EQUIVALENT,
  497. /* min, max, act ct */ 0, 1, 0,
  498. /* opt state flags */ DECODE_FLAGS, 0,
  499. /* last opt argumnt */ { NULL },
  500. /* arg list/cookie */ NULL,
  501. /* must/cannot opts */ aDecodeMustList, NULL,
  502. /* option proc */ NULL,
  503. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  504. /* disablement strs */ NULL, NULL },
  505. { /* entry idx, value */ 7, VALUE_OPT_ENABLE_FILE_CACHE,
  506. /* equiv idx, value */ 7, VALUE_OPT_ENABLE_FILE_CACHE,
  507. /* equivalenced to */ NO_EQUIVALENT,
  508. /* min, max, act ct */ 0, 1, 0,
  509. /* opt state flags */ ENABLE_FILE_CACHE_FLAGS, 0,
  510. /* last opt argumnt */ { NULL },
  511. /* arg list/cookie */ NULL,
  512. /* must/cannot opts */ aEnable_File_CacheMustList, NULL,
  513. /* option proc */ NULL,
  514. /* desc, NAME, name */ zEnable_File_CacheText, zEnable_File_Cache_NAME, zEnable_File_Cache_Name,
  515. /* disablement strs */ NULL, NULL },
  516. { /* entry idx, value */ 8, VALUE_OPT_CACHEFILE,
  517. /* equiv idx, value */ 8, VALUE_OPT_CACHEFILE,
  518. /* equivalenced to */ NO_EQUIVALENT,
  519. /* min, max, act ct */ 0, 1, 0,
  520. /* opt state flags */ CACHEFILE_FLAGS, 0,
  521. /* last opt argumnt */ { NULL },
  522. /* arg list/cookie */ NULL,
  523. /* must/cannot opts */ NULL, NULL,
  524. /* option proc */ NULL,
  525. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  526. /* disablement strs */ NULL, NULL },
  527. { /* entry idx, value */ 9, VALUE_OPT_INTF1,
  528. /* equiv idx, value */ 9, VALUE_OPT_INTF1,
  529. /* equivalenced to */ NO_EQUIVALENT,
  530. /* min, max, act ct */ 1, 1, 0,
  531. /* opt state flags */ INTF1_FLAGS, 0,
  532. /* last opt argumnt */ { NULL },
  533. /* arg list/cookie */ NULL,
  534. /* must/cannot opts */ NULL, NULL,
  535. /* option proc */ NULL,
  536. /* desc, NAME, name */ zIntf1Text, zIntf1_NAME, zIntf1_Name,
  537. /* disablement strs */ NULL, NULL },
  538. { /* entry idx, value */ 10, VALUE_OPT_INTF2,
  539. /* equiv idx, value */ 10, VALUE_OPT_INTF2,
  540. /* equivalenced to */ NO_EQUIVALENT,
  541. /* min, max, act ct */ 0, 1, 0,
  542. /* opt state flags */ INTF2_FLAGS, 0,
  543. /* last opt argumnt */ { NULL },
  544. /* arg list/cookie */ NULL,
  545. /* must/cannot opts */ aIntf2MustList, NULL,
  546. /* option proc */ NULL,
  547. /* desc, NAME, name */ zIntf2Text, zIntf2_NAME, zIntf2_Name,
  548. /* disablement strs */ NULL, NULL },
  549. { /* entry idx, value */ 11, VALUE_OPT_LISTNICS,
  550. /* equiv idx, value */ 11, VALUE_OPT_LISTNICS,
  551. /* equivalenced to */ NO_EQUIVALENT,
  552. /* min, max, act ct */ 0, 1, 0,
  553. /* opt state flags */ LISTNICS_FLAGS, 0,
  554. /* last opt argumnt */ { NULL },
  555. /* arg list/cookie */ NULL,
  556. /* must/cannot opts */ NULL, NULL,
  557. /* option proc */ doOptListnics,
  558. /* desc, NAME, name */ zListnicsText, zListnics_NAME, zListnics_Name,
  559. /* disablement strs */ NULL, NULL },
  560. { /* entry idx, value */ 12, VALUE_OPT_LOOP,
  561. /* equiv idx, value */ 12, VALUE_OPT_LOOP,
  562. /* equivalenced to */ NO_EQUIVALENT,
  563. /* min, max, act ct */ 0, 1, 0,
  564. /* opt state flags */ LOOP_FLAGS, 0,
  565. /* last opt argumnt */ { zLoopDefaultArg },
  566. /* arg list/cookie */ NULL,
  567. /* must/cannot opts */ NULL, NULL,
  568. /* option proc */ doOptLoop,
  569. /* desc, NAME, name */ zLoopText, zLoop_NAME, zLoop_Name,
  570. /* disablement strs */ NULL, NULL },
  571. { /* entry idx, value */ 13, VALUE_OPT_PKTLEN,
  572. /* equiv idx, value */ 13, VALUE_OPT_PKTLEN,
  573. /* equivalenced to */ NO_EQUIVALENT,
  574. /* min, max, act ct */ 0, 1, 0,
  575. /* opt state flags */ PKTLEN_FLAGS, 0,
  576. /* last opt argumnt */ { NULL },
  577. /* arg list/cookie */ NULL,
  578. /* must/cannot opts */ NULL, NULL,
  579. /* option proc */ NULL,
  580. /* desc, NAME, name */ zPktlenText, zPktlen_NAME, zPktlen_Name,
  581. /* disablement strs */ NULL, NULL },
  582. { /* entry idx, value */ 14, VALUE_OPT_LIMIT,
  583. /* equiv idx, value */ 14, VALUE_OPT_LIMIT,
  584. /* equivalenced to */ NO_EQUIVALENT,
  585. /* min, max, act ct */ 0, 1, 0,
  586. /* opt state flags */ LIMIT_FLAGS, 0,
  587. /* last opt argumnt */ { zLimitDefaultArg },
  588. /* arg list/cookie */ NULL,
  589. /* must/cannot opts */ NULL, NULL,
  590. /* option proc */ doOptLimit,
  591. /* desc, NAME, name */ zLimitText, zLimit_NAME, zLimit_Name,
  592. /* disablement strs */ NULL, NULL },
  593. { /* entry idx, value */ 15, VALUE_OPT_MULTIPLIER,
  594. /* equiv idx, value */ 15, VALUE_OPT_MULTIPLIER,
  595. /* equivalenced to */ NO_EQUIVALENT,
  596. /* min, max, act ct */ 0, 1, 0,
  597. /* opt state flags */ MULTIPLIER_FLAGS, 0,
  598. /* last opt argumnt */ { NULL },
  599. /* arg list/cookie */ NULL,
  600. /* must/cannot opts */ NULL, aMultiplierCantList,
  601. /* option proc */ NULL,
  602. /* desc, NAME, name */ zMultiplierText, zMultiplier_NAME, zMultiplier_Name,
  603. /* disablement strs */ NULL, NULL },
  604. { /* entry idx, value */ 16, VALUE_OPT_PPS,
  605. /* equiv idx, value */ 16, VALUE_OPT_PPS,
  606. /* equivalenced to */ NO_EQUIVALENT,
  607. /* min, max, act ct */ 0, 1, 0,
  608. /* opt state flags */ PPS_FLAGS, 0,
  609. /* last opt argumnt */ { NULL },
  610. /* arg list/cookie */ NULL,
  611. /* must/cannot opts */ NULL, aPpsCantList,
  612. /* option proc */ optionNumericVal,
  613. /* desc, NAME, name */ zPpsText, zPps_NAME, zPps_Name,
  614. /* disablement strs */ NULL, NULL },
  615. { /* entry idx, value */ 17, VALUE_OPT_MBPS,
  616. /* equiv idx, value */ 17, VALUE_OPT_MBPS,
  617. /* equivalenced to */ NO_EQUIVALENT,
  618. /* min, max, act ct */ 0, 1, 0,
  619. /* opt state flags */ MBPS_FLAGS, 0,
  620. /* last opt argumnt */ { NULL },
  621. /* arg list/cookie */ NULL,
  622. /* must/cannot opts */ NULL, aMbpsCantList,
  623. /* option proc */ NULL,
  624. /* desc, NAME, name */ zMbpsText, zMbps_NAME, zMbps_Name,
  625. /* disablement strs */ NULL, NULL },
  626. { /* entry idx, value */ 18, VALUE_OPT_TOPSPEED,
  627. /* equiv idx, value */ 18, VALUE_OPT_TOPSPEED,
  628. /* equivalenced to */ NO_EQUIVALENT,
  629. /* min, max, act ct */ 0, 1, 0,
  630. /* opt state flags */ TOPSPEED_FLAGS, 0,
  631. /* last opt argumnt */ { NULL },
  632. /* arg list/cookie */ NULL,
  633. /* must/cannot opts */ NULL, aTopspeedCantList,
  634. /* option proc */ NULL,
  635. /* desc, NAME, name */ zTopspeedText, zTopspeed_NAME, zTopspeed_Name,
  636. /* disablement strs */ NULL, NULL },
  637. { /* entry idx, value */ 19, VALUE_OPT_ONEATATIME,
  638. /* equiv idx, value */ 19, VALUE_OPT_ONEATATIME,
  639. /* equivalenced to */ NO_EQUIVALENT,
  640. /* min, max, act ct */ 0, 1, 0,
  641. /* opt state flags */ ONEATATIME_FLAGS, 0,
  642. /* last opt argumnt */ { NULL },
  643. /* arg list/cookie */ NULL,
  644. /* must/cannot opts */ NULL, aOneatatimeCantList,
  645. /* option proc */ NULL,
  646. /* desc, NAME, name */ zOneatatimeText, zOneatatime_NAME, zOneatatime_Name,
  647. /* disablement strs */ NULL, NULL },
  648. { /* entry idx, value */ 20, VALUE_OPT_PID,
  649. /* equiv idx, value */ 20, VALUE_OPT_PID,
  650. /* equivalenced to */ NO_EQUIVALENT,
  651. /* min, max, act ct */ 0, 1, 0,
  652. /* opt state flags */ PID_FLAGS, 0,
  653. /* last opt argumnt */ { NULL },
  654. /* arg list/cookie */ NULL,
  655. /* must/cannot opts */ NULL, NULL,
  656. /* option proc */ doOptPid,
  657. /* desc, NAME, name */ zPidText, zPid_NAME, zPid_Name,
  658. /* disablement strs */ NULL, NULL },
  659. { /* entry idx, value */ 21, VALUE_OPT_VERSION,
  660. /* equiv idx, value */ 21, VALUE_OPT_VERSION,
  661. /* equivalenced to */ NO_EQUIVALENT,
  662. /* min, max, act ct */ 0, 1, 0,
  663. /* opt state flags */ VERSION_FLAGS, 0,
  664. /* last opt argumnt */ { NULL },
  665. /* arg list/cookie */ NULL,
  666. /* must/cannot opts */ NULL, NULL,
  667. /* option proc */ doOptVersion,
  668. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  669. /* disablement strs */ NULL, NULL },
  670. { /* entry idx, value */ 22, VALUE_OPT_LESS_HELP,
  671. /* equiv idx, value */ 22, VALUE_OPT_LESS_HELP,
  672. /* equivalenced to */ NO_EQUIVALENT,
  673. /* min, max, act ct */ 0, 1, 0,
  674. /* opt state flags */ LESS_HELP_FLAGS, 0,
  675. /* last opt argumnt */ { NULL },
  676. /* arg list/cookie */ NULL,
  677. /* must/cannot opts */ NULL, NULL,
  678. /* option proc */ doOptLess_Help,
  679. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  680. /* disablement strs */ NULL, NULL },
  681. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  682. /* equiv idx value */ NO_EQUIVALENT, 0,
  683. /* equivalenced to */ NO_EQUIVALENT,
  684. /* min, max, act ct */ 0, 1, 0,
  685. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  686. /* last opt argumnt */ { NULL },
  687. /* arg list/cookie */ NULL,
  688. /* must/cannot opts */ NULL, NULL,
  689. /* option proc */ doUsageOpt,
  690. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  691. /* disablement strs */ NULL, NULL },
  692. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  693. /* equiv idx value */ NO_EQUIVALENT, 0,
  694. /* equivalenced to */ NO_EQUIVALENT,
  695. /* min, max, act ct */ 0, 1, 0,
  696. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  697. /* last opt argumnt */ { NULL },
  698. /* arg list/cookie */ NULL,
  699. /* must/cannot opts */ NULL, NULL,
  700. /* option proc */ optionPagedUsage,
  701. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  702. /* disablement strs */ NULL, NULL },
  703. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  704. /* equiv idx value */ NO_EQUIVALENT, 0,
  705. /* equivalenced to */ NO_EQUIVALENT,
  706. /* min, max, act ct */ 0, 1, 0,
  707. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  708. | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
  709. /* last opt argumnt */ { NULL },
  710. /* arg list/cookie */ NULL,
  711. /* must/cannot opts */ NULL, NULL,
  712. /* option proc */ NULL,
  713. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  714. /* disablement strs */ NULL, NULL },
  715. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  716. /* equiv idx value */ NO_EQUIVALENT, 0,
  717. /* equivalenced to */ NO_EQUIVALENT,
  718. /* min, max, act ct */ 0, NOLIMIT, 0,
  719. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) \
  720. | OPTST_DISABLE_IMM, 0,
  721. /* last opt argumnt */ { NULL },
  722. /* arg list/cookie */ NULL,
  723. /* must/cannot opts */ NULL, NULL,
  724. /* option proc */ optionLoadOpt,
  725. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  726. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  727. };
  728. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  729. *
  730. * Define the Tcpreplay Option Environment
  731. */
  732. tSCC zPROGNAME[] = "TCPREPLAY";
  733. tSCC zUsageTitle[] =
  734. "tcpreplay (tcpreplay) - Replay network traffic stored in pcap files\n\
  735. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... <pcap_file(s)>\n";
  736. tSCC zRcName[] = ".tcpreplayrc";
  737. tSCC* apzHomeList[] = {
  738. "$$/",
  739. NULL };
  740. #define zBugsAddr NULL
  741. tSCC zExplain[] = "\n\
  742. tcpreplay is a tool for replaying network traffic from files saved with\n\
  743. tcpdump or other tools which write pcap(3) files.\n";
  744. tSCC zDetail[] = "\n\
  745. The basic operation of tcpreplay is to resend all packets from the\n\
  746. input file(s) at the speed at which they were recorded, or a specified \n\
  747. data rate, up to as fast as the hardware is capable.\n\n\
  748. Optionally, the traffic can be split between two interfaces, written to\n\
  749. files, filtered and edited in various ways, providing the means to test\n\
  750. firewalls, NIDS and other network devices.\n\n\
  751. For more details, please see the Tcpreplay Manual at:\n\
  752. http://tcpreplay.synfin.net/trac/wiki/manual\n";
  753. #define zFullVersion NULL
  754. /* extracted from /opt/local/share/autogen/optcode.tpl near line 428 */
  755. #if defined(ENABLE_NLS)
  756. # define OPTPROC_BASE OPTPROC_TRANSLATE
  757. static tOptionXlateProc translate_option_strings;
  758. #else
  759. # define OPTPROC_BASE OPTPROC_NONE
  760. # define translate_option_strings NULL
  761. #endif /* ENABLE_NLS */
  762. #define tcpreplay_full_usage NULL
  763. #define tcpreplay_short_usage NULL
  764. tOptions tcpreplayOptions = {
  765. OPTIONS_STRUCT_VERSION,
  766. 0, NULL, /* original argc + argv */
  767. ( OPTPROC_BASE
  768. + OPTPROC_ERRSTOP
  769. + OPTPROC_SHORTOPT
  770. + OPTPROC_LONGOPT
  771. + OPTPROC_NO_REQ_OPT
  772. + OPTPROC_ARGS_REQ
  773. + OPTPROC_GNUUSAGE
  774. + OPTPROC_HAS_IMMED ),
  775. 0, NULL, /* current option index, current option */
  776. NULL, NULL, zPROGNAME,
  777. zRcName, zCopyright, zCopyrightNotice,
  778. zFullVersion, apzHomeList, zUsageTitle,
  779. zExplain, zDetail, optDesc,
  780. zBugsAddr, /* address to send bugs to */
  781. NULL, NULL, /* extensions/saved state */
  782. optionUsage, /* usage procedure */
  783. translate_option_strings, /* translation procedure */
  784. /*
  785. * Indexes to special options
  786. */
  787. { INDEX_OPT_MORE_HELP,
  788. INDEX_OPT_SAVE_OPTS,
  789. NO_EQUIVALENT /* index of '-#' option */,
  790. NO_EQUIVALENT /* index of default opt */
  791. },
  792. 27 /* full option count */, 23 /* user option count */,
  793. tcpreplay_full_usage, tcpreplay_short_usage
  794. };
  795. /*
  796. * Create the static procedure(s) declared above.
  797. */
  798. static void
  799. doUsageOpt(
  800. tOptions* pOptions,
  801. tOptDesc* pOptDesc )
  802. {
  803. USAGE( EXIT_SUCCESS );
  804. }
  805. /* * * * * * *
  806. *
  807. * For the dbug option, when DEBUG is #define-d.
  808. */
  809. #ifdef DEBUG
  810. static void
  811. doOptDbug(
  812. tOptions* pOptions,
  813. tOptDesc* pOptDesc )
  814. {
  815. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  816. { 0, 5 } };
  817. int val;
  818. int ix;
  819. char const* pzIndent = "\t\t\t\t ";
  820. extern FILE* option_usage_fp;
  821. if (pOptDesc == NULL) /* usage is requesting range list
  822. option_usage_fp has already been set */
  823. goto emit_ranges;
  824. val = atoi( pOptDesc->optArg.argString );
  825. for (ix = 0; ix < 1; ix++) {
  826. if (val < rng[ix].rmin)
  827. continue; /* ranges need not be ordered. */
  828. if (val == rng[ix].rmin)
  829. goto valid_return;
  830. if (rng[ix].rmax == INT_MIN)
  831. continue;
  832. if (val <= rng[ix].rmax)
  833. goto valid_return;
  834. }
  835. option_usage_fp = stderr;
  836. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  837. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  838. pzIndent = "\t";
  839. emit_ranges:
  840. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  841. pzIndent, rng[0].rmin, rng[0].rmax );
  842. if (pOptDesc == NULL)
  843. return;
  844. USAGE( EXIT_FAILURE );
  845. /* NOTREACHED */
  846. return;
  847. valid_return:
  848. pOptDesc->optArg.argInt = val;
  849. }
  850. #endif /* defined DEBUG */
  851. /* * * * * * *
  852. *
  853. * For the listnics option, when ENABLE_PCAP_FINDALLDEVS is #define-d.
  854. */
  855. #ifdef ENABLE_PCAP_FINDALLDEVS
  856. static void
  857. doOptListnics(
  858. tOptions* pOptions,
  859. tOptDesc* pOptDesc )
  860. {
  861. /* extracted from tcpreplay_opts.def, line 256 */
  862. interface_list_t *list = get_interface_list();
  863. list_interfaces(list);
  864. free(list);
  865. exit(0);
  866. }
  867. #endif /* defined ENABLE_PCAP_FINDALLDEVS */
  868. /* * * * * * *
  869. *
  870. * For the loop option.
  871. */
  872. static void
  873. doOptLoop(
  874. tOptions* pOptions,
  875. tOptDesc* pOptDesc )
  876. {
  877. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  878. { 0, INT_MAX } };
  879. int val;
  880. int ix;
  881. char const* pzIndent = "\t\t\t\t ";
  882. extern FILE* option_usage_fp;
  883. if (pOptDesc == NULL) /* usage is requesting range list
  884. option_usage_fp has already been set */
  885. goto emit_ranges;
  886. val = atoi( pOptDesc->optArg.argString );
  887. for (ix = 0; ix < 1; ix++) {
  888. if (val < rng[ix].rmin)
  889. continue; /* ranges need not be ordered. */
  890. if (val == rng[ix].rmin)
  891. goto valid_return;
  892. if (rng[ix].rmax == INT_MIN)
  893. continue;
  894. if (val <= rng[ix].rmax)
  895. goto valid_return;
  896. }
  897. option_usage_fp = stderr;
  898. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  899. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  900. pzIndent = "\t";
  901. emit_ranges:
  902. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  903. pzIndent, rng[0].rmin, rng[0].rmax );
  904. if (pOptDesc == NULL)
  905. return;
  906. USAGE( EXIT_FAILURE );
  907. /* NOTREACHED */
  908. return;
  909. valid_return:
  910. pOptDesc->optArg.argInt = val;
  911. }
  912. /* * * * * * *
  913. *
  914. * For the limit option.
  915. */
  916. static void
  917. doOptLimit(
  918. tOptions* pOptions,
  919. tOptDesc* pOptDesc )
  920. {
  921. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  922. { 1, INT_MAX } };
  923. int val;
  924. int ix;
  925. char const* pzIndent = "\t\t\t\t ";
  926. extern FILE* option_usage_fp;
  927. if (pOptDesc == NULL) /* usage is requesting range list
  928. option_usage_fp has already been set */
  929. goto emit_ranges;
  930. val = atoi( pOptDesc->optArg.argString );
  931. for (ix = 0; ix < 1; ix++) {
  932. if (val < rng[ix].rmin)
  933. continue; /* ranges need not be ordered. */
  934. if (val == rng[ix].rmin)
  935. goto valid_return;
  936. if (rng[ix].rmax == INT_MIN)
  937. continue;
  938. if (val <= rng[ix].rmax)
  939. goto valid_return;
  940. }
  941. option_usage_fp = stderr;
  942. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  943. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  944. pzIndent = "\t";
  945. emit_ranges:
  946. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  947. pzIndent, rng[0].rmin, rng[0].rmax );
  948. if (pOptDesc == NULL)
  949. return;
  950. USAGE( EXIT_FAILURE );
  951. /* NOTREACHED */
  952. return;
  953. valid_return:
  954. pOptDesc->optArg.argInt = val;
  955. }
  956. /* * * * * * *
  957. *
  958. * For the pid option.
  959. */
  960. static void
  961. doOptPid(
  962. tOptions* pOptions,
  963. tOptDesc* pOptDesc )
  964. {
  965. /* extracted from tcpreplay_opts.def, line 391 */
  966. fprintf(stderr, "PID: %hu\n", getpid());
  967. }
  968. /* * * * * * *
  969. *
  970. * For the version option.
  971. */
  972. static void
  973. doOptVersion(
  974. tOptions* pOptions,
  975. tOptDesc* pOptDesc )
  976. {
  977. /* extracted from tcpreplay_opts.def, line 403 */
  978. fprintf(stderr, "tcpreplay version: %s (build %s)", VERSION, svn_version());
  979. #ifdef DEBUG
  980. fprintf(stderr, " (debug)");
  981. #endif
  982. fprintf(stderr, "\n");
  983. fprintf(stderr, "Copyright 2001-2008 by Aaron Turner <aturner at synfin dot net>\n");
  984. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  985. #ifdef HAVE_LIBNET
  986. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  987. #else
  988. fprintf(stderr, "Not compiled with libnet.\n");
  989. #endif
  990. #ifdef HAVE_WINPCAP
  991. fprintf(stderr, "Compiled against winpcap: %s\n", get_pcap_version());
  992. #else
  993. fprintf(stderr, "Compiled against libpcap: %s\n", get_pcap_version());
  994. #endif
  995. #ifdef ENABLE_64BITS
  996. fprintf(stderr, "64 bit packet counters: enabled\n");
  997. #else
  998. fprintf(stderr, "64 bit packet counters: disabled\n");
  999. #endif
  1000. #ifdef ENABLE_VERBOSE
  1001. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  1002. #else
  1003. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  1004. #endif
  1005. #ifdef TCPREPLAY_EDIT
  1006. fprintf(stderr, "Packet editing: enabled\n");
  1007. #else
  1008. fprintf(stderr, "Packet editing: disabled\n");
  1009. #endif
  1010. #ifdef ENABLE_FRAGROUTE
  1011. fprintf(stderr, "Fragroute engine: enabled\n");
  1012. #else
  1013. fprintf(stderr, "Fragroute engine: disabled\n");
  1014. #endif
  1015. exit(0);
  1016. }
  1017. /* * * * * * *
  1018. *
  1019. * For the less-help option.
  1020. */
  1021. static void
  1022. doOptLess_Help(
  1023. tOptions* pOptions,
  1024. tOptDesc* pOptDesc )
  1025. {
  1026. /* extracted from tcpreplay_opts.def, line 453 */
  1027. USAGE(EXIT_FAILURE);
  1028. }
  1029. /* extracted from /opt/local/share/autogen/optcode.tpl near line 537 */
  1030. #if ENABLE_NLS
  1031. #include <stdio.h>
  1032. #include <stdlib.h>
  1033. #include <string.h>
  1034. #include <unistd.h>
  1035. #include <autoopts/usage-txt.h>
  1036. static char* AO_gettext( char const* pz );
  1037. static void coerce_it(void** s);
  1038. static char*
  1039. AO_gettext( char const* pz )
  1040. {
  1041. char* pzRes;
  1042. if (pz == NULL)
  1043. return NULL;
  1044. pzRes = _(pz);
  1045. if (pzRes == pz)
  1046. return pzRes;
  1047. pzRes = strdup( pzRes );
  1048. if (pzRes == NULL) {
  1049. fputs( _("No memory for duping translated strings\n"), stderr );
  1050. exit( EXIT_FAILURE );
  1051. }
  1052. return pzRes;
  1053. }
  1054. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  1055. #define COERSION(_f) \
  1056. coerce_it((void*)&(tcpreplayOptions._f))
  1057. /*
  1058. * This invokes the translation code (e.g. gettext(3)).
  1059. */
  1060. static void
  1061. translate_option_strings( void )
  1062. {
  1063. /*
  1064. * Guard against re-translation. It won't work. The strings will have
  1065. * been changed by the first pass through this code. One shot only.
  1066. */
  1067. if (option_usage_text.field_ct == 0)
  1068. return;
  1069. /*
  1070. * Do the translations. The first pointer follows the field count field.
  1071. * The field count field is the size of a pointer.
  1072. */
  1073. {
  1074. char** ppz = (char**)(void*)&(option_usage_text);
  1075. int ix = option_usage_text.field_ct;
  1076. do {
  1077. ppz++;
  1078. *ppz = AO_gettext(*ppz);
  1079. } while (--ix > 0);
  1080. }
  1081. option_usage_text.field_ct = 0;
  1082. {
  1083. tOptDesc* pOD = tcpreplayOptions.pOptDesc;
  1084. int ix = tcpreplayOptions.optCt;
  1085. for (;;) {
  1086. pOD->pzText = AO_gettext(pOD->pzText);
  1087. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  1088. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  1089. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  1090. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  1091. if (--ix <= 0)
  1092. break;
  1093. pOD++;
  1094. }
  1095. }
  1096. COERSION(pzCopyright);
  1097. COERSION(pzCopyNotice);
  1098. COERSION(pzFullVersion);
  1099. COERSION(pzUsageTitle);
  1100. COERSION(pzExplain);
  1101. COERSION(pzDetail);
  1102. }
  1103. #endif /* ENABLE_NLS */
  1104. #ifdef __cplusplus
  1105. }
  1106. #endif
  1107. /* tcpreplay_opts.c ends here */