tcprewrite_opts.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (tcprewrite_opts.c)
  4. *
  5. * It has been AutoGen-ed Thursday July 28, 2005 at 09:57:17 PM PDT
  6. * From the definitions tcprewrite_opts.def
  7. * and the template file options
  8. */
  9. #include <stdio.h>
  10. #include <limits.h>
  11. #define OPTION_CODE_COMPILE 1
  12. #include "tcprewrite_opts.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. tSCC zCopyright[] =
  17. "tcprewrite copyright (c) 2004-2005 Aaron Turner, all rights reserved";
  18. tSCC zCopyrightNotice[] =
  19. "tcprewrite is free software copyrighted by Aaron Turner.\n\n\
  20. Redistribution and use in source and binary forms, with or without\n\
  21. modification, are permitted provided that the following conditions\n\
  22. are met:\n\
  23. 1. Redistributions of source code must retain the above copyright\n\
  24. notice, this list of conditions and the following disclaimer.\n\
  25. 2. Redistributions in binary form must reproduce the above copyright\n\
  26. notice, this list of conditions and the following disclaimer in the\n\
  27. documentation and/or other materials provided with the distribution.\n\
  28. 3. Neither the name ``Aaron Turner'' nor the name of any other\n\
  29. contributor may be used to endorse or promote products derived\n\
  30. from this software without specific prior written permission.\n\n\
  31. tcprewrite IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS\n\
  32. OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n\
  33. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\
  34. ARE DISCLAIMED. IN NO EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS\n\
  35. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n\
  36. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n\
  37. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n\
  38. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n\
  39. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n\
  40. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n\
  41. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
  42. extern tUsageProc optionUsage;
  43. /*
  44. * global included definitions
  45. */
  46. #include "defines.h"
  47. #include "common.h"
  48. #include "tcprewrite.h"
  49. #include "mac.h"
  50. extern char pcap_version[];
  51. extern tcprewrite_opt_t options;
  52. #ifndef NULL
  53. # define NULL 0
  54. #endif
  55. #ifndef EXIT_SUCCESS
  56. # define EXIT_SUCCESS 0
  57. #endif
  58. #ifndef EXIT_FAILURE
  59. # define EXIT_FAILURE 1
  60. #endif
  61. /*
  62. * Dbug option description:
  63. */
  64. tSCC zDbugText[] =
  65. "Enable debugging output";
  66. tSCC zDbug_NAME[] = "DBUG";
  67. tSCC zDbug_Name[] = "dbug";
  68. #define zDbugDefaultArg ((tCC*)0)
  69. #define DBUG_FLAGS (OPTST_DISABLED \
  70. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  71. /*
  72. * Dmac option description:
  73. */
  74. tSCC zDmacText[] =
  75. "Rewrite destination MAC addresses";
  76. tSCC zDmac_NAME[] = "DMAC";
  77. tSCC zDmac_Name[] = "dmac";
  78. #define DMAC_FLAGS (OPTST_DISABLED \
  79. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  80. /*
  81. * Smac option description:
  82. */
  83. tSCC zSmacText[] =
  84. "Rewrite source MAC addresses";
  85. tSCC zSmac_NAME[] = "SMAC";
  86. tSCC zSmac_Name[] = "smac";
  87. #define SMAC_FLAGS (OPTST_DISABLED \
  88. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  89. /*
  90. * Proto option description:
  91. */
  92. tSCC zProtoText[] =
  93. "Override L2 protocol type for DLT_RAW";
  94. tSCC zProto_NAME[] = "PROTO";
  95. tSCC zProto_Name[] = "proto";
  96. #define PROTO_FLAGS (OPTST_DISABLED \
  97. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  98. /*
  99. * Dlink option description:
  100. */
  101. tSCC zDlinkText[] =
  102. "Rewrite Data-Link layer with specified data";
  103. tSCC zDlink_NAME[] = "DLINK";
  104. tSCC zDlink_Name[] = "dlink";
  105. #define DLINK_FLAGS (OPTST_DISABLED \
  106. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  107. /*
  108. * Portmap option description:
  109. */
  110. tSCC zPortmapText[] =
  111. "Rewrite TCP/UDP ports";
  112. tSCC zPortmap_NAME[] = "PORTMAP";
  113. tSCC zPortmap_Name[] = "portmap";
  114. #define PORTMAP_FLAGS (OPTST_DISABLED \
  115. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  116. /*
  117. * Seed option description:
  118. */
  119. tSCC zSeedText[] =
  120. "Randomize src/dst IP addresses w/ given seed";
  121. tSCC zSeed_NAME[] = "SEED";
  122. tSCC zSeed_Name[] = "seed";
  123. #define SEED_FLAGS (OPTST_DISABLED \
  124. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  125. /*
  126. * Pnat option description:
  127. */
  128. tSCC zPnatText[] =
  129. "Rewrite IP addresses using pseudo-NAT";
  130. tSCC zPnat_NAME[] = "PNAT";
  131. tSCC zPnat_Name[] = "pnat";
  132. #define PNAT_FLAGS (OPTST_DISABLED \
  133. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  134. /*
  135. * Endpoints option description:
  136. */
  137. tSCC zEndpointsText[] =
  138. "Rewrite IP addresses to be between two endpoints";
  139. tSCC zEndpoints_NAME[] = "ENDPOINTS";
  140. tSCC zEndpoints_Name[] = "endpoints";
  141. #define ENDPOINTS_FLAGS (OPTST_DISABLED \
  142. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  143. /*
  144. * Fixcsum option description:
  145. */
  146. tSCC zFixcsumText[] =
  147. "Force recalculation of IP/TCP/UDP checksums";
  148. tSCC zFixcsum_NAME[] = "FIXCSUM";
  149. tSCC zFixcsum_Name[] = "fixcsum";
  150. #define FIXCSUM_FLAGS (OPTST_DISABLED)
  151. /*
  152. * Infile option description:
  153. */
  154. tSCC zInfileText[] =
  155. "Input pcap file to be processed";
  156. tSCC zInfile_NAME[] = "INFILE";
  157. tSCC zInfile_Name[] = "infile";
  158. #define INFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  159. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  160. /*
  161. * Outfile option description:
  162. */
  163. tSCC zOutfileText[] =
  164. "Output pcap file";
  165. tSCC zOutfile_NAME[] = "OUTFILE";
  166. tSCC zOutfile_Name[] = "outfile";
  167. #define OUTFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  168. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  169. /*
  170. * Cachefile option description:
  171. */
  172. tSCC zCachefileText[] =
  173. "Split traffic via tcpprep cache file";
  174. tSCC zCachefile_NAME[] = "CACHEFILE";
  175. tSCC zCachefile_Name[] = "cachefile";
  176. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  177. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  178. /*
  179. * Mtu option description:
  180. */
  181. tSCC zMtuText[] =
  182. "Override default MTU length (1500 bytes)";
  183. tSCC zMtu_NAME[] = "MTU";
  184. tSCC zMtu_Name[] = "mtu";
  185. #define MTU_FLAGS (OPTST_DISABLED \
  186. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  187. /*
  188. * Efcs option description:
  189. */
  190. tSCC zEfcsText[] =
  191. "Remove Ethernet checksums (FCS) from end of frames";
  192. tSCC zEfcs_NAME[] = "EFCS";
  193. tSCC zEfcs_Name[] = "efcs";
  194. #define EFCS_FLAGS (OPTST_DISABLED)
  195. /*
  196. * Fixlen option description:
  197. */
  198. tSCC zFixlenText[] =
  199. "Pad or truncate packet data to match header length";
  200. tSCC zFixlen_NAME[] = "FIXLEN";
  201. tSCC zFixlen_Name[] = "fixlen";
  202. #define FIXLEN_FLAGS (OPTST_DISABLED \
  203. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  204. /*
  205. * Vlan option description:
  206. */
  207. tSCC zVlanText[] =
  208. "Specify 802.1q VLAN tag mode";
  209. tSCC zVlan_NAME[] = "VLAN";
  210. tSCC zVlan_Name[] = "vlan";
  211. #define VLAN_FLAGS (OPTST_DISABLED \
  212. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  213. /*
  214. * Vlan_Tag option description with
  215. * "Must also have options" and "Incompatible options":
  216. */
  217. tSCC zVlan_TagText[] =
  218. "Specify the new 802.1q VLAN tag value";
  219. tSCC zVlan_Tag_NAME[] = "VLAN_TAG";
  220. tSCC zVlan_Tag_Name[] = "vlan-tag";
  221. static const int
  222. aVlan_TagMustList[] = {
  223. INDEX_OPT_VLAN, NO_EQUIVALENT };
  224. #define VLAN_TAG_FLAGS (OPTST_DISABLED \
  225. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  226. /*
  227. * Vlan_Cfi option description with
  228. * "Must also have options" and "Incompatible options":
  229. */
  230. tSCC zVlan_CfiText[] =
  231. "Specify the 802.1q VLAN CFI value";
  232. tSCC zVlan_Cfi_NAME[] = "VLAN_CFI";
  233. tSCC zVlan_Cfi_Name[] = "vlan-cfi";
  234. static const int
  235. aVlan_CfiMustList[] = {
  236. INDEX_OPT_VLAN, NO_EQUIVALENT };
  237. #define VLAN_CFI_FLAGS (OPTST_DISABLED \
  238. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  239. /*
  240. * Vlan_Pri option description with
  241. * "Must also have options" and "Incompatible options":
  242. */
  243. tSCC zVlan_PriText[] =
  244. "Specify the 802.1q VLAN priority";
  245. tSCC zVlan_Pri_NAME[] = "VLAN_PRI";
  246. tSCC zVlan_Pri_Name[] = "vlan-pri";
  247. static const int
  248. aVlan_PriMustList[] = {
  249. INDEX_OPT_VLAN, NO_EQUIVALENT };
  250. #define VLAN_PRI_FLAGS (OPTST_DISABLED \
  251. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  252. /*
  253. * Verbose option description:
  254. */
  255. #ifdef HAVE_TCPDUMP
  256. tSCC zVerboseText[] =
  257. "Print decoded packets via tcpdump to STDOUT";
  258. tSCC zVerbose_NAME[] = "VERBOSE";
  259. tSCC zVerbose_Name[] = "verbose";
  260. #define VERBOSE_FLAGS (OPTST_DISABLED)
  261. #else /* disable Verbose */
  262. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  263. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  264. #define zVerboseText NULL
  265. #define zVerbose_NAME NULL
  266. #define zVerbose_Name NULL
  267. #endif /* HAVE_TCPDUMP */
  268. /*
  269. * Decode option description with
  270. * "Must also have options" and "Incompatible options":
  271. */
  272. #ifdef HAVE_TCPDUMP
  273. tSCC zDecodeText[] =
  274. "Arguments passed to tcpdump decoder";
  275. tSCC zDecode_NAME[] = "DECODE";
  276. tSCC zDecode_Name[] = "decode";
  277. static const int
  278. aDecodeMustList[] = {
  279. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  280. #define DECODE_FLAGS (OPTST_DISABLED \
  281. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  282. #else /* disable Decode */
  283. #define VALUE_OPT_DECODE NO_EQUIVALENT
  284. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  285. #define aDecodeMustList NULL
  286. #define zDecodeText NULL
  287. #define zDecode_NAME NULL
  288. #define zDecode_Name NULL
  289. #endif /* HAVE_TCPDUMP */
  290. /*
  291. * Version option description:
  292. */
  293. tSCC zVersionText[] =
  294. "Print version information";
  295. tSCC zVersion_NAME[] = "VERSION";
  296. tSCC zVersion_Name[] = "version";
  297. #define VERSION_FLAGS (OPTST_DISABLED)
  298. /*
  299. * Less_Help option description:
  300. */
  301. tSCC zLess_HelpText[] =
  302. "Display less usage information and exit";
  303. tSCC zLess_Help_NAME[] = "LESS_HELP";
  304. tSCC zLess_Help_Name[] = "less-help";
  305. #define LESS_HELP_FLAGS (OPTST_DISABLED)
  306. /*
  307. * Help/More_Help option descriptions:
  308. */
  309. tSCC zHelpText[] = "Display usage information and exit";
  310. tSCC zHelp_Name[] = "help";
  311. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  312. tSCC zMore_Help_Name[] = "more-help";
  313. /*
  314. * Save/Load_Opts option description:
  315. */
  316. tSCC zSave_OptsText[] = "Save the option state to a config file";
  317. tSCC zSave_Opts_Name[] = "save-opts";
  318. tSCC zLoad_OptsText[] = "Load options from a config file";
  319. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  320. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  321. tSCC zNotLoad_Opts_Pfx[] = "no";
  322. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  323. /*
  324. * Declare option callback procedures
  325. */
  326. extern tOptProc
  327. optionNumericVal, optionPagedUsage;
  328. static tOptProc
  329. doOptCachefile, doOptDbug, doOptDlink, doOptDmac,
  330. doOptEfcs, doOptFixcsum, doOptFixlen, doOptInfile,
  331. doOptLess_Help, doOptMtu, doOptPnat, doOptPortmap,
  332. doOptProto, doOptSmac, doOptVersion, doOptVlan,
  333. doOptVlan_Cfi, doOptVlan_Pri, doOptVlan_Tag, doUsageOpt;
  334. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  335. *
  336. * Define the Tcprewrite Option Descriptions.
  337. */
  338. static tOptDesc optDesc[ OPTION_CT ] = {
  339. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  340. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  341. /* equivalenced to */ NO_EQUIVALENT,
  342. /* min, max, act ct */ 0, 1, 0,
  343. /* opt state flags */ DBUG_FLAGS, 0,
  344. /* last opt argumnt */ zDbugDefaultArg,
  345. /* arg list/cookie */ NULL,
  346. /* must/cannot opts */ NULL, NULL,
  347. /* option proc */ doOptDbug,
  348. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  349. /* disablement strs */ NULL, NULL },
  350. { /* entry idx, value */ 1, VALUE_OPT_DMAC,
  351. /* equiv idx, value */ 1, VALUE_OPT_DMAC,
  352. /* equivalenced to */ NO_EQUIVALENT,
  353. /* min, max, act ct */ 0, 1, 0,
  354. /* opt state flags */ DMAC_FLAGS, 0,
  355. /* last opt argumnt */ NULL,
  356. /* arg list/cookie */ NULL,
  357. /* must/cannot opts */ NULL, NULL,
  358. /* option proc */ doOptDmac,
  359. /* desc, NAME, name */ zDmacText, zDmac_NAME, zDmac_Name,
  360. /* disablement strs */ NULL, NULL },
  361. { /* entry idx, value */ 2, VALUE_OPT_SMAC,
  362. /* equiv idx, value */ 2, VALUE_OPT_SMAC,
  363. /* equivalenced to */ NO_EQUIVALENT,
  364. /* min, max, act ct */ 0, 1, 0,
  365. /* opt state flags */ SMAC_FLAGS, 0,
  366. /* last opt argumnt */ NULL,
  367. /* arg list/cookie */ NULL,
  368. /* must/cannot opts */ NULL, NULL,
  369. /* option proc */ doOptSmac,
  370. /* desc, NAME, name */ zSmacText, zSmac_NAME, zSmac_Name,
  371. /* disablement strs */ NULL, NULL },
  372. { /* entry idx, value */ 3, VALUE_OPT_PROTO,
  373. /* equiv idx, value */ 3, VALUE_OPT_PROTO,
  374. /* equivalenced to */ NO_EQUIVALENT,
  375. /* min, max, act ct */ 0, 1, 0,
  376. /* opt state flags */ PROTO_FLAGS, 0,
  377. /* last opt argumnt */ NULL,
  378. /* arg list/cookie */ NULL,
  379. /* must/cannot opts */ NULL, NULL,
  380. /* option proc */ doOptProto,
  381. /* desc, NAME, name */ zProtoText, zProto_NAME, zProto_Name,
  382. /* disablement strs */ NULL, NULL },
  383. { /* entry idx, value */ 4, VALUE_OPT_DLINK,
  384. /* equiv idx, value */ 4, VALUE_OPT_DLINK,
  385. /* equivalenced to */ NO_EQUIVALENT,
  386. /* min, max, act ct */ 0, 2, 0,
  387. /* opt state flags */ DLINK_FLAGS, 0,
  388. /* last opt argumnt */ NULL,
  389. /* arg list/cookie */ NULL,
  390. /* must/cannot opts */ NULL, NULL,
  391. /* option proc */ doOptDlink,
  392. /* desc, NAME, name */ zDlinkText, zDlink_NAME, zDlink_Name,
  393. /* disablement strs */ NULL, NULL },
  394. { /* entry idx, value */ 5, VALUE_OPT_PORTMAP,
  395. /* equiv idx, value */ 5, VALUE_OPT_PORTMAP,
  396. /* equivalenced to */ NO_EQUIVALENT,
  397. /* min, max, act ct */ 0, 1, 0,
  398. /* opt state flags */ PORTMAP_FLAGS, 0,
  399. /* last opt argumnt */ NULL,
  400. /* arg list/cookie */ NULL,
  401. /* must/cannot opts */ NULL, NULL,
  402. /* option proc */ doOptPortmap,
  403. /* desc, NAME, name */ zPortmapText, zPortmap_NAME, zPortmap_Name,
  404. /* disablement strs */ NULL, NULL },
  405. { /* entry idx, value */ 6, VALUE_OPT_SEED,
  406. /* equiv idx, value */ 6, VALUE_OPT_SEED,
  407. /* equivalenced to */ NO_EQUIVALENT,
  408. /* min, max, act ct */ 0, 1, 0,
  409. /* opt state flags */ SEED_FLAGS, 0,
  410. /* last opt argumnt */ NULL,
  411. /* arg list/cookie */ NULL,
  412. /* must/cannot opts */ NULL, NULL,
  413. /* option proc */ optionNumericVal,
  414. /* desc, NAME, name */ zSeedText, zSeed_NAME, zSeed_Name,
  415. /* disablement strs */ NULL, NULL },
  416. { /* entry idx, value */ 7, VALUE_OPT_PNAT,
  417. /* equiv idx, value */ 7, VALUE_OPT_PNAT,
  418. /* equivalenced to */ NO_EQUIVALENT,
  419. /* min, max, act ct */ 0, 2, 0,
  420. /* opt state flags */ PNAT_FLAGS, 0,
  421. /* last opt argumnt */ NULL,
  422. /* arg list/cookie */ NULL,
  423. /* must/cannot opts */ NULL, NULL,
  424. /* option proc */ doOptPnat,
  425. /* desc, NAME, name */ zPnatText, zPnat_NAME, zPnat_Name,
  426. /* disablement strs */ NULL, NULL },
  427. { /* entry idx, value */ 8, VALUE_OPT_ENDPOINTS,
  428. /* equiv idx, value */ 8, VALUE_OPT_ENDPOINTS,
  429. /* equivalenced to */ NO_EQUIVALENT,
  430. /* min, max, act ct */ 0, 1, 0,
  431. /* opt state flags */ ENDPOINTS_FLAGS, 0,
  432. /* last opt argumnt */ NULL,
  433. /* arg list/cookie */ NULL,
  434. /* must/cannot opts */ NULL, NULL,
  435. /* option proc */ NULL,
  436. /* desc, NAME, name */ zEndpointsText, zEndpoints_NAME, zEndpoints_Name,
  437. /* disablement strs */ NULL, NULL },
  438. { /* entry idx, value */ 9, VALUE_OPT_FIXCSUM,
  439. /* equiv idx, value */ 9, VALUE_OPT_FIXCSUM,
  440. /* equivalenced to */ NO_EQUIVALENT,
  441. /* min, max, act ct */ 0, 1, 0,
  442. /* opt state flags */ FIXCSUM_FLAGS, 0,
  443. /* last opt argumnt */ NULL,
  444. /* arg list/cookie */ NULL,
  445. /* must/cannot opts */ NULL, NULL,
  446. /* option proc */ doOptFixcsum,
  447. /* desc, NAME, name */ zFixcsumText, zFixcsum_NAME, zFixcsum_Name,
  448. /* disablement strs */ NULL, NULL },
  449. { /* entry idx, value */ 10, VALUE_OPT_INFILE,
  450. /* equiv idx, value */ 10, VALUE_OPT_INFILE,
  451. /* equivalenced to */ NO_EQUIVALENT,
  452. /* min, max, act ct */ 1, 1, 0,
  453. /* opt state flags */ INFILE_FLAGS, 0,
  454. /* last opt argumnt */ NULL,
  455. /* arg list/cookie */ NULL,
  456. /* must/cannot opts */ NULL, NULL,
  457. /* option proc */ doOptInfile,
  458. /* desc, NAME, name */ zInfileText, zInfile_NAME, zInfile_Name,
  459. /* disablement strs */ NULL, NULL },
  460. { /* entry idx, value */ 11, VALUE_OPT_OUTFILE,
  461. /* equiv idx, value */ 11, VALUE_OPT_OUTFILE,
  462. /* equivalenced to */ NO_EQUIVALENT,
  463. /* min, max, act ct */ 1, 1, 0,
  464. /* opt state flags */ OUTFILE_FLAGS, 0,
  465. /* last opt argumnt */ NULL,
  466. /* arg list/cookie */ NULL,
  467. /* must/cannot opts */ NULL, NULL,
  468. /* option proc */ NULL,
  469. /* desc, NAME, name */ zOutfileText, zOutfile_NAME, zOutfile_Name,
  470. /* disablement strs */ NULL, NULL },
  471. { /* entry idx, value */ 12, VALUE_OPT_CACHEFILE,
  472. /* equiv idx, value */ 12, VALUE_OPT_CACHEFILE,
  473. /* equivalenced to */ NO_EQUIVALENT,
  474. /* min, max, act ct */ 0, 1, 0,
  475. /* opt state flags */ CACHEFILE_FLAGS, 0,
  476. /* last opt argumnt */ NULL,
  477. /* arg list/cookie */ NULL,
  478. /* must/cannot opts */ NULL, NULL,
  479. /* option proc */ doOptCachefile,
  480. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  481. /* disablement strs */ NULL, NULL },
  482. { /* entry idx, value */ 13, VALUE_OPT_MTU,
  483. /* equiv idx, value */ 13, VALUE_OPT_MTU,
  484. /* equivalenced to */ NO_EQUIVALENT,
  485. /* min, max, act ct */ 0, 1, 0,
  486. /* opt state flags */ MTU_FLAGS, 0,
  487. /* last opt argumnt */ NULL,
  488. /* arg list/cookie */ NULL,
  489. /* must/cannot opts */ NULL, NULL,
  490. /* option proc */ doOptMtu,
  491. /* desc, NAME, name */ zMtuText, zMtu_NAME, zMtu_Name,
  492. /* disablement strs */ NULL, NULL },
  493. { /* entry idx, value */ 14, VALUE_OPT_EFCS,
  494. /* equiv idx, value */ 14, VALUE_OPT_EFCS,
  495. /* equivalenced to */ NO_EQUIVALENT,
  496. /* min, max, act ct */ 0, 1, 0,
  497. /* opt state flags */ EFCS_FLAGS, 0,
  498. /* last opt argumnt */ NULL,
  499. /* arg list/cookie */ NULL,
  500. /* must/cannot opts */ NULL, NULL,
  501. /* option proc */ doOptEfcs,
  502. /* desc, NAME, name */ zEfcsText, zEfcs_NAME, zEfcs_Name,
  503. /* disablement strs */ NULL, NULL },
  504. { /* entry idx, value */ 15, VALUE_OPT_FIXLEN,
  505. /* equiv idx, value */ 15, VALUE_OPT_FIXLEN,
  506. /* equivalenced to */ NO_EQUIVALENT,
  507. /* min, max, act ct */ 0, 1, 0,
  508. /* opt state flags */ FIXLEN_FLAGS, 0,
  509. /* last opt argumnt */ NULL,
  510. /* arg list/cookie */ NULL,
  511. /* must/cannot opts */ NULL, NULL,
  512. /* option proc */ doOptFixlen,
  513. /* desc, NAME, name */ zFixlenText, zFixlen_NAME, zFixlen_Name,
  514. /* disablement strs */ NULL, NULL },
  515. { /* entry idx, value */ 16, VALUE_OPT_VLAN,
  516. /* equiv idx, value */ 16, VALUE_OPT_VLAN,
  517. /* equivalenced to */ NO_EQUIVALENT,
  518. /* min, max, act ct */ 0, 1, 0,
  519. /* opt state flags */ VLAN_FLAGS, 0,
  520. /* last opt argumnt */ NULL,
  521. /* arg list/cookie */ NULL,
  522. /* must/cannot opts */ NULL, NULL,
  523. /* option proc */ doOptVlan,
  524. /* desc, NAME, name */ zVlanText, zVlan_NAME, zVlan_Name,
  525. /* disablement strs */ NULL, NULL },
  526. { /* entry idx, value */ 17, VALUE_OPT_VLAN_TAG,
  527. /* equiv idx, value */ 17, VALUE_OPT_VLAN_TAG,
  528. /* equivalenced to */ NO_EQUIVALENT,
  529. /* min, max, act ct */ 0, 1, 0,
  530. /* opt state flags */ VLAN_TAG_FLAGS, 0,
  531. /* last opt argumnt */ NULL,
  532. /* arg list/cookie */ NULL,
  533. /* must/cannot opts */ aVlan_TagMustList, NULL,
  534. /* option proc */ doOptVlan_Tag,
  535. /* desc, NAME, name */ zVlan_TagText, zVlan_Tag_NAME, zVlan_Tag_Name,
  536. /* disablement strs */ NULL, NULL },
  537. { /* entry idx, value */ 18, VALUE_OPT_VLAN_CFI,
  538. /* equiv idx, value */ 18, VALUE_OPT_VLAN_CFI,
  539. /* equivalenced to */ NO_EQUIVALENT,
  540. /* min, max, act ct */ 0, 1, 0,
  541. /* opt state flags */ VLAN_CFI_FLAGS, 0,
  542. /* last opt argumnt */ NULL,
  543. /* arg list/cookie */ NULL,
  544. /* must/cannot opts */ aVlan_CfiMustList, NULL,
  545. /* option proc */ doOptVlan_Cfi,
  546. /* desc, NAME, name */ zVlan_CfiText, zVlan_Cfi_NAME, zVlan_Cfi_Name,
  547. /* disablement strs */ NULL, NULL },
  548. { /* entry idx, value */ 19, VALUE_OPT_VLAN_PRI,
  549. /* equiv idx, value */ 19, VALUE_OPT_VLAN_PRI,
  550. /* equivalenced to */ NO_EQUIVALENT,
  551. /* min, max, act ct */ 0, 1, 0,
  552. /* opt state flags */ VLAN_PRI_FLAGS, 0,
  553. /* last opt argumnt */ NULL,
  554. /* arg list/cookie */ NULL,
  555. /* must/cannot opts */ aVlan_PriMustList, NULL,
  556. /* option proc */ doOptVlan_Pri,
  557. /* desc, NAME, name */ zVlan_PriText, zVlan_Pri_NAME, zVlan_Pri_Name,
  558. /* disablement strs */ NULL, NULL },
  559. { /* entry idx, value */ 20, VALUE_OPT_VERBOSE,
  560. /* equiv idx, value */ 20, VALUE_OPT_VERBOSE,
  561. /* equivalenced to */ NO_EQUIVALENT,
  562. /* min, max, act ct */ 0, 1, 0,
  563. /* opt state flags */ VERBOSE_FLAGS, 0,
  564. /* last opt argumnt */ NULL,
  565. /* arg list/cookie */ NULL,
  566. /* must/cannot opts */ NULL, NULL,
  567. /* option proc */ NULL,
  568. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  569. /* disablement strs */ NULL, NULL },
  570. { /* entry idx, value */ 21, VALUE_OPT_DECODE,
  571. /* equiv idx, value */ 21, VALUE_OPT_DECODE,
  572. /* equivalenced to */ NO_EQUIVALENT,
  573. /* min, max, act ct */ 0, 1, 0,
  574. /* opt state flags */ DECODE_FLAGS, 0,
  575. /* last opt argumnt */ NULL,
  576. /* arg list/cookie */ NULL,
  577. /* must/cannot opts */ aDecodeMustList, NULL,
  578. /* option proc */ NULL,
  579. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  580. /* disablement strs */ NULL, NULL },
  581. { /* entry idx, value */ 22, VALUE_OPT_VERSION,
  582. /* equiv idx, value */ 22, VALUE_OPT_VERSION,
  583. /* equivalenced to */ NO_EQUIVALENT,
  584. /* min, max, act ct */ 0, 1, 0,
  585. /* opt state flags */ VERSION_FLAGS, 0,
  586. /* last opt argumnt */ NULL,
  587. /* arg list/cookie */ NULL,
  588. /* must/cannot opts */ NULL, NULL,
  589. /* option proc */ doOptVersion,
  590. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  591. /* disablement strs */ NULL, NULL },
  592. { /* entry idx, value */ 23, VALUE_OPT_LESS_HELP,
  593. /* equiv idx, value */ 23, VALUE_OPT_LESS_HELP,
  594. /* equivalenced to */ NO_EQUIVALENT,
  595. /* min, max, act ct */ 0, 1, 0,
  596. /* opt state flags */ LESS_HELP_FLAGS, 0,
  597. /* last opt argumnt */ NULL,
  598. /* arg list/cookie */ NULL,
  599. /* must/cannot opts */ NULL, NULL,
  600. /* option proc */ doOptLess_Help,
  601. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  602. /* disablement strs */ NULL, NULL },
  603. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  604. /* equiv idx value */ NO_EQUIVALENT, 0,
  605. /* equivalenced to */ NO_EQUIVALENT,
  606. /* min, max, act ct */ 0, 1, 0,
  607. /* opt state flags */ OPTST_IMM, 0,
  608. /* last opt argumnt */ NULL,
  609. /* arg list/cookie */ NULL,
  610. /* must/cannot opts */ NULL, NULL,
  611. /* option proc */ doUsageOpt,
  612. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  613. /* disablement strs */ NULL, NULL },
  614. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  615. /* equiv idx value */ NO_EQUIVALENT, 0,
  616. /* equivalenced to */ NO_EQUIVALENT,
  617. /* min, max, act ct */ 0, 1, 0,
  618. /* opt state flags */ OPTST_IMM, 0,
  619. /* last opt argumnt */ NULL,
  620. /* arg list/cookie */ NULL,
  621. /* must/cannot opts */ NULL, NULL,
  622. /* option proc */ optionPagedUsage,
  623. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  624. /* disablement strs */ NULL, NULL },
  625. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  626. /* equiv idx value */ NO_EQUIVALENT, 0,
  627. /* equivalenced to */ NO_EQUIVALENT,
  628. /* min, max, act ct */ 0, 1, 0,
  629. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  630. | OPTST_ARG_OPTIONAL, 0,
  631. /* last opt argumnt */ NULL,
  632. /* arg list/cookie */ NULL,
  633. /* must/cannot opts */ NULL, NULL,
  634. /* option proc */ NULL,
  635. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  636. /* disablement strs */ NULL, NULL },
  637. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  638. /* equiv idx value */ NO_EQUIVALENT, 0,
  639. /* equivalenced to */ NO_EQUIVALENT,
  640. /* min, max, act ct */ 0, NOLIMIT, 0,
  641. /* opt state flags */ OPTST_DISABLE_IMM | \
  642. OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
  643. /* last opt argumnt */ NULL,
  644. /* arg list/cookie */ NULL,
  645. /* must/cannot opts */ NULL, NULL,
  646. /* option proc */ optionLoadOpt,
  647. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  648. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  649. };
  650. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  651. *
  652. * Define the Tcprewrite Option Environment
  653. */
  654. tSCC zPROGNAME[] = "TCPREWRITE";
  655. tSCC zUsageTitle[] =
  656. "tcprewrite - Rewrite the packets in a pcap file.\n\
  657. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  658. tSCC zRcName[] = ".tcprewriterc";
  659. tSCC* apzHomeList[] = {
  660. "$$/",
  661. NULL };
  662. #define zBugsAddr NULL
  663. #define zExplain NULL
  664. tSCC zDetail[] = "\n\
  665. Tcprewrite is a tool to rewrite packets stored in ``pcap(3)'' file format, such\n\
  666. as crated by tools such as ``tcpdump(1)'' and ``ethereal(1)''. Once a pcap \n\
  667. file has had it's packets rewritten, they can be replayed back out on the network\n\
  668. using ``tcpreplay(1)''.\n\n\
  669. tcprewrite currently supports the following DLT types:\n\
  670. * DLT_C_HDLC\n\
  671. * DLT_EN10MB\n\
  672. * DLT_LINUX_SSL\n\
  673. * DLT_RAW\n\n\
  674. The packet editing features of tcprewrite which distinguish between \"client\"\n\
  675. and \"server\" traffic requires a tcpprep(1) cache file.\n";
  676. #define zFullVersion NULL
  677. /* extracted from /usr/local/share/autogen/optcode.tpl near line 309 */
  678. #if defined(ENABLE_NLS)
  679. # define OPTPROC_BASE OPTPROC_TRANSLATE
  680. static tOptionXlateProc translate_option_strings;
  681. #else
  682. # define OPTPROC_BASE OPTPROC_NONE
  683. # define translate_option_strings NULL
  684. #endif /* ENABLE_NLS */
  685. tOptions tcprewriteOptions = {
  686. OPTIONS_STRUCT_VERSION,
  687. 0, NULL, /* original argc + argv */
  688. ( OPTPROC_BASE
  689. + OPTPROC_ERRSTOP
  690. + OPTPROC_SHORTOPT
  691. + OPTPROC_LONGOPT
  692. + OPTPROC_NO_REQ_OPT
  693. + OPTPROC_NO_ARGS
  694. + OPTPROC_GNUUSAGE
  695. + OPTPROC_HAS_IMMED ),
  696. 0, NULL, /* current option index, current option */
  697. NULL, NULL, zPROGNAME,
  698. zRcName, zCopyright, zCopyrightNotice,
  699. zFullVersion, apzHomeList, zUsageTitle,
  700. zExplain, zDetail, optDesc,
  701. zBugsAddr, /* address to send bugs to */
  702. NULL, NULL, /* extensions/saved state */
  703. optionUsage, /* usage procedure */
  704. translate_option_strings, /* translation procedure */
  705. /*
  706. * Indexes to special options
  707. */
  708. { INDEX_OPT_MORE_HELP,
  709. INDEX_OPT_SAVE_OPTS,
  710. NO_EQUIVALENT /* index of '-#' option */,
  711. 13 /* index of default opt */
  712. },
  713. OPTION_CT, 24 /* user option count */
  714. };
  715. /*
  716. * Create the static procedure(s) declared above.
  717. */
  718. static void
  719. doUsageOpt(
  720. tOptions* pOptions,
  721. tOptDesc* pOptDesc )
  722. {
  723. USAGE( EXIT_SUCCESS );
  724. }
  725. /* * * * * * *
  726. *
  727. * For the dbug option.
  728. */
  729. static void
  730. doOptDbug(
  731. tOptions* pOptions,
  732. tOptDesc* pOptDesc )
  733. {
  734. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  735. { 0, 5 } };
  736. long val;
  737. int ix;
  738. tCC* pzIndent = "\t\t\t\t ";
  739. extern FILE* option_usage_fp;
  740. if (pOptDesc == NULL) /* usage is requesting range list
  741. option_usage_fp has already been set */
  742. goto emit_ranges;
  743. val = atoi( pOptDesc->pzLastArg );
  744. for (ix = 0; ix < 1; ix++) {
  745. if (val < rng[ix].rmin)
  746. continue; /* ranges need not be ordered. */
  747. if (val == rng[ix].rmin)
  748. goto valid_return;
  749. if (rng[ix].rmax == INT_MIN)
  750. continue;
  751. if (val <= rng[ix].rmax)
  752. goto valid_return;
  753. }
  754. option_usage_fp = stderr;
  755. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  756. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  757. pzIndent = "\t";
  758. emit_ranges:
  759. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  760. pzIndent, rng[0].rmin, rng[0].rmax );
  761. if (pOptDesc == NULL)
  762. return;
  763. USAGE( EXIT_FAILURE );
  764. /* NOTREACHED */
  765. return;
  766. valid_return:
  767. pOptDesc->pzLastArg = (char*)val;
  768. }
  769. /* * * * * * *
  770. *
  771. * For the dmac option.
  772. */
  773. static void
  774. doOptDmac(
  775. tOptions* pOptions,
  776. tOptDesc* pOptDesc )
  777. {
  778. int mask = 0;
  779. mask = dualmac2hex(OPT_ARG(DMAC), options.intf1_dmac, options.intf2_dmac,
  780. strlen(OPT_ARG(DMAC)));
  781. options.mac_mask ^= (mask << 2);
  782. }
  783. /* * * * * * *
  784. *
  785. * For the smac option.
  786. */
  787. static void
  788. doOptSmac(
  789. tOptions* pOptions,
  790. tOptDesc* pOptDesc )
  791. {
  792. int mask = 0;
  793. mask = dualmac2hex(OPT_ARG(SMAC), options.intf1_smac, options.intf2_smac,
  794. strlen(OPT_ARG(SMAC)));
  795. options.mac_mask ^= mask;
  796. }
  797. /* * * * * * *
  798. *
  799. * For the proto option.
  800. */
  801. static void
  802. doOptProto(
  803. tOptions* pOptions,
  804. tOptDesc* pOptDesc )
  805. {
  806. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  807. { 0, 65535 } };
  808. long val;
  809. int ix;
  810. tCC* pzIndent = "\t\t\t\t ";
  811. extern FILE* option_usage_fp;
  812. if (pOptDesc == NULL) /* usage is requesting range list
  813. option_usage_fp has already been set */
  814. goto emit_ranges;
  815. val = atoi( pOptDesc->pzLastArg );
  816. for (ix = 0; ix < 1; ix++) {
  817. if (val < rng[ix].rmin)
  818. continue; /* ranges need not be ordered. */
  819. if (val == rng[ix].rmin)
  820. goto valid_return;
  821. if (rng[ix].rmax == INT_MIN)
  822. continue;
  823. if (val <= rng[ix].rmax)
  824. goto valid_return;
  825. }
  826. option_usage_fp = stderr;
  827. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  828. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  829. pzIndent = "\t";
  830. emit_ranges:
  831. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  832. pzIndent, rng[0].rmin, rng[0].rmax );
  833. if (pOptDesc == NULL)
  834. return;
  835. USAGE( EXIT_FAILURE );
  836. /* NOTREACHED */
  837. return;
  838. valid_return:
  839. pOptDesc->pzLastArg = (char*)val;
  840. }
  841. /* * * * * * *
  842. *
  843. * For the dlink option.
  844. */
  845. static void
  846. doOptDlink(
  847. tOptions* pOptions,
  848. tOptDesc* pOptDesc )
  849. {
  850. static int count = 1;
  851. options.l2.enabled = 1;
  852. if (count == 1) {
  853. options.l2.len = read_hexstring(OPT_ARG(DLINK), options.l2.data1, L2DATALEN);
  854. /*
  855. * preemtively copy over our data1[] to data2[] if user doesn't specify
  856. * any data2[] data
  857. */
  858. memcpy(options.l2.data2, options.l2.data1, options.l2.len);
  859. count ++;
  860. } else {
  861. if (options.l2.len != read_hexstring(OPT_ARG(DLINK), options.l2.data2, L2DATALEN))
  862. err(1, "Layer2 data for both interfaces must be the same length");
  863. }
  864. }
  865. /* * * * * * *
  866. *
  867. * For the portmap option.
  868. */
  869. static void
  870. doOptPortmap(
  871. tOptions* pOptions,
  872. tOptDesc* pOptDesc )
  873. {
  874. }
  875. /* * * * * * *
  876. *
  877. * For the pnat option.
  878. */
  879. static void
  880. doOptPnat(
  881. tOptions* pOptions,
  882. tOptDesc* pOptDesc )
  883. {
  884. static int count = 1;
  885. options.rewrite_ip ++;
  886. if (count == 1) {
  887. if (! parse_cidr_map(&options.cidrmap1, OPT_ARG(PNAT)))
  888. errx(1, "Unable to parse primary pseudo-NAT: %s", OPT_ARG(PNAT));
  889. count ++;
  890. } else {
  891. if (! parse_cidr_map(&options.cidrmap2, OPT_ARG(PNAT)))
  892. errx(1, "Unable parse secondary pseudo-NAT: %s", OPT_ARG(PNAT));
  893. }
  894. }
  895. /* * * * * * *
  896. *
  897. * For the fixcsum option.
  898. */
  899. static void
  900. doOptFixcsum(
  901. tOptions* pOptions,
  902. tOptDesc* pOptDesc )
  903. {
  904. options.fixcsum = 1;
  905. }
  906. /* * * * * * *
  907. *
  908. * For the infile option.
  909. */
  910. static void
  911. doOptInfile(
  912. tOptions* pOptions,
  913. tOptDesc* pOptDesc )
  914. {
  915. char ebuf[PCAP_ERRBUF_SIZE];
  916. options.infile = safe_strdup(OPT_ARG(INFILE));
  917. if ((options.pin = pcap_open_offline(options.infile, ebuf)) == NULL)
  918. errx(1, "Unable to open input pcap file: %s", ebuf);
  919. }
  920. /* * * * * * *
  921. *
  922. * For the cachefile option.
  923. */
  924. static void
  925. doOptCachefile(
  926. tOptions* pOptions,
  927. tOptDesc* pOptDesc )
  928. {
  929. options.cache_packets =
  930. read_cache(&options.cachedata, OPT_ARG(CACHEFILE), &options.comment);
  931. }
  932. /* * * * * * *
  933. *
  934. * For the mtu option.
  935. */
  936. static void
  937. doOptMtu(
  938. tOptions* pOptions,
  939. tOptDesc* pOptDesc )
  940. {
  941. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  942. { 1, MAXPACKET } };
  943. long val;
  944. int ix;
  945. tCC* pzIndent = "\t\t\t\t ";
  946. extern FILE* option_usage_fp;
  947. if (pOptDesc == NULL) /* usage is requesting range list
  948. option_usage_fp has already been set */
  949. goto emit_ranges;
  950. val = atoi( pOptDesc->pzLastArg );
  951. for (ix = 0; ix < 1; ix++) {
  952. if (val < rng[ix].rmin)
  953. continue; /* ranges need not be ordered. */
  954. if (val == rng[ix].rmin)
  955. goto valid_return;
  956. if (rng[ix].rmax == INT_MIN)
  957. continue;
  958. if (val <= rng[ix].rmax)
  959. goto valid_return;
  960. }
  961. option_usage_fp = stderr;
  962. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  963. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  964. pzIndent = "\t";
  965. emit_ranges:
  966. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  967. pzIndent, rng[0].rmin, rng[0].rmax );
  968. if (pOptDesc == NULL)
  969. return;
  970. USAGE( EXIT_FAILURE );
  971. /* NOTREACHED */
  972. return;
  973. valid_return:
  974. pOptDesc->pzLastArg = (char*)val;
  975. }
  976. /* * * * * * *
  977. *
  978. * For the efcs option.
  979. */
  980. static void
  981. doOptEfcs(
  982. tOptions* pOptions,
  983. tOptDesc* pOptDesc )
  984. {
  985. options.efcs = 1;
  986. }
  987. /* * * * * * *
  988. *
  989. * For the fixlen option.
  990. */
  991. static void
  992. doOptFixlen(
  993. tOptions* pOptions,
  994. tOptDesc* pOptDesc )
  995. {
  996. if (strcmp(OPT_ARG(FIXLEN), "pad") == 0) {
  997. options.fixlen = FIXLEN_PAD;
  998. } else if (strcmp(OPT_ARG(FIXLEN), "trunc") == 0) {
  999. options.fixlen = FIXLEN_TRUNC;
  1000. } else {
  1001. errx(1, "Invalid fixlen argument '%s'. Must be 'trunc' or 'pad'", OPT_ARG(FIXLEN));
  1002. }
  1003. }
  1004. /* * * * * * *
  1005. *
  1006. * For the vlan option.
  1007. */
  1008. static void
  1009. doOptVlan(
  1010. tOptions* pOptions,
  1011. tOptDesc* pOptDesc )
  1012. {
  1013. if (strcmp(OPT_ARG(VLAN), "add") == 0) {
  1014. options.vlan = VLAN_ADD;
  1015. } else if (strcmp(OPT_ARG(VLAN), "del") == 0) {
  1016. options.vlan = VLAN_DEL;
  1017. } else {
  1018. errx(1, "Invalid vlan argument '%s'. Must be 'add' or 'del'", OPT_ARG(VLAN));
  1019. }
  1020. }
  1021. /* * * * * * *
  1022. *
  1023. * For the vlan_tag option.
  1024. */
  1025. static void
  1026. doOptVlan_Tag(
  1027. tOptions* pOptions,
  1028. tOptDesc* pOptDesc )
  1029. {
  1030. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  1031. { 0, 4095 } };
  1032. long val;
  1033. int ix;
  1034. tCC* pzIndent = "\t\t\t\t ";
  1035. extern FILE* option_usage_fp;
  1036. if (pOptDesc == NULL) /* usage is requesting range list
  1037. option_usage_fp has already been set */
  1038. goto emit_ranges;
  1039. val = atoi( pOptDesc->pzLastArg );
  1040. for (ix = 0; ix < 1; ix++) {
  1041. if (val < rng[ix].rmin)
  1042. continue; /* ranges need not be ordered. */
  1043. if (val == rng[ix].rmin)
  1044. goto valid_return;
  1045. if (rng[ix].rmax == INT_MIN)
  1046. continue;
  1047. if (val <= rng[ix].rmax)
  1048. goto valid_return;
  1049. }
  1050. option_usage_fp = stderr;
  1051. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  1052. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  1053. pzIndent = "\t";
  1054. emit_ranges:
  1055. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  1056. pzIndent, rng[0].rmin, rng[0].rmax );
  1057. if (pOptDesc == NULL)
  1058. return;
  1059. USAGE( EXIT_FAILURE );
  1060. /* NOTREACHED */
  1061. return;
  1062. valid_return:
  1063. pOptDesc->pzLastArg = (char*)val;
  1064. }
  1065. /* * * * * * *
  1066. *
  1067. * For the vlan_cfi option.
  1068. */
  1069. static void
  1070. doOptVlan_Cfi(
  1071. tOptions* pOptions,
  1072. tOptDesc* pOptDesc )
  1073. {
  1074. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  1075. { 0, 1 } };
  1076. long val;
  1077. int ix;
  1078. tCC* pzIndent = "\t\t\t\t ";
  1079. extern FILE* option_usage_fp;
  1080. if (pOptDesc == NULL) /* usage is requesting range list
  1081. option_usage_fp has already been set */
  1082. goto emit_ranges;
  1083. val = atoi( pOptDesc->pzLastArg );
  1084. for (ix = 0; ix < 1; ix++) {
  1085. if (val < rng[ix].rmin)
  1086. continue; /* ranges need not be ordered. */
  1087. if (val == rng[ix].rmin)
  1088. goto valid_return;
  1089. if (rng[ix].rmax == INT_MIN)
  1090. continue;
  1091. if (val <= rng[ix].rmax)
  1092. goto valid_return;
  1093. }
  1094. option_usage_fp = stderr;
  1095. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  1096. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  1097. pzIndent = "\t";
  1098. emit_ranges:
  1099. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  1100. pzIndent, rng[0].rmin, rng[0].rmax );
  1101. if (pOptDesc == NULL)
  1102. return;
  1103. USAGE( EXIT_FAILURE );
  1104. /* NOTREACHED */
  1105. return;
  1106. valid_return:
  1107. pOptDesc->pzLastArg = (char*)val;
  1108. }
  1109. /* * * * * * *
  1110. *
  1111. * For the vlan_pri option.
  1112. */
  1113. static void
  1114. doOptVlan_Pri(
  1115. tOptions* pOptions,
  1116. tOptDesc* pOptDesc )
  1117. {
  1118. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  1119. { 0, 7 } };
  1120. long val;
  1121. int ix;
  1122. tCC* pzIndent = "\t\t\t\t ";
  1123. extern FILE* option_usage_fp;
  1124. if (pOptDesc == NULL) /* usage is requesting range list
  1125. option_usage_fp has already been set */
  1126. goto emit_ranges;
  1127. val = atoi( pOptDesc->pzLastArg );
  1128. for (ix = 0; ix < 1; ix++) {
  1129. if (val < rng[ix].rmin)
  1130. continue; /* ranges need not be ordered. */
  1131. if (val == rng[ix].rmin)
  1132. goto valid_return;
  1133. if (rng[ix].rmax == INT_MIN)
  1134. continue;
  1135. if (val <= rng[ix].rmax)
  1136. goto valid_return;
  1137. }
  1138. option_usage_fp = stderr;
  1139. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  1140. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  1141. pzIndent = "\t";
  1142. emit_ranges:
  1143. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  1144. pzIndent, rng[0].rmin, rng[0].rmax );
  1145. if (pOptDesc == NULL)
  1146. return;
  1147. USAGE( EXIT_FAILURE );
  1148. /* NOTREACHED */
  1149. return;
  1150. valid_return:
  1151. pOptDesc->pzLastArg = (char*)val;
  1152. }
  1153. /* * * * * * *
  1154. *
  1155. * For the version option.
  1156. */
  1157. static void
  1158. doOptVersion(
  1159. tOptions* pOptions,
  1160. tOptDesc* pOptDesc )
  1161. {
  1162. fprintf(stderr, "tcprewrite version: %s (build %s)", VERSION, svn_version());
  1163. #ifdef DEBUG
  1164. fprintf(stderr, " (debug)");
  1165. #endif
  1166. fprintf(stderr, "\n");
  1167. fprintf(stderr, "Copyright 2001-2005 by Aaron Turner <aturner@pobox.com>\n");
  1168. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  1169. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  1170. fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
  1171. #ifdef ENABLE_64BITS
  1172. fprintf(stderr, "64 bit packet counters: enabled\n");
  1173. #else
  1174. fprintf(stderr, "64 bit packet counters: disabled\n");
  1175. #endif
  1176. exit(0);
  1177. }
  1178. /* * * * * * *
  1179. *
  1180. * For the less-help option.
  1181. */
  1182. static void
  1183. doOptLess_Help(
  1184. tOptions* pOptions,
  1185. tOptDesc* pOptDesc )
  1186. {
  1187. USAGE(EXIT_FAILURE);
  1188. }
  1189. /* extracted from /usr/local/share/autogen/optcode.tpl near line 396 */
  1190. #if ENABLE_NLS
  1191. #include <string.h>
  1192. #include <stdio.h>
  1193. #include <autoopts/usage-txt.h>
  1194. static char*
  1195. AO_gettext( const char* pz )
  1196. {
  1197. char* pzRes;
  1198. if (pz == NULL)
  1199. return NULL;
  1200. pzRes = _(pz);
  1201. if (pzRes == pz)
  1202. return pzRes;
  1203. pzRes = strdup( pzRes );
  1204. if (pzRes == NULL) {
  1205. fputs( _("No memory for duping translated strings\n"), stderr );
  1206. exit( EXIT_FAILURE );
  1207. }
  1208. return pzRes;
  1209. }
  1210. /*
  1211. * This invokes the translation code (e.g. gettext(3)).
  1212. */
  1213. static void
  1214. translate_option_strings( void )
  1215. {
  1216. /*
  1217. * Guard against re-translation. It won't work. The strings will have
  1218. * been changed by the first pass through this code. One shot only.
  1219. */
  1220. if (option_usage_text.field_ct == 0)
  1221. return;
  1222. /*
  1223. * Do the translations. The first pointer follows the field count field.
  1224. * The field count field is the size of a pointer.
  1225. */
  1226. {
  1227. char** ppz = (char**)(void*)&(option_usage_text);
  1228. int ix = option_usage_text.field_ct;
  1229. do {
  1230. ppz++;
  1231. *ppz = AO_gettext(*ppz);
  1232. } while (--ix > 0);
  1233. }
  1234. option_usage_text.field_ct = 0;
  1235. {
  1236. tOptDesc* pOD = tcprewriteOptions.pOptDesc;
  1237. int ix = tcprewriteOptions.optCt;
  1238. for (;;) {
  1239. pOD->pzText = AO_gettext(pOD->pzText);
  1240. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  1241. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  1242. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  1243. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  1244. if (--ix <= 0)
  1245. break;
  1246. pOD++;
  1247. }
  1248. }
  1249. tcprewriteOptions.pzCopyright = AO_gettext(tcprewriteOptions.pzCopyright);
  1250. tcprewriteOptions.pzCopyNotice = AO_gettext(tcprewriteOptions.pzCopyNotice);
  1251. tcprewriteOptions.pzFullVersion = AO_gettext(tcprewriteOptions.pzFullVersion);
  1252. tcprewriteOptions.pzUsageTitle = AO_gettext(tcprewriteOptions.pzUsageTitle);
  1253. tcprewriteOptions.pzExplain = AO_gettext(tcprewriteOptions.pzExplain);
  1254. tcprewriteOptions.pzDetail = AO_gettext(tcprewriteOptions.pzDetail);
  1255. }
  1256. #endif /* ENABLE_NLS */
  1257. #ifdef __cplusplus
  1258. }
  1259. #endif