tcprewrite_opts.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  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 Tuesday February 17, 2009 at 06:26:57 PM PST
  6. * From the definitions tcprewrite_opts.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 32:0:7 templates.
  10. */
  11. /*
  12. * This file was produced by an AutoOpts template. AutoOpts is a
  13. * copyrighted work. This source file is not encumbered by AutoOpts
  14. * licensing, but is provided under the licensing terms chosen by the
  15. * tcprewrite author or copyright holder. AutoOpts is licensed under
  16. * the terms of the LGPL. The redistributable library (``libopts'') is
  17. * licensed under the terms of either the LGPL or, at the users discretion,
  18. * the BSD license. See the AutoOpts and/or libopts sources for details.
  19. *
  20. * This source file is copyrighted and licensed under the following terms:
  21. *
  22. * tcprewrite copyright 2004-2008 Aaron Turner - all rights reserved
  23. *
  24. * tcprewrite is free software copyrighted by Aaron Turner.
  25. *
  26. * Redistribution and use in source and binary forms, with or without
  27. * modification, are permitted provided that the following conditions
  28. * are met:
  29. * 1. Redistributions of source code must retain the above copyright
  30. * notice, this list of conditions and the following disclaimer.
  31. * 2. Redistributions in binary form must reproduce the above copyright
  32. * notice, this list of conditions and the following disclaimer in the
  33. * documentation and/or other materials provided with the distribution.
  34. * 3. Neither the name ``Aaron Turner'' nor the name of any other
  35. * contributor may be used to endorse or promote products derived
  36. * from this software without specific prior written permission.
  37. *
  38. * tcprewrite IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS
  39. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  40. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. * ARE DISCLAIMED. IN NO EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS
  42. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  43. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  44. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  45. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  46. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  47. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  48. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50. #include <sys/types.h>
  51. #include <limits.h>
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <errno.h>
  55. extern FILE * option_usage_fp;
  56. #define OPTION_CODE_COMPILE 1
  57. #include "tcprewrite_opts.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /* TRANSLATORS: choose the translation for option names wisely because you
  62. cannot ever change your mind. */
  63. tSCC zCopyright[] =
  64. "tcprewrite copyright (c) 2004-2008 Aaron Turner, all rights reserved";
  65. tSCC zCopyrightNotice[1460] =
  66. "tcprewrite is free software copyrighted by Aaron Turner.\n\n\
  67. Redistribution and use in source and binary forms, with or without\n\
  68. modification, are permitted provided that the following conditions are met: 1.\n\
  69. Redistributions of source code must retain the above copyright notice, this\n\
  70. list of conditions and the following disclaimer. 2. Redistributions in binary\n\
  71. form must reproduce the above copyright notice, this list of conditions and the\n\
  72. following disclaimer in the documentation and/or other materials provided with\n\
  73. the distribution. 3. Neither the name ``Aaron Turner'' nor the name of any\n\
  74. other contributor may be used to endorse or promote products derived from this\n\
  75. software without specific prior written permission.\n\n\
  76. tcprewrite IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS OR IMPLIED\n\
  77. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n\
  78. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n\
  79. EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n\
  80. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n\
  81. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
  82. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n\
  83. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n\
  84. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n\
  85. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
  86. extern tUsageProc optionUsage;
  87. /*
  88. * global included definitions
  89. */
  90. #include "defines.h"
  91. #include "common.h"
  92. #include "config.h"
  93. #include "tcprewrite.h"
  94. #include <stdlib.h>
  95. #include <string.h>
  96. extern tcprewrite_opt_t options;
  97. #ifndef NULL
  98. # define NULL 0
  99. #endif
  100. #ifndef EXIT_SUCCESS
  101. # define EXIT_SUCCESS 0
  102. #endif
  103. #ifndef EXIT_FAILURE
  104. # define EXIT_FAILURE 1
  105. #endif
  106. /*
  107. * Tcpedit option description:
  108. */
  109. tSCC zTcpeditText[] =
  110. "";
  111. #define TCPEDIT_FLAGS (OPTST_DOCUMENT | OPTST_NO_INIT)
  112. /*
  113. * Portmap option description:
  114. */
  115. tSCC zPortmapText[] =
  116. "Rewrite TCP/UDP ports";
  117. tSCC zPortmap_NAME[] = "PORTMAP";
  118. tSCC zPortmap_Name[] = "portmap";
  119. #define PORTMAP_FLAGS (OPTST_DISABLED \
  120. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  121. /*
  122. * Seed option description:
  123. */
  124. tSCC zSeedText[] =
  125. "Randomize src/dst IP addresses w/ given seed";
  126. tSCC zSeed_NAME[] = "SEED";
  127. tSCC zSeed_Name[] = "seed";
  128. #define SEED_FLAGS (OPTST_DISABLED \
  129. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  130. /*
  131. * Pnat option description with
  132. * "Must also have options" and "Incompatible options":
  133. */
  134. tSCC zPnatText[] =
  135. "Rewrite IP addresses using pseudo-NAT";
  136. tSCC zPnat_NAME[] = "PNAT";
  137. tSCC zPnat_Name[] = "pnat";
  138. static const int
  139. aPnatCantList[] = {
  140. INDEX_OPT_SRCIPMAP, NO_EQUIVALENT };
  141. #define PNAT_FLAGS (OPTST_DISABLED | OPTST_STACKED \
  142. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  143. /*
  144. * Srcipmap option description with
  145. * "Must also have options" and "Incompatible options":
  146. */
  147. tSCC zSrcipmapText[] =
  148. "Rewrite source IP addresses using pseudo-NAT";
  149. tSCC zSrcipmap_NAME[] = "SRCIPMAP";
  150. tSCC zSrcipmap_Name[] = "srcipmap";
  151. static const int
  152. aSrcipmapCantList[] = {
  153. INDEX_OPT_PNAT, NO_EQUIVALENT };
  154. #define SRCIPMAP_FLAGS (OPTST_DISABLED \
  155. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  156. /*
  157. * Dstipmap option description with
  158. * "Must also have options" and "Incompatible options":
  159. */
  160. tSCC zDstipmapText[] =
  161. "Rewrite destination IP addresses using pseudo-NAT";
  162. tSCC zDstipmap_NAME[] = "DSTIPMAP";
  163. tSCC zDstipmap_Name[] = "dstipmap";
  164. static const int
  165. aDstipmapCantList[] = {
  166. INDEX_OPT_PNAT, NO_EQUIVALENT };
  167. #define DSTIPMAP_FLAGS (OPTST_DISABLED \
  168. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  169. /*
  170. * Endpoints option description with
  171. * "Must also have options" and "Incompatible options":
  172. */
  173. #ifdef HAVE_CACHEFILE_SUPPORT
  174. tSCC zEndpointsText[] =
  175. "Rewrite IP addresses to be between two endpoints";
  176. tSCC zEndpoints_NAME[] = "ENDPOINTS";
  177. tSCC zEndpoints_Name[] = "endpoints";
  178. static const int
  179. aEndpointsMustList[] = {
  180. INDEX_OPT_CACHEFILE, NO_EQUIVALENT };
  181. #define ENDPOINTS_FLAGS (OPTST_DISABLED \
  182. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  183. #else /* disable Endpoints */
  184. #define VALUE_OPT_ENDPOINTS NO_EQUIVALENT
  185. #define ENDPOINTS_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  186. #define aEndpointsMustList NULL
  187. #define zEndpointsText NULL
  188. #define zEndpoints_NAME NULL
  189. #define zEndpoints_Name NULL
  190. #endif /* HAVE_CACHEFILE_SUPPORT */
  191. /*
  192. * Skipbroadcast option description:
  193. */
  194. tSCC zSkipbroadcastText[] =
  195. "Skip rewriting broadcast/multicast IP's";
  196. tSCC zSkipbroadcast_NAME[] = "SKIPBROADCAST";
  197. tSCC zSkipbroadcast_Name[] = "skipbroadcast";
  198. #define SKIPBROADCAST_FLAGS (OPTST_DISABLED)
  199. /*
  200. * Fixcsum option description:
  201. */
  202. tSCC zFixcsumText[] =
  203. "Force recalculation of IP/TCP/UDP checksums";
  204. tSCC zFixcsum_NAME[] = "FIXCSUM";
  205. tSCC zFixcsum_Name[] = "fixcsum";
  206. #define FIXCSUM_FLAGS (OPTST_DISABLED)
  207. /*
  208. * Mtu option description:
  209. */
  210. tSCC zMtuText[] =
  211. "Override default MTU length (1500 bytes)";
  212. tSCC zMtu_NAME[] = "MTU";
  213. tSCC zMtu_Name[] = "mtu";
  214. #define MTU_FLAGS (OPTST_DISABLED \
  215. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  216. /*
  217. * Mtu_Trunc option description:
  218. */
  219. tSCC zMtu_TruncText[] =
  220. "Truncate packets larger then specified MTU";
  221. tSCC zMtu_Trunc_NAME[] = "MTU_TRUNC";
  222. tSCC zMtu_Trunc_Name[] = "mtu-trunc";
  223. #define MTU_TRUNC_FLAGS (OPTST_DISABLED)
  224. /*
  225. * Efcs option description:
  226. */
  227. tSCC zEfcsText[] =
  228. "Remove Ethernet checksums (FCS) from end of frames";
  229. tSCC zEfcs_NAME[] = "EFCS";
  230. tSCC zEfcs_Name[] = "efcs";
  231. #define EFCS_FLAGS (OPTST_DISABLED)
  232. /*
  233. * Ttl option description:
  234. */
  235. tSCC zTtlText[] =
  236. "Modify the IPv4 TTL";
  237. tSCC zTtl_NAME[] = "TTL";
  238. tSCC zTtl_Name[] = "ttl";
  239. #define TTL_FLAGS (OPTST_DISABLED \
  240. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  241. /*
  242. * Tos option description:
  243. */
  244. tSCC zTosText[] =
  245. "Set the IPv4 TOS/DiffServ/ECN byte";
  246. tSCC zTos_NAME[] = "TOS";
  247. tSCC zTos_Name[] = "tos";
  248. #define TOS_FLAGS (OPTST_DISABLED \
  249. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  250. /*
  251. * Fixlen option description:
  252. */
  253. tSCC zFixlenText[] =
  254. "Pad or truncate packet data to match header length";
  255. tSCC zFixlen_NAME[] = "FIXLEN";
  256. tSCC zFixlen_Name[] = "fixlen";
  257. #define FIXLEN_FLAGS (OPTST_DISABLED \
  258. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  259. /*
  260. * Skipl2broadcast option description:
  261. */
  262. tSCC zSkipl2broadcastText[] =
  263. "Skip rewriting broadcast/multicast Layer 2 addresses";
  264. tSCC zSkipl2broadcast_NAME[] = "SKIPL2BROADCAST";
  265. tSCC zSkipl2broadcast_Name[] = "skipl2broadcast";
  266. #define SKIPL2BROADCAST_FLAGS (OPTST_DISABLED)
  267. /*
  268. * Dlt option description:
  269. */
  270. tSCC zDltText[] =
  271. "Override output DLT encapsulation";
  272. tSCC zDlt_NAME[] = "DLT";
  273. tSCC zDlt_Name[] = "dlt";
  274. #define DLT_FLAGS (OPTST_DISABLED \
  275. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  276. /*
  277. * Enet_Dmac option description:
  278. */
  279. tSCC zEnet_DmacText[] =
  280. "Override destination ethernet MAC addresses";
  281. tSCC zEnet_Dmac_NAME[] = "ENET_DMAC";
  282. tSCC zEnet_Dmac_Name[] = "enet-dmac";
  283. #define ENET_DMAC_FLAGS (OPTST_DISABLED \
  284. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  285. /*
  286. * Enet_Smac option description:
  287. */
  288. tSCC zEnet_SmacText[] =
  289. "Override source ethernet MAC addresses";
  290. tSCC zEnet_Smac_NAME[] = "ENET_SMAC";
  291. tSCC zEnet_Smac_Name[] = "enet-smac";
  292. #define ENET_SMAC_FLAGS (OPTST_DISABLED \
  293. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  294. /*
  295. * Enet_Vlan option description:
  296. */
  297. tSCC zEnet_VlanText[] =
  298. "Specify ethernet 802.1q VLAN tag mode";
  299. tSCC zEnet_Vlan_NAME[] = "ENET_VLAN";
  300. tSCC zEnet_Vlan_Name[] = "enet-vlan";
  301. #define ENET_VLAN_FLAGS (OPTST_DISABLED \
  302. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  303. /*
  304. * Enet_Vlan_Tag option description with
  305. * "Must also have options" and "Incompatible options":
  306. */
  307. tSCC zEnet_Vlan_TagText[] =
  308. "Specify the new ethernet 802.1q VLAN tag value";
  309. tSCC zEnet_Vlan_Tag_NAME[] = "ENET_VLAN_TAG";
  310. tSCC zEnet_Vlan_Tag_Name[] = "enet-vlan-tag";
  311. static const int
  312. aEnet_Vlan_TagMustList[] = {
  313. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  314. #define ENET_VLAN_TAG_FLAGS (OPTST_DISABLED \
  315. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  316. /*
  317. * Enet_Vlan_Cfi option description with
  318. * "Must also have options" and "Incompatible options":
  319. */
  320. tSCC zEnet_Vlan_CfiText[] =
  321. "Specify the ethernet 802.1q VLAN CFI value";
  322. tSCC zEnet_Vlan_Cfi_NAME[] = "ENET_VLAN_CFI";
  323. tSCC zEnet_Vlan_Cfi_Name[] = "enet-vlan-cfi";
  324. static const int
  325. aEnet_Vlan_CfiMustList[] = {
  326. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  327. #define ENET_VLAN_CFI_FLAGS (OPTST_DISABLED \
  328. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  329. /*
  330. * Enet_Vlan_Pri option description with
  331. * "Must also have options" and "Incompatible options":
  332. */
  333. tSCC zEnet_Vlan_PriText[] =
  334. "Specify the ethernet 802.1q VLAN priority";
  335. tSCC zEnet_Vlan_Pri_NAME[] = "ENET_VLAN_PRI";
  336. tSCC zEnet_Vlan_Pri_Name[] = "enet-vlan-pri";
  337. static const int
  338. aEnet_Vlan_PriMustList[] = {
  339. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  340. #define ENET_VLAN_PRI_FLAGS (OPTST_DISABLED \
  341. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  342. /*
  343. * Hdlc_Control option description:
  344. */
  345. tSCC zHdlc_ControlText[] =
  346. "Specify HDLC control value";
  347. tSCC zHdlc_Control_NAME[] = "HDLC_CONTROL";
  348. tSCC zHdlc_Control_Name[] = "hdlc-control";
  349. #define HDLC_CONTROL_FLAGS (OPTST_DISABLED \
  350. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  351. /*
  352. * Hdlc_Address option description:
  353. */
  354. tSCC zHdlc_AddressText[] =
  355. "Specify HDLC address";
  356. tSCC zHdlc_Address_NAME[] = "HDLC_ADDRESS";
  357. tSCC zHdlc_Address_Name[] = "hdlc-address";
  358. #define HDLC_ADDRESS_FLAGS (OPTST_DISABLED \
  359. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  360. /*
  361. * User_Dlt option description:
  362. */
  363. tSCC zUser_DltText[] =
  364. "Set output file DLT type";
  365. tSCC zUser_Dlt_NAME[] = "USER_DLT";
  366. tSCC zUser_Dlt_Name[] = "user-dlt";
  367. #define USER_DLT_FLAGS (OPTST_DISABLED \
  368. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  369. /*
  370. * User_Dlink option description:
  371. */
  372. tSCC zUser_DlinkText[] =
  373. "Rewrite Data-Link layer with user specified data";
  374. tSCC zUser_Dlink_NAME[] = "USER_DLINK";
  375. tSCC zUser_Dlink_Name[] = "user-dlink";
  376. #define USER_DLINK_FLAGS (OPTST_DISABLED | OPTST_STACKED \
  377. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  378. /*
  379. * Dbug option description:
  380. */
  381. #ifdef DEBUG
  382. tSCC zDbugText[] =
  383. "Enable debugging output";
  384. tSCC zDbug_NAME[] = "DBUG";
  385. tSCC zDbug_Name[] = "dbug";
  386. #define zDbugDefaultArg ((char const*)0)
  387. #define DBUG_FLAGS (OPTST_DISABLED | OPTST_IMM \
  388. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  389. #else /* disable Dbug */
  390. #define VALUE_OPT_DBUG NO_EQUIVALENT
  391. #define DBUG_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  392. #define zDbugDefaultArg NULL
  393. #define zDbugText NULL
  394. #define zDbug_NAME NULL
  395. #define zDbug_Name NULL
  396. #endif /* DEBUG */
  397. /*
  398. * Infile option description:
  399. */
  400. tSCC zInfileText[] =
  401. "Input pcap file to be processed";
  402. tSCC zInfile_NAME[] = "INFILE";
  403. tSCC zInfile_Name[] = "infile";
  404. #define INFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET | OPTST_IMM \
  405. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  406. /*
  407. * Outfile option description:
  408. */
  409. tSCC zOutfileText[] =
  410. "Output pcap file";
  411. tSCC zOutfile_NAME[] = "OUTFILE";
  412. tSCC zOutfile_Name[] = "outfile";
  413. #define OUTFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  414. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  415. /*
  416. * Cachefile option description:
  417. */
  418. tSCC zCachefileText[] =
  419. "Split traffic via tcpprep cache file";
  420. tSCC zCachefile_NAME[] = "CACHEFILE";
  421. tSCC zCachefile_Name[] = "cachefile";
  422. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  423. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  424. /*
  425. * Verbose option description:
  426. */
  427. #ifdef ENABLE_VERBOSE
  428. tSCC zVerboseText[] =
  429. "Print decoded packets via tcpdump to STDOUT";
  430. tSCC zVerbose_NAME[] = "VERBOSE";
  431. tSCC zVerbose_Name[] = "verbose";
  432. #define VERBOSE_FLAGS (OPTST_DISABLED | OPTST_IMM)
  433. #else /* disable Verbose */
  434. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  435. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  436. #define zVerboseText NULL
  437. #define zVerbose_NAME NULL
  438. #define zVerbose_Name NULL
  439. #endif /* ENABLE_VERBOSE */
  440. /*
  441. * Decode option description with
  442. * "Must also have options" and "Incompatible options":
  443. */
  444. #ifdef ENABLE_VERBOSE
  445. tSCC zDecodeText[] =
  446. "Arguments passed to tcpdump decoder";
  447. tSCC zDecode_NAME[] = "DECODE";
  448. tSCC zDecode_Name[] = "decode";
  449. static const int
  450. aDecodeMustList[] = {
  451. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  452. #define DECODE_FLAGS (OPTST_DISABLED \
  453. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  454. #else /* disable Decode */
  455. #define VALUE_OPT_DECODE NO_EQUIVALENT
  456. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  457. #define aDecodeMustList NULL
  458. #define zDecodeText NULL
  459. #define zDecode_NAME NULL
  460. #define zDecode_Name NULL
  461. #endif /* ENABLE_VERBOSE */
  462. /*
  463. * Fragroute option description:
  464. */
  465. #ifdef ENABLE_FRAGROUTE
  466. tSCC zFragrouteText[] =
  467. "Parse fragroute configuration file";
  468. tSCC zFragroute_NAME[] = "FRAGROUTE";
  469. tSCC zFragroute_Name[] = "fragroute";
  470. #define FRAGROUTE_FLAGS (OPTST_DISABLED \
  471. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  472. #else /* disable Fragroute */
  473. #define VALUE_OPT_FRAGROUTE NO_EQUIVALENT
  474. #define FRAGROUTE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  475. #define zFragrouteText NULL
  476. #define zFragroute_NAME NULL
  477. #define zFragroute_Name NULL
  478. #endif /* ENABLE_FRAGROUTE */
  479. /*
  480. * Fragdir option description:
  481. */
  482. #ifdef ENABLE_FRAGROUTE
  483. tSCC zFragdirText[] =
  484. "Which flows to apply fragroute to: c2s, s2c, both";
  485. tSCC zFragdir_NAME[] = "FRAGDIR";
  486. tSCC zFragdir_Name[] = "fragdir";
  487. #define FRAGDIR_FLAGS (OPTST_DISABLED \
  488. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  489. #else /* disable Fragdir */
  490. #define VALUE_OPT_FRAGDIR NO_EQUIVALENT
  491. #define FRAGDIR_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  492. #define zFragdirText NULL
  493. #define zFragdir_NAME NULL
  494. #define zFragdir_Name NULL
  495. #endif /* ENABLE_FRAGROUTE */
  496. /*
  497. * Skip_Soft_Errors option description:
  498. */
  499. tSCC zSkip_Soft_ErrorsText[] =
  500. "Skip writing packets with soft errors";
  501. tSCC zSkip_Soft_Errors_NAME[] = "SKIP_SOFT_ERRORS";
  502. tSCC zSkip_Soft_Errors_Name[] = "skip-soft-errors";
  503. #define SKIP_SOFT_ERRORS_FLAGS (OPTST_DISABLED)
  504. /*
  505. * Version option description:
  506. */
  507. tSCC zVersionText[] =
  508. "Print version information";
  509. tSCC zVersion_NAME[] = "VERSION";
  510. tSCC zVersion_Name[] = "version";
  511. #define VERSION_FLAGS (OPTST_DISABLED)
  512. /*
  513. * Less_Help option description:
  514. */
  515. tSCC zLess_HelpText[] =
  516. "Display less usage information and exit";
  517. tSCC zLess_Help_NAME[] = "LESS_HELP";
  518. tSCC zLess_Help_Name[] = "less-help";
  519. #define LESS_HELP_FLAGS (OPTST_DISABLED | OPTST_IMM)
  520. /*
  521. * Help/More_Help option descriptions:
  522. */
  523. tSCC zHelpText[] = "Display usage information and exit";
  524. tSCC zHelp_Name[] = "help";
  525. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  526. tSCC zMore_Help_Name[] = "more-help";
  527. tSCC zSave_OptsText[] = "Save the option state to a config file";
  528. tSCC zSave_Opts_Name[] = "save-opts";
  529. tSCC zLoad_OptsText[] = "Load options from a config file";
  530. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  531. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  532. tSCC zNotLoad_Opts_Pfx[] = "no";
  533. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  534. /*
  535. * Declare option callback procedures
  536. */
  537. #ifdef DEBUG
  538. static tOptProc doOptDbug;
  539. #else /* not DEBUG */
  540. # define doOptDbug NULL
  541. #endif /* def/not DEBUG */
  542. extern tOptProc
  543. optionNumericVal, optionPagedUsage, optionStackArg;
  544. static tOptProc
  545. doOptCachefile, doOptEnet_Vlan_Cfi, doOptEnet_Vlan_Pri,
  546. doOptEnet_Vlan_Tag, doOptLess_Help, doOptMtu,
  547. doOptTos, doOptVersion, doUsageOpt;
  548. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  549. *
  550. * Define the Tcprewrite Option Descriptions.
  551. */
  552. static tOptDesc optDesc[ OPTION_CT ] = {
  553. { /* entry idx, value */ 0, 0,
  554. /* equiv idx, value */ 0, 0,
  555. /* equivalenced to */ NO_EQUIVALENT,
  556. /* min, max, act ct */ 0, 0, 0,
  557. /* opt state flags */ TCPEDIT_FLAGS, 0,
  558. /* last opt argumnt */ { NULL },
  559. /* arg list/cookie */ NULL,
  560. /* must/cannot opts */ NULL, NULL,
  561. /* option proc */ NULL,
  562. /* desc, NAME, name */ zTcpeditText, NULL, NULL,
  563. /* disablement strs */ NULL, NULL },
  564. { /* entry idx, value */ 1, VALUE_OPT_PORTMAP,
  565. /* equiv idx, value */ 1, VALUE_OPT_PORTMAP,
  566. /* equivalenced to */ NO_EQUIVALENT,
  567. /* min, max, act ct */ 0, 1, 0,
  568. /* opt state flags */ PORTMAP_FLAGS, 0,
  569. /* last opt argumnt */ { NULL },
  570. /* arg list/cookie */ NULL,
  571. /* must/cannot opts */ NULL, NULL,
  572. /* option proc */ NULL,
  573. /* desc, NAME, name */ zPortmapText, zPortmap_NAME, zPortmap_Name,
  574. /* disablement strs */ NULL, NULL },
  575. { /* entry idx, value */ 2, VALUE_OPT_SEED,
  576. /* equiv idx, value */ 2, VALUE_OPT_SEED,
  577. /* equivalenced to */ NO_EQUIVALENT,
  578. /* min, max, act ct */ 0, 1, 0,
  579. /* opt state flags */ SEED_FLAGS, 0,
  580. /* last opt argumnt */ { NULL },
  581. /* arg list/cookie */ NULL,
  582. /* must/cannot opts */ NULL, NULL,
  583. /* option proc */ optionNumericVal,
  584. /* desc, NAME, name */ zSeedText, zSeed_NAME, zSeed_Name,
  585. /* disablement strs */ NULL, NULL },
  586. { /* entry idx, value */ 3, VALUE_OPT_PNAT,
  587. /* equiv idx, value */ 3, VALUE_OPT_PNAT,
  588. /* equivalenced to */ NO_EQUIVALENT,
  589. /* min, max, act ct */ 0, 2, 0,
  590. /* opt state flags */ PNAT_FLAGS, 0,
  591. /* last opt argumnt */ { NULL },
  592. /* arg list/cookie */ NULL,
  593. /* must/cannot opts */ NULL, aPnatCantList,
  594. /* option proc */ optionStackArg,
  595. /* desc, NAME, name */ zPnatText, zPnat_NAME, zPnat_Name,
  596. /* disablement strs */ NULL, NULL },
  597. { /* entry idx, value */ 4, VALUE_OPT_SRCIPMAP,
  598. /* equiv idx, value */ 4, VALUE_OPT_SRCIPMAP,
  599. /* equivalenced to */ NO_EQUIVALENT,
  600. /* min, max, act ct */ 0, 1, 0,
  601. /* opt state flags */ SRCIPMAP_FLAGS, 0,
  602. /* last opt argumnt */ { NULL },
  603. /* arg list/cookie */ NULL,
  604. /* must/cannot opts */ NULL, aSrcipmapCantList,
  605. /* option proc */ NULL,
  606. /* desc, NAME, name */ zSrcipmapText, zSrcipmap_NAME, zSrcipmap_Name,
  607. /* disablement strs */ NULL, NULL },
  608. { /* entry idx, value */ 5, VALUE_OPT_DSTIPMAP,
  609. /* equiv idx, value */ 5, VALUE_OPT_DSTIPMAP,
  610. /* equivalenced to */ NO_EQUIVALENT,
  611. /* min, max, act ct */ 0, 1, 0,
  612. /* opt state flags */ DSTIPMAP_FLAGS, 0,
  613. /* last opt argumnt */ { NULL },
  614. /* arg list/cookie */ NULL,
  615. /* must/cannot opts */ NULL, aDstipmapCantList,
  616. /* option proc */ NULL,
  617. /* desc, NAME, name */ zDstipmapText, zDstipmap_NAME, zDstipmap_Name,
  618. /* disablement strs */ NULL, NULL },
  619. { /* entry idx, value */ 6, VALUE_OPT_ENDPOINTS,
  620. /* equiv idx, value */ 6, VALUE_OPT_ENDPOINTS,
  621. /* equivalenced to */ NO_EQUIVALENT,
  622. /* min, max, act ct */ 0, 1, 0,
  623. /* opt state flags */ ENDPOINTS_FLAGS, 0,
  624. /* last opt argumnt */ { NULL },
  625. /* arg list/cookie */ NULL,
  626. /* must/cannot opts */ aEndpointsMustList, NULL,
  627. /* option proc */ NULL,
  628. /* desc, NAME, name */ zEndpointsText, zEndpoints_NAME, zEndpoints_Name,
  629. /* disablement strs */ NULL, NULL },
  630. { /* entry idx, value */ 7, VALUE_OPT_SKIPBROADCAST,
  631. /* equiv idx, value */ 7, VALUE_OPT_SKIPBROADCAST,
  632. /* equivalenced to */ NO_EQUIVALENT,
  633. /* min, max, act ct */ 0, 1, 0,
  634. /* opt state flags */ SKIPBROADCAST_FLAGS, 0,
  635. /* last opt argumnt */ { NULL },
  636. /* arg list/cookie */ NULL,
  637. /* must/cannot opts */ NULL, NULL,
  638. /* option proc */ NULL,
  639. /* desc, NAME, name */ zSkipbroadcastText, zSkipbroadcast_NAME, zSkipbroadcast_Name,
  640. /* disablement strs */ NULL, NULL },
  641. { /* entry idx, value */ 8, VALUE_OPT_FIXCSUM,
  642. /* equiv idx, value */ 8, VALUE_OPT_FIXCSUM,
  643. /* equivalenced to */ NO_EQUIVALENT,
  644. /* min, max, act ct */ 0, 1, 0,
  645. /* opt state flags */ FIXCSUM_FLAGS, 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 */ zFixcsumText, zFixcsum_NAME, zFixcsum_Name,
  651. /* disablement strs */ NULL, NULL },
  652. { /* entry idx, value */ 9, VALUE_OPT_MTU,
  653. /* equiv idx, value */ 9, VALUE_OPT_MTU,
  654. /* equivalenced to */ NO_EQUIVALENT,
  655. /* min, max, act ct */ 0, 1, 0,
  656. /* opt state flags */ MTU_FLAGS, 0,
  657. /* last opt argumnt */ { NULL },
  658. /* arg list/cookie */ NULL,
  659. /* must/cannot opts */ NULL, NULL,
  660. /* option proc */ doOptMtu,
  661. /* desc, NAME, name */ zMtuText, zMtu_NAME, zMtu_Name,
  662. /* disablement strs */ NULL, NULL },
  663. { /* entry idx, value */ 10, VALUE_OPT_MTU_TRUNC,
  664. /* equiv idx, value */ 10, VALUE_OPT_MTU_TRUNC,
  665. /* equivalenced to */ NO_EQUIVALENT,
  666. /* min, max, act ct */ 0, 1, 0,
  667. /* opt state flags */ MTU_TRUNC_FLAGS, 0,
  668. /* last opt argumnt */ { NULL },
  669. /* arg list/cookie */ NULL,
  670. /* must/cannot opts */ NULL, NULL,
  671. /* option proc */ NULL,
  672. /* desc, NAME, name */ zMtu_TruncText, zMtu_Trunc_NAME, zMtu_Trunc_Name,
  673. /* disablement strs */ NULL, NULL },
  674. { /* entry idx, value */ 11, VALUE_OPT_EFCS,
  675. /* equiv idx, value */ 11, VALUE_OPT_EFCS,
  676. /* equivalenced to */ NO_EQUIVALENT,
  677. /* min, max, act ct */ 0, 1, 0,
  678. /* opt state flags */ EFCS_FLAGS, 0,
  679. /* last opt argumnt */ { NULL },
  680. /* arg list/cookie */ NULL,
  681. /* must/cannot opts */ NULL, NULL,
  682. /* option proc */ NULL,
  683. /* desc, NAME, name */ zEfcsText, zEfcs_NAME, zEfcs_Name,
  684. /* disablement strs */ NULL, NULL },
  685. { /* entry idx, value */ 12, VALUE_OPT_TTL,
  686. /* equiv idx, value */ 12, VALUE_OPT_TTL,
  687. /* equivalenced to */ NO_EQUIVALENT,
  688. /* min, max, act ct */ 0, 1, 0,
  689. /* opt state flags */ TTL_FLAGS, 0,
  690. /* last opt argumnt */ { NULL },
  691. /* arg list/cookie */ NULL,
  692. /* must/cannot opts */ NULL, NULL,
  693. /* option proc */ NULL,
  694. /* desc, NAME, name */ zTtlText, zTtl_NAME, zTtl_Name,
  695. /* disablement strs */ NULL, NULL },
  696. { /* entry idx, value */ 13, VALUE_OPT_TOS,
  697. /* equiv idx, value */ 13, VALUE_OPT_TOS,
  698. /* equivalenced to */ NO_EQUIVALENT,
  699. /* min, max, act ct */ 0, 1, 0,
  700. /* opt state flags */ TOS_FLAGS, 0,
  701. /* last opt argumnt */ { NULL },
  702. /* arg list/cookie */ NULL,
  703. /* must/cannot opts */ NULL, NULL,
  704. /* option proc */ doOptTos,
  705. /* desc, NAME, name */ zTosText, zTos_NAME, zTos_Name,
  706. /* disablement strs */ NULL, NULL },
  707. { /* entry idx, value */ 14, VALUE_OPT_FIXLEN,
  708. /* equiv idx, value */ 14, VALUE_OPT_FIXLEN,
  709. /* equivalenced to */ NO_EQUIVALENT,
  710. /* min, max, act ct */ 0, 1, 0,
  711. /* opt state flags */ FIXLEN_FLAGS, 0,
  712. /* last opt argumnt */ { NULL },
  713. /* arg list/cookie */ NULL,
  714. /* must/cannot opts */ NULL, NULL,
  715. /* option proc */ NULL,
  716. /* desc, NAME, name */ zFixlenText, zFixlen_NAME, zFixlen_Name,
  717. /* disablement strs */ NULL, NULL },
  718. { /* entry idx, value */ 15, VALUE_OPT_SKIPL2BROADCAST,
  719. /* equiv idx, value */ 15, VALUE_OPT_SKIPL2BROADCAST,
  720. /* equivalenced to */ NO_EQUIVALENT,
  721. /* min, max, act ct */ 0, 1, 0,
  722. /* opt state flags */ SKIPL2BROADCAST_FLAGS, 0,
  723. /* last opt argumnt */ { NULL },
  724. /* arg list/cookie */ NULL,
  725. /* must/cannot opts */ NULL, NULL,
  726. /* option proc */ NULL,
  727. /* desc, NAME, name */ zSkipl2broadcastText, zSkipl2broadcast_NAME, zSkipl2broadcast_Name,
  728. /* disablement strs */ NULL, NULL },
  729. { /* entry idx, value */ 16, VALUE_OPT_DLT,
  730. /* equiv idx, value */ 16, VALUE_OPT_DLT,
  731. /* equivalenced to */ NO_EQUIVALENT,
  732. /* min, max, act ct */ 0, 1, 0,
  733. /* opt state flags */ DLT_FLAGS, 0,
  734. /* last opt argumnt */ { NULL },
  735. /* arg list/cookie */ NULL,
  736. /* must/cannot opts */ NULL, NULL,
  737. /* option proc */ NULL,
  738. /* desc, NAME, name */ zDltText, zDlt_NAME, zDlt_Name,
  739. /* disablement strs */ NULL, NULL },
  740. { /* entry idx, value */ 17, VALUE_OPT_ENET_DMAC,
  741. /* equiv idx, value */ 17, VALUE_OPT_ENET_DMAC,
  742. /* equivalenced to */ NO_EQUIVALENT,
  743. /* min, max, act ct */ 0, 1, 0,
  744. /* opt state flags */ ENET_DMAC_FLAGS, 0,
  745. /* last opt argumnt */ { NULL },
  746. /* arg list/cookie */ NULL,
  747. /* must/cannot opts */ NULL, NULL,
  748. /* option proc */ NULL,
  749. /* desc, NAME, name */ zEnet_DmacText, zEnet_Dmac_NAME, zEnet_Dmac_Name,
  750. /* disablement strs */ NULL, NULL },
  751. { /* entry idx, value */ 18, VALUE_OPT_ENET_SMAC,
  752. /* equiv idx, value */ 18, VALUE_OPT_ENET_SMAC,
  753. /* equivalenced to */ NO_EQUIVALENT,
  754. /* min, max, act ct */ 0, 1, 0,
  755. /* opt state flags */ ENET_SMAC_FLAGS, 0,
  756. /* last opt argumnt */ { NULL },
  757. /* arg list/cookie */ NULL,
  758. /* must/cannot opts */ NULL, NULL,
  759. /* option proc */ NULL,
  760. /* desc, NAME, name */ zEnet_SmacText, zEnet_Smac_NAME, zEnet_Smac_Name,
  761. /* disablement strs */ NULL, NULL },
  762. { /* entry idx, value */ 19, VALUE_OPT_ENET_VLAN,
  763. /* equiv idx, value */ 19, VALUE_OPT_ENET_VLAN,
  764. /* equivalenced to */ NO_EQUIVALENT,
  765. /* min, max, act ct */ 0, 1, 0,
  766. /* opt state flags */ ENET_VLAN_FLAGS, 0,
  767. /* last opt argumnt */ { NULL },
  768. /* arg list/cookie */ NULL,
  769. /* must/cannot opts */ NULL, NULL,
  770. /* option proc */ NULL,
  771. /* desc, NAME, name */ zEnet_VlanText, zEnet_Vlan_NAME, zEnet_Vlan_Name,
  772. /* disablement strs */ NULL, NULL },
  773. { /* entry idx, value */ 20, VALUE_OPT_ENET_VLAN_TAG,
  774. /* equiv idx, value */ 20, VALUE_OPT_ENET_VLAN_TAG,
  775. /* equivalenced to */ NO_EQUIVALENT,
  776. /* min, max, act ct */ 0, 1, 0,
  777. /* opt state flags */ ENET_VLAN_TAG_FLAGS, 0,
  778. /* last opt argumnt */ { NULL },
  779. /* arg list/cookie */ NULL,
  780. /* must/cannot opts */ aEnet_Vlan_TagMustList, NULL,
  781. /* option proc */ doOptEnet_Vlan_Tag,
  782. /* desc, NAME, name */ zEnet_Vlan_TagText, zEnet_Vlan_Tag_NAME, zEnet_Vlan_Tag_Name,
  783. /* disablement strs */ NULL, NULL },
  784. { /* entry idx, value */ 21, VALUE_OPT_ENET_VLAN_CFI,
  785. /* equiv idx, value */ 21, VALUE_OPT_ENET_VLAN_CFI,
  786. /* equivalenced to */ NO_EQUIVALENT,
  787. /* min, max, act ct */ 0, 1, 0,
  788. /* opt state flags */ ENET_VLAN_CFI_FLAGS, 0,
  789. /* last opt argumnt */ { NULL },
  790. /* arg list/cookie */ NULL,
  791. /* must/cannot opts */ aEnet_Vlan_CfiMustList, NULL,
  792. /* option proc */ doOptEnet_Vlan_Cfi,
  793. /* desc, NAME, name */ zEnet_Vlan_CfiText, zEnet_Vlan_Cfi_NAME, zEnet_Vlan_Cfi_Name,
  794. /* disablement strs */ NULL, NULL },
  795. { /* entry idx, value */ 22, VALUE_OPT_ENET_VLAN_PRI,
  796. /* equiv idx, value */ 22, VALUE_OPT_ENET_VLAN_PRI,
  797. /* equivalenced to */ NO_EQUIVALENT,
  798. /* min, max, act ct */ 0, 1, 0,
  799. /* opt state flags */ ENET_VLAN_PRI_FLAGS, 0,
  800. /* last opt argumnt */ { NULL },
  801. /* arg list/cookie */ NULL,
  802. /* must/cannot opts */ aEnet_Vlan_PriMustList, NULL,
  803. /* option proc */ doOptEnet_Vlan_Pri,
  804. /* desc, NAME, name */ zEnet_Vlan_PriText, zEnet_Vlan_Pri_NAME, zEnet_Vlan_Pri_Name,
  805. /* disablement strs */ NULL, NULL },
  806. { /* entry idx, value */ 23, VALUE_OPT_HDLC_CONTROL,
  807. /* equiv idx, value */ 23, VALUE_OPT_HDLC_CONTROL,
  808. /* equivalenced to */ NO_EQUIVALENT,
  809. /* min, max, act ct */ 0, 1, 0,
  810. /* opt state flags */ HDLC_CONTROL_FLAGS, 0,
  811. /* last opt argumnt */ { NULL },
  812. /* arg list/cookie */ NULL,
  813. /* must/cannot opts */ NULL, NULL,
  814. /* option proc */ optionNumericVal,
  815. /* desc, NAME, name */ zHdlc_ControlText, zHdlc_Control_NAME, zHdlc_Control_Name,
  816. /* disablement strs */ NULL, NULL },
  817. { /* entry idx, value */ 24, VALUE_OPT_HDLC_ADDRESS,
  818. /* equiv idx, value */ 24, VALUE_OPT_HDLC_ADDRESS,
  819. /* equivalenced to */ NO_EQUIVALENT,
  820. /* min, max, act ct */ 0, 1, 0,
  821. /* opt state flags */ HDLC_ADDRESS_FLAGS, 0,
  822. /* last opt argumnt */ { NULL },
  823. /* arg list/cookie */ NULL,
  824. /* must/cannot opts */ NULL, NULL,
  825. /* option proc */ optionNumericVal,
  826. /* desc, NAME, name */ zHdlc_AddressText, zHdlc_Address_NAME, zHdlc_Address_Name,
  827. /* disablement strs */ NULL, NULL },
  828. { /* entry idx, value */ 25, VALUE_OPT_USER_DLT,
  829. /* equiv idx, value */ 25, VALUE_OPT_USER_DLT,
  830. /* equivalenced to */ NO_EQUIVALENT,
  831. /* min, max, act ct */ 0, 1, 0,
  832. /* opt state flags */ USER_DLT_FLAGS, 0,
  833. /* last opt argumnt */ { NULL },
  834. /* arg list/cookie */ NULL,
  835. /* must/cannot opts */ NULL, NULL,
  836. /* option proc */ optionNumericVal,
  837. /* desc, NAME, name */ zUser_DltText, zUser_Dlt_NAME, zUser_Dlt_Name,
  838. /* disablement strs */ NULL, NULL },
  839. { /* entry idx, value */ 26, VALUE_OPT_USER_DLINK,
  840. /* equiv idx, value */ 26, VALUE_OPT_USER_DLINK,
  841. /* equivalenced to */ NO_EQUIVALENT,
  842. /* min, max, act ct */ 0, 2, 0,
  843. /* opt state flags */ USER_DLINK_FLAGS, 0,
  844. /* last opt argumnt */ { NULL },
  845. /* arg list/cookie */ NULL,
  846. /* must/cannot opts */ NULL, NULL,
  847. /* option proc */ optionStackArg,
  848. /* desc, NAME, name */ zUser_DlinkText, zUser_Dlink_NAME, zUser_Dlink_Name,
  849. /* disablement strs */ NULL, NULL },
  850. { /* entry idx, value */ 27, VALUE_OPT_DBUG,
  851. /* equiv idx, value */ 27, VALUE_OPT_DBUG,
  852. /* equivalenced to */ NO_EQUIVALENT,
  853. /* min, max, act ct */ 0, 1, 0,
  854. /* opt state flags */ DBUG_FLAGS, 0,
  855. /* last opt argumnt */ { zDbugDefaultArg },
  856. /* arg list/cookie */ NULL,
  857. /* must/cannot opts */ NULL, NULL,
  858. /* option proc */ doOptDbug,
  859. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  860. /* disablement strs */ NULL, NULL },
  861. { /* entry idx, value */ 28, VALUE_OPT_INFILE,
  862. /* equiv idx, value */ 28, VALUE_OPT_INFILE,
  863. /* equivalenced to */ NO_EQUIVALENT,
  864. /* min, max, act ct */ 1, 1, 0,
  865. /* opt state flags */ INFILE_FLAGS, 0,
  866. /* last opt argumnt */ { NULL },
  867. /* arg list/cookie */ NULL,
  868. /* must/cannot opts */ NULL, NULL,
  869. /* option proc */ NULL,
  870. /* desc, NAME, name */ zInfileText, zInfile_NAME, zInfile_Name,
  871. /* disablement strs */ NULL, NULL },
  872. { /* entry idx, value */ 29, VALUE_OPT_OUTFILE,
  873. /* equiv idx, value */ 29, VALUE_OPT_OUTFILE,
  874. /* equivalenced to */ NO_EQUIVALENT,
  875. /* min, max, act ct */ 1, 1, 0,
  876. /* opt state flags */ OUTFILE_FLAGS, 0,
  877. /* last opt argumnt */ { NULL },
  878. /* arg list/cookie */ NULL,
  879. /* must/cannot opts */ NULL, NULL,
  880. /* option proc */ NULL,
  881. /* desc, NAME, name */ zOutfileText, zOutfile_NAME, zOutfile_Name,
  882. /* disablement strs */ NULL, NULL },
  883. { /* entry idx, value */ 30, VALUE_OPT_CACHEFILE,
  884. /* equiv idx, value */ 30, VALUE_OPT_CACHEFILE,
  885. /* equivalenced to */ NO_EQUIVALENT,
  886. /* min, max, act ct */ 0, 1, 0,
  887. /* opt state flags */ CACHEFILE_FLAGS, 0,
  888. /* last opt argumnt */ { NULL },
  889. /* arg list/cookie */ NULL,
  890. /* must/cannot opts */ NULL, NULL,
  891. /* option proc */ doOptCachefile,
  892. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  893. /* disablement strs */ NULL, NULL },
  894. { /* entry idx, value */ 31, VALUE_OPT_VERBOSE,
  895. /* equiv idx, value */ 31, VALUE_OPT_VERBOSE,
  896. /* equivalenced to */ NO_EQUIVALENT,
  897. /* min, max, act ct */ 0, 1, 0,
  898. /* opt state flags */ VERBOSE_FLAGS, 0,
  899. /* last opt argumnt */ { NULL },
  900. /* arg list/cookie */ NULL,
  901. /* must/cannot opts */ NULL, NULL,
  902. /* option proc */ NULL,
  903. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  904. /* disablement strs */ NULL, NULL },
  905. { /* entry idx, value */ 32, VALUE_OPT_DECODE,
  906. /* equiv idx, value */ 32, VALUE_OPT_DECODE,
  907. /* equivalenced to */ NO_EQUIVALENT,
  908. /* min, max, act ct */ 0, 1, 0,
  909. /* opt state flags */ DECODE_FLAGS, 0,
  910. /* last opt argumnt */ { NULL },
  911. /* arg list/cookie */ NULL,
  912. /* must/cannot opts */ aDecodeMustList, NULL,
  913. /* option proc */ NULL,
  914. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  915. /* disablement strs */ NULL, NULL },
  916. { /* entry idx, value */ 33, VALUE_OPT_FRAGROUTE,
  917. /* equiv idx, value */ 33, VALUE_OPT_FRAGROUTE,
  918. /* equivalenced to */ NO_EQUIVALENT,
  919. /* min, max, act ct */ 0, 1, 0,
  920. /* opt state flags */ FRAGROUTE_FLAGS, 0,
  921. /* last opt argumnt */ { NULL },
  922. /* arg list/cookie */ NULL,
  923. /* must/cannot opts */ NULL, NULL,
  924. /* option proc */ NULL,
  925. /* desc, NAME, name */ zFragrouteText, zFragroute_NAME, zFragroute_Name,
  926. /* disablement strs */ NULL, NULL },
  927. { /* entry idx, value */ 34, VALUE_OPT_FRAGDIR,
  928. /* equiv idx, value */ 34, VALUE_OPT_FRAGDIR,
  929. /* equivalenced to */ NO_EQUIVALENT,
  930. /* min, max, act ct */ 0, 1, 0,
  931. /* opt state flags */ FRAGDIR_FLAGS, 0,
  932. /* last opt argumnt */ { NULL },
  933. /* arg list/cookie */ NULL,
  934. /* must/cannot opts */ NULL, NULL,
  935. /* option proc */ NULL,
  936. /* desc, NAME, name */ zFragdirText, zFragdir_NAME, zFragdir_Name,
  937. /* disablement strs */ NULL, NULL },
  938. { /* entry idx, value */ 35, VALUE_OPT_SKIP_SOFT_ERRORS,
  939. /* equiv idx, value */ 35, VALUE_OPT_SKIP_SOFT_ERRORS,
  940. /* equivalenced to */ NO_EQUIVALENT,
  941. /* min, max, act ct */ 0, 1, 0,
  942. /* opt state flags */ SKIP_SOFT_ERRORS_FLAGS, 0,
  943. /* last opt argumnt */ { NULL },
  944. /* arg list/cookie */ NULL,
  945. /* must/cannot opts */ NULL, NULL,
  946. /* option proc */ NULL,
  947. /* desc, NAME, name */ zSkip_Soft_ErrorsText, zSkip_Soft_Errors_NAME, zSkip_Soft_Errors_Name,
  948. /* disablement strs */ NULL, NULL },
  949. { /* entry idx, value */ 36, VALUE_OPT_VERSION,
  950. /* equiv idx, value */ 36, VALUE_OPT_VERSION,
  951. /* equivalenced to */ NO_EQUIVALENT,
  952. /* min, max, act ct */ 0, 1, 0,
  953. /* opt state flags */ VERSION_FLAGS, 0,
  954. /* last opt argumnt */ { NULL },
  955. /* arg list/cookie */ NULL,
  956. /* must/cannot opts */ NULL, NULL,
  957. /* option proc */ doOptVersion,
  958. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  959. /* disablement strs */ NULL, NULL },
  960. { /* entry idx, value */ 37, VALUE_OPT_LESS_HELP,
  961. /* equiv idx, value */ 37, VALUE_OPT_LESS_HELP,
  962. /* equivalenced to */ NO_EQUIVALENT,
  963. /* min, max, act ct */ 0, 1, 0,
  964. /* opt state flags */ LESS_HELP_FLAGS, 0,
  965. /* last opt argumnt */ { NULL },
  966. /* arg list/cookie */ NULL,
  967. /* must/cannot opts */ NULL, NULL,
  968. /* option proc */ doOptLess_Help,
  969. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  970. /* disablement strs */ NULL, NULL },
  971. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  972. /* equiv idx value */ NO_EQUIVALENT, 0,
  973. /* equivalenced to */ NO_EQUIVALENT,
  974. /* min, max, act ct */ 0, 1, 0,
  975. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  976. /* last opt argumnt */ { NULL },
  977. /* arg list/cookie */ NULL,
  978. /* must/cannot opts */ NULL, NULL,
  979. /* option proc */ doUsageOpt,
  980. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  981. /* disablement strs */ NULL, NULL },
  982. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  983. /* equiv idx value */ NO_EQUIVALENT, 0,
  984. /* equivalenced to */ NO_EQUIVALENT,
  985. /* min, max, act ct */ 0, 1, 0,
  986. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  987. /* last opt argumnt */ { NULL },
  988. /* arg list/cookie */ NULL,
  989. /* must/cannot opts */ NULL, NULL,
  990. /* option proc */ optionPagedUsage,
  991. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  992. /* disablement strs */ NULL, NULL },
  993. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  994. /* equiv idx value */ NO_EQUIVALENT, 0,
  995. /* equivalenced to */ NO_EQUIVALENT,
  996. /* min, max, act ct */ 0, 1, 0,
  997. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  998. | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
  999. /* last opt argumnt */ { NULL },
  1000. /* arg list/cookie */ NULL,
  1001. /* must/cannot opts */ NULL, NULL,
  1002. /* option proc */ NULL,
  1003. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  1004. /* disablement strs */ NULL, NULL },
  1005. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  1006. /* equiv idx value */ NO_EQUIVALENT, 0,
  1007. /* equivalenced to */ NO_EQUIVALENT,
  1008. /* min, max, act ct */ 0, NOLIMIT, 0,
  1009. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  1010. | OPTST_DISABLE_IMM, 0,
  1011. /* last opt argumnt */ { NULL },
  1012. /* arg list/cookie */ NULL,
  1013. /* must/cannot opts */ NULL, NULL,
  1014. /* option proc */ optionLoadOpt,
  1015. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  1016. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  1017. };
  1018. tOptDesc * const tcpedit_tcpedit_optDesc_p = optDesc + 0;
  1019. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1020. *
  1021. * Define the Tcprewrite Option Environment
  1022. */
  1023. tSCC zPROGNAME[] = "TCPREWRITE";
  1024. tSCC zUsageTitle[] =
  1025. "tcprewrite (tcprewrite) - Rewrite the packets in a pcap file.\n\
  1026. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  1027. tSCC zRcName[] = ".tcprewriterc";
  1028. tSCC* apzHomeList[] = {
  1029. "$$/",
  1030. NULL };
  1031. #define zBugsAddr NULL
  1032. #define zExplain NULL
  1033. tSCC zDetail[] = "\n\
  1034. Tcprewrite is a tool to rewrite packets stored in ``pcap(3)'' file format, \n\
  1035. such as crated by tools such as ``tcpdump(1)'' and ``ethereal(1)''. \n\
  1036. Once a pcap file has had it's packets rewritten, they can be replayed back \n\
  1037. out on the network using ``tcpreplay(1)''.\n\n\
  1038. tcprewrite currently supports reading the following DLT types:\n\n\n\
  1039. ``DLT_C_HDLC'' aka Cisco HDLC\n\n\n\
  1040. ``DLT_EN10MB'' aka Ethernet\n\n\n\
  1041. ``DLT_LINUX_SLL'' aka Linux Cooked Socket\n\n\n\
  1042. ``DLT_RAW'' aka RAW IP\n\n\n\
  1043. ``DLT_NULL'' aka BSD Loopback\n\n\n\
  1044. ``DLT_LOOP'' aka OpenBSD Loopback\n\n\n\
  1045. ``DLT_IEEE802_11'' aka 802.11a/b/g\n\n\n\
  1046. ``DLT_IEEE802_11_RADIO'' aka 802.11a/b/g with Radiotap headers\n\n\
  1047. Please see the --dlt option for supported DLT types for writing.\n\n\
  1048. The packet editing features of tcprewrite which distinguish between \"client\"\n\
  1049. and \"server\" traffic requires a tcpprep(1) cache file.\n\n\
  1050. For more details, please see the Tcpreplay Manual at:\n\
  1051. http://tcpreplay.synfin.net/trac/wiki/manual\n";
  1052. #define zFullVersion NULL
  1053. /* extracted from /usr/local/share/autogen/optcode.tpl near line 496 */
  1054. #if defined(ENABLE_NLS)
  1055. # define OPTPROC_BASE OPTPROC_TRANSLATE
  1056. static tOptionXlateProc translate_option_strings;
  1057. #else
  1058. # define OPTPROC_BASE OPTPROC_NONE
  1059. # define translate_option_strings NULL
  1060. #endif /* ENABLE_NLS */
  1061. #define tcprewrite_full_usage NULL
  1062. #define tcprewrite_short_usage NULL
  1063. tOptions tcprewriteOptions = {
  1064. OPTIONS_STRUCT_VERSION,
  1065. 0, NULL, /* original argc + argv */
  1066. ( OPTPROC_BASE
  1067. + OPTPROC_ERRSTOP
  1068. + OPTPROC_SHORTOPT
  1069. + OPTPROC_LONGOPT
  1070. + OPTPROC_NO_REQ_OPT
  1071. + OPTPROC_NO_ARGS
  1072. + OPTPROC_GNUUSAGE
  1073. + OPTPROC_HAS_IMMED ),
  1074. 0, NULL, /* current option index, current option */
  1075. NULL, NULL, zPROGNAME,
  1076. zRcName, zCopyright, zCopyrightNotice,
  1077. zFullVersion, apzHomeList, zUsageTitle,
  1078. zExplain, zDetail, optDesc,
  1079. zBugsAddr, /* address to send bugs to */
  1080. NULL, NULL, /* extensions/saved state */
  1081. optionUsage, /* usage procedure */
  1082. translate_option_strings, /* translation procedure */
  1083. /*
  1084. * Indexes to special options
  1085. */
  1086. { INDEX_OPT_MORE_HELP, /* more-help option index */
  1087. INDEX_OPT_SAVE_OPTS, /* save option index */
  1088. NO_EQUIVALENT, /* '-#' option index */
  1089. 9 /* index of default opt */
  1090. },
  1091. 42 /* full option count */, 38 /* user option count */,
  1092. tcprewrite_full_usage, tcprewrite_short_usage,
  1093. NULL, NULL
  1094. };
  1095. /*
  1096. * Create the static procedure(s) declared above.
  1097. */
  1098. static void
  1099. doUsageOpt(
  1100. tOptions* pOptions,
  1101. tOptDesc* pOptDesc )
  1102. {
  1103. USAGE( EXIT_SUCCESS );
  1104. }
  1105. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1106. *
  1107. * For the mtu option.
  1108. */
  1109. static void
  1110. doOptMtu(tOptions* pOptions, tOptDesc* pOptDesc)
  1111. {
  1112. static const struct {long const rmin, rmax;} rng[1] = {
  1113. { 1, MAXPACKET } };
  1114. long val;
  1115. int ix;
  1116. char * pzEnd;
  1117. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1118. goto emit_ranges;
  1119. errno = 0;
  1120. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1121. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1122. goto bad_value;
  1123. if (*pzEnd != '\0')
  1124. goto bad_value;
  1125. for (ix = 0; ix < 1; ix++) {
  1126. if (val < rng[ix].rmin)
  1127. continue; /* ranges need not be ordered. */
  1128. if (val == rng[ix].rmin)
  1129. goto valid_return;
  1130. if (rng[ix].rmax == LONG_MIN)
  1131. continue;
  1132. if (val <= rng[ix].rmax)
  1133. goto valid_return;
  1134. }
  1135. bad_value:
  1136. option_usage_fp = stderr;
  1137. emit_ranges:
  1138. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1139. return;
  1140. valid_return:
  1141. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1142. free((void *)pOptDesc->optArg.argString);
  1143. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1144. }
  1145. pOptDesc->optArg.argInt = val;
  1146. }
  1147. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1148. *
  1149. * For the tos option.
  1150. */
  1151. static void
  1152. doOptTos(tOptions* pOptions, tOptDesc* pOptDesc)
  1153. {
  1154. static const struct {long const rmin, rmax;} rng[1] = {
  1155. { 0, 255 } };
  1156. long val;
  1157. int ix;
  1158. char * pzEnd;
  1159. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1160. goto emit_ranges;
  1161. errno = 0;
  1162. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1163. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1164. goto bad_value;
  1165. if (*pzEnd != '\0')
  1166. goto bad_value;
  1167. for (ix = 0; ix < 1; ix++) {
  1168. if (val < rng[ix].rmin)
  1169. continue; /* ranges need not be ordered. */
  1170. if (val == rng[ix].rmin)
  1171. goto valid_return;
  1172. if (rng[ix].rmax == LONG_MIN)
  1173. continue;
  1174. if (val <= rng[ix].rmax)
  1175. goto valid_return;
  1176. }
  1177. bad_value:
  1178. option_usage_fp = stderr;
  1179. emit_ranges:
  1180. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1181. return;
  1182. valid_return:
  1183. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1184. free((void *)pOptDesc->optArg.argString);
  1185. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1186. }
  1187. pOptDesc->optArg.argInt = val;
  1188. }
  1189. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1190. *
  1191. * For the enet-vlan-tag option.
  1192. */
  1193. static void
  1194. doOptEnet_Vlan_Tag(tOptions* pOptions, tOptDesc* pOptDesc)
  1195. {
  1196. static const struct {long const rmin, rmax;} rng[1] = {
  1197. { 0, 4095 } };
  1198. long val;
  1199. int ix;
  1200. char * pzEnd;
  1201. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1202. goto emit_ranges;
  1203. errno = 0;
  1204. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1205. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1206. goto bad_value;
  1207. if (*pzEnd != '\0')
  1208. goto bad_value;
  1209. for (ix = 0; ix < 1; ix++) {
  1210. if (val < rng[ix].rmin)
  1211. continue; /* ranges need not be ordered. */
  1212. if (val == rng[ix].rmin)
  1213. goto valid_return;
  1214. if (rng[ix].rmax == LONG_MIN)
  1215. continue;
  1216. if (val <= rng[ix].rmax)
  1217. goto valid_return;
  1218. }
  1219. bad_value:
  1220. option_usage_fp = stderr;
  1221. emit_ranges:
  1222. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1223. return;
  1224. valid_return:
  1225. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1226. free((void *)pOptDesc->optArg.argString);
  1227. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1228. }
  1229. pOptDesc->optArg.argInt = val;
  1230. }
  1231. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1232. *
  1233. * For the enet-vlan-cfi option.
  1234. */
  1235. static void
  1236. doOptEnet_Vlan_Cfi(tOptions* pOptions, tOptDesc* pOptDesc)
  1237. {
  1238. static const struct {long const rmin, rmax;} rng[1] = {
  1239. { 0, 1 } };
  1240. long val;
  1241. int ix;
  1242. char * pzEnd;
  1243. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1244. goto emit_ranges;
  1245. errno = 0;
  1246. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1247. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1248. goto bad_value;
  1249. if (*pzEnd != '\0')
  1250. goto bad_value;
  1251. for (ix = 0; ix < 1; ix++) {
  1252. if (val < rng[ix].rmin)
  1253. continue; /* ranges need not be ordered. */
  1254. if (val == rng[ix].rmin)
  1255. goto valid_return;
  1256. if (rng[ix].rmax == LONG_MIN)
  1257. continue;
  1258. if (val <= rng[ix].rmax)
  1259. goto valid_return;
  1260. }
  1261. bad_value:
  1262. option_usage_fp = stderr;
  1263. emit_ranges:
  1264. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1265. return;
  1266. valid_return:
  1267. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1268. free((void *)pOptDesc->optArg.argString);
  1269. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1270. }
  1271. pOptDesc->optArg.argInt = val;
  1272. }
  1273. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1274. *
  1275. * For the enet-vlan-pri option.
  1276. */
  1277. static void
  1278. doOptEnet_Vlan_Pri(tOptions* pOptions, tOptDesc* pOptDesc)
  1279. {
  1280. static const struct {long const rmin, rmax;} rng[1] = {
  1281. { 0, 7 } };
  1282. long val;
  1283. int ix;
  1284. char * pzEnd;
  1285. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1286. goto emit_ranges;
  1287. errno = 0;
  1288. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1289. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1290. goto bad_value;
  1291. if (*pzEnd != '\0')
  1292. goto bad_value;
  1293. for (ix = 0; ix < 1; ix++) {
  1294. if (val < rng[ix].rmin)
  1295. continue; /* ranges need not be ordered. */
  1296. if (val == rng[ix].rmin)
  1297. goto valid_return;
  1298. if (rng[ix].rmax == LONG_MIN)
  1299. continue;
  1300. if (val <= rng[ix].rmax)
  1301. goto valid_return;
  1302. }
  1303. bad_value:
  1304. option_usage_fp = stderr;
  1305. emit_ranges:
  1306. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1307. return;
  1308. valid_return:
  1309. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1310. free((void *)pOptDesc->optArg.argString);
  1311. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1312. }
  1313. pOptDesc->optArg.argInt = val;
  1314. }
  1315. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1316. *
  1317. * For the dbug option, when DEBUG is #define-d.
  1318. */
  1319. #ifdef DEBUG
  1320. static void
  1321. doOptDbug(tOptions* pOptions, tOptDesc* pOptDesc)
  1322. {
  1323. static const struct {long const rmin, rmax;} rng[1] = {
  1324. { 0, 5 } };
  1325. long val;
  1326. int ix;
  1327. char * pzEnd;
  1328. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1329. goto emit_ranges;
  1330. errno = 0;
  1331. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1332. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1333. goto bad_value;
  1334. if (*pzEnd != '\0')
  1335. goto bad_value;
  1336. for (ix = 0; ix < 1; ix++) {
  1337. if (val < rng[ix].rmin)
  1338. continue; /* ranges need not be ordered. */
  1339. if (val == rng[ix].rmin)
  1340. goto valid_return;
  1341. if (rng[ix].rmax == LONG_MIN)
  1342. continue;
  1343. if (val <= rng[ix].rmax)
  1344. goto valid_return;
  1345. }
  1346. bad_value:
  1347. option_usage_fp = stderr;
  1348. emit_ranges:
  1349. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1350. return;
  1351. valid_return:
  1352. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1353. free((void *)pOptDesc->optArg.argString);
  1354. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1355. }
  1356. pOptDesc->optArg.argInt = val;
  1357. }
  1358. #endif /* defined DEBUG */
  1359. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1360. *
  1361. * For the cachefile option.
  1362. */
  1363. static void
  1364. doOptCachefile(tOptions* pOptions, tOptDesc* pOptDesc)
  1365. {
  1366. /* extracted from tcprewrite_opts.def, line 128 */
  1367. options.cache_packets =
  1368. read_cache(&options.cachedata, OPT_ARG(CACHEFILE), &options.comment);
  1369. }
  1370. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1371. *
  1372. * For the version option.
  1373. */
  1374. static void
  1375. doOptVersion(tOptions* pOptions, tOptDesc* pOptDesc)
  1376. {
  1377. /* extracted from tcprewrite_opts.def, line 217 */
  1378. fprintf(stderr, "tcprewrite version: %s (build %s)", VERSION, svn_version());
  1379. #ifdef DEBUG
  1380. fprintf(stderr, " (debug)");
  1381. #endif
  1382. fprintf(stderr, "\n");
  1383. fprintf(stderr, "Copyright 2001-2009 by Aaron Turner <aturner at synfin dot net>\n");
  1384. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  1385. #ifdef HAVE_LIBDNET
  1386. fprintf(stderr, "Compiled against libdnet: %s\n", LIBDNET_VERSION);
  1387. #else
  1388. fprintf(stderr, "Not compiled with libdnet.\n");
  1389. #endif
  1390. #ifdef HAVE_WINPCAP
  1391. fprintf(stderr, "Compiled against winpcap: %s\n", get_pcap_version());
  1392. #else
  1393. fprintf(stderr, "Compiled against libpcap: %s\n", get_pcap_version());
  1394. #endif
  1395. #ifdef ENABLE_64BITS
  1396. fprintf(stderr, "64 bit packet counters: enabled\n");
  1397. #else
  1398. fprintf(stderr, "64 bit packet counters: disabled\n");
  1399. #endif
  1400. #ifdef ENABLE_VERBOSE
  1401. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  1402. #else
  1403. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  1404. #endif
  1405. #ifdef ENABLE_FRAGROUTE
  1406. fprintf(stderr, "Fragroute engine: enabled\n");
  1407. #else
  1408. fprintf(stderr, "Fragroute engine: disabled\n");
  1409. #endif
  1410. exit(0);
  1411. }
  1412. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1413. *
  1414. * For the less-help option.
  1415. */
  1416. static void
  1417. doOptLess_Help(tOptions* pOptions, tOptDesc* pOptDesc)
  1418. {
  1419. /* extracted from tcprewrite_opts.def, line 262 */
  1420. USAGE(EXIT_FAILURE);
  1421. }
  1422. /* extracted from /usr/local/share/autogen/optcode.tpl near line 629 */
  1423. #if ENABLE_NLS
  1424. #include <stdio.h>
  1425. #include <stdlib.h>
  1426. #include <string.h>
  1427. #include <unistd.h>
  1428. #include <autoopts/usage-txt.h>
  1429. static char* AO_gettext( char const* pz );
  1430. static void coerce_it(void** s);
  1431. static char*
  1432. AO_gettext( char const* pz )
  1433. {
  1434. char* pzRes;
  1435. if (pz == NULL)
  1436. return NULL;
  1437. pzRes = _(pz);
  1438. if (pzRes == pz)
  1439. return pzRes;
  1440. pzRes = strdup( pzRes );
  1441. if (pzRes == NULL) {
  1442. fputs( _("No memory for duping translated strings\n"), stderr );
  1443. exit( EXIT_FAILURE );
  1444. }
  1445. return pzRes;
  1446. }
  1447. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  1448. #define COERSION(_f) \
  1449. coerce_it((void*)&(tcprewriteOptions._f))
  1450. /*
  1451. * This invokes the translation code (e.g. gettext(3)).
  1452. */
  1453. static void
  1454. translate_option_strings( void )
  1455. {
  1456. /*
  1457. * Guard against re-translation. It won't work. The strings will have
  1458. * been changed by the first pass through this code. One shot only.
  1459. */
  1460. if (option_usage_text.field_ct != 0) {
  1461. /*
  1462. * Do the translations. The first pointer follows the field count
  1463. * field. The field count field is the size of a pointer.
  1464. */
  1465. tOptDesc* pOD = tcprewriteOptions.pOptDesc;
  1466. char** ppz = (char**)(void*)&(option_usage_text);
  1467. int ix = option_usage_text.field_ct;
  1468. do {
  1469. ppz++;
  1470. *ppz = AO_gettext(*ppz);
  1471. } while (--ix > 0);
  1472. COERSION(pzCopyright);
  1473. COERSION(pzCopyNotice);
  1474. COERSION(pzFullVersion);
  1475. COERSION(pzUsageTitle);
  1476. COERSION(pzExplain);
  1477. COERSION(pzDetail);
  1478. option_usage_text.field_ct = 0;
  1479. for (ix = tcprewriteOptions.optCt; ix > 0; ix--, pOD++)
  1480. coerce_it((void*)&(pOD->pzText));
  1481. }
  1482. if ((tcprewriteOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
  1483. tOptDesc* pOD = tcprewriteOptions.pOptDesc;
  1484. int ix;
  1485. for (ix = tcprewriteOptions.optCt; ix > 0; ix--, pOD++) {
  1486. coerce_it((void*)&(pOD->pz_Name));
  1487. coerce_it((void*)&(pOD->pz_DisableName));
  1488. coerce_it((void*)&(pOD->pz_DisablePfx));
  1489. }
  1490. /* prevent re-translation */
  1491. tcprewriteOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
  1492. }
  1493. }
  1494. #endif /* ENABLE_NLS */
  1495. #ifdef __cplusplus
  1496. }
  1497. #endif
  1498. /* tcprewrite_opts.c ends here */