tcpreplay_opts.c 37 KB

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