tcprewrite_opts.c 42 KB

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