tcprewrite_opts.c 39 KB

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