tcpreplay_opts.c 39 KB

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