tcprewrite_opts.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  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 April 4, 2010 at 05:59:19 PM by AutoGen 5.9.9
  6. * From the definitions tcprewrite_opts.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 32:2: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 (c) 2000-2010 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) 2000-2010 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 | OPTST_STACKED \
  120. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  121. /*
  122. * Seed option description:
  123. */
  124. tSCC zSeedText[] =
  125. "Randomize src/dst IPv4/v6 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 IPv4/v6 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 IPv4/v6 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 IPv4/v6 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 IPv4/v6 addresses";
  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 IPv4/TCP/UDP header 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/v6 TTL/Hop Limit";
  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. * Tclass option description:
  252. */
  253. tSCC zTclassText[] =
  254. "Set the IPv6 Traffic Class byte";
  255. tSCC zTclass_NAME[] = "TCLASS";
  256. tSCC zTclass_Name[] = "tclass";
  257. #define TCLASS_FLAGS (OPTST_DISABLED \
  258. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  259. /*
  260. * Flowlabel option description:
  261. */
  262. tSCC zFlowlabelText[] =
  263. "Set the IPv6 Flow Label";
  264. tSCC zFlowlabel_NAME[] = "FLOWLABEL";
  265. tSCC zFlowlabel_Name[] = "flowlabel";
  266. #define FLOWLABEL_FLAGS (OPTST_DISABLED \
  267. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  268. /*
  269. * Fixlen option description:
  270. */
  271. tSCC zFixlenText[] =
  272. "Pad or truncate packet data to match header length";
  273. tSCC zFixlen_NAME[] = "FIXLEN";
  274. tSCC zFixlen_Name[] = "fixlen";
  275. #define FIXLEN_FLAGS (OPTST_DISABLED \
  276. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  277. /*
  278. * Skipl2broadcast option description:
  279. */
  280. tSCC zSkipl2broadcastText[] =
  281. "Skip rewriting broadcast/multicast Layer 2 addresses";
  282. tSCC zSkipl2broadcast_NAME[] = "SKIPL2BROADCAST";
  283. tSCC zSkipl2broadcast_Name[] = "skipl2broadcast";
  284. #define SKIPL2BROADCAST_FLAGS (OPTST_DISABLED)
  285. /*
  286. * Dlt option description:
  287. */
  288. tSCC zDltText[] =
  289. "Override output DLT encapsulation";
  290. tSCC zDlt_NAME[] = "DLT";
  291. tSCC zDlt_Name[] = "dlt";
  292. #define DLT_FLAGS (OPTST_DISABLED \
  293. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  294. /*
  295. * Enet_Dmac option description:
  296. */
  297. tSCC zEnet_DmacText[] =
  298. "Override destination ethernet MAC addresses";
  299. tSCC zEnet_Dmac_NAME[] = "ENET_DMAC";
  300. tSCC zEnet_Dmac_Name[] = "enet-dmac";
  301. #define ENET_DMAC_FLAGS (OPTST_DISABLED \
  302. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  303. /*
  304. * Enet_Smac option description:
  305. */
  306. tSCC zEnet_SmacText[] =
  307. "Override source ethernet MAC addresses";
  308. tSCC zEnet_Smac_NAME[] = "ENET_SMAC";
  309. tSCC zEnet_Smac_Name[] = "enet-smac";
  310. #define ENET_SMAC_FLAGS (OPTST_DISABLED \
  311. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  312. /*
  313. * Enet_Vlan option description:
  314. */
  315. tSCC zEnet_VlanText[] =
  316. "Specify ethernet 802.1q VLAN tag mode";
  317. tSCC zEnet_Vlan_NAME[] = "ENET_VLAN";
  318. tSCC zEnet_Vlan_Name[] = "enet-vlan";
  319. #define ENET_VLAN_FLAGS (OPTST_DISABLED \
  320. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  321. /*
  322. * Enet_Vlan_Tag option description with
  323. * "Must also have options" and "Incompatible options":
  324. */
  325. tSCC zEnet_Vlan_TagText[] =
  326. "Specify the new ethernet 802.1q VLAN tag value";
  327. tSCC zEnet_Vlan_Tag_NAME[] = "ENET_VLAN_TAG";
  328. tSCC zEnet_Vlan_Tag_Name[] = "enet-vlan-tag";
  329. static const int
  330. aEnet_Vlan_TagMustList[] = {
  331. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  332. #define ENET_VLAN_TAG_FLAGS (OPTST_DISABLED \
  333. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  334. /*
  335. * Enet_Vlan_Cfi option description with
  336. * "Must also have options" and "Incompatible options":
  337. */
  338. tSCC zEnet_Vlan_CfiText[] =
  339. "Specify the ethernet 802.1q VLAN CFI value";
  340. tSCC zEnet_Vlan_Cfi_NAME[] = "ENET_VLAN_CFI";
  341. tSCC zEnet_Vlan_Cfi_Name[] = "enet-vlan-cfi";
  342. static const int
  343. aEnet_Vlan_CfiMustList[] = {
  344. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  345. #define ENET_VLAN_CFI_FLAGS (OPTST_DISABLED \
  346. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  347. /*
  348. * Enet_Vlan_Pri option description with
  349. * "Must also have options" and "Incompatible options":
  350. */
  351. tSCC zEnet_Vlan_PriText[] =
  352. "Specify the ethernet 802.1q VLAN priority";
  353. tSCC zEnet_Vlan_Pri_NAME[] = "ENET_VLAN_PRI";
  354. tSCC zEnet_Vlan_Pri_Name[] = "enet-vlan-pri";
  355. static const int
  356. aEnet_Vlan_PriMustList[] = {
  357. INDEX_OPT_ENET_VLAN, NO_EQUIVALENT };
  358. #define ENET_VLAN_PRI_FLAGS (OPTST_DISABLED \
  359. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  360. /*
  361. * Hdlc_Control option description:
  362. */
  363. tSCC zHdlc_ControlText[] =
  364. "Specify HDLC control value";
  365. tSCC zHdlc_Control_NAME[] = "HDLC_CONTROL";
  366. tSCC zHdlc_Control_Name[] = "hdlc-control";
  367. #define HDLC_CONTROL_FLAGS (OPTST_DISABLED \
  368. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  369. /*
  370. * Hdlc_Address option description:
  371. */
  372. tSCC zHdlc_AddressText[] =
  373. "Specify HDLC address";
  374. tSCC zHdlc_Address_NAME[] = "HDLC_ADDRESS";
  375. tSCC zHdlc_Address_Name[] = "hdlc-address";
  376. #define HDLC_ADDRESS_FLAGS (OPTST_DISABLED \
  377. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  378. /*
  379. * User_Dlt option description:
  380. */
  381. tSCC zUser_DltText[] =
  382. "Set output file DLT type";
  383. tSCC zUser_Dlt_NAME[] = "USER_DLT";
  384. tSCC zUser_Dlt_Name[] = "user-dlt";
  385. #define USER_DLT_FLAGS (OPTST_DISABLED \
  386. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  387. /*
  388. * User_Dlink option description:
  389. */
  390. tSCC zUser_DlinkText[] =
  391. "Rewrite Data-Link layer with user specified data";
  392. tSCC zUser_Dlink_NAME[] = "USER_DLINK";
  393. tSCC zUser_Dlink_Name[] = "user-dlink";
  394. #define USER_DLINK_FLAGS (OPTST_DISABLED | OPTST_STACKED \
  395. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  396. /*
  397. * Dbug option description:
  398. */
  399. #ifdef DEBUG
  400. tSCC zDbugText[] =
  401. "Enable debugging output";
  402. tSCC zDbug_NAME[] = "DBUG";
  403. tSCC zDbug_Name[] = "dbug";
  404. #define zDbugDefaultArg ((char const*)0)
  405. #define DBUG_FLAGS (OPTST_DISABLED | OPTST_IMM \
  406. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  407. #else /* disable Dbug */
  408. #define VALUE_OPT_DBUG NO_EQUIVALENT
  409. #define DBUG_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  410. #define zDbugDefaultArg NULL
  411. #define zDbugText NULL
  412. #define zDbug_NAME NULL
  413. #define zDbug_Name NULL
  414. #endif /* DEBUG */
  415. /*
  416. * Infile option description:
  417. */
  418. tSCC zInfileText[] =
  419. "Input pcap file to be processed";
  420. tSCC zInfile_NAME[] = "INFILE";
  421. tSCC zInfile_Name[] = "infile";
  422. #define INFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET | OPTST_IMM \
  423. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  424. /*
  425. * Outfile option description:
  426. */
  427. tSCC zOutfileText[] =
  428. "Output pcap file";
  429. tSCC zOutfile_NAME[] = "OUTFILE";
  430. tSCC zOutfile_Name[] = "outfile";
  431. #define OUTFILE_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  432. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  433. /*
  434. * Cachefile option description:
  435. */
  436. tSCC zCachefileText[] =
  437. "Split traffic via tcpprep cache file";
  438. tSCC zCachefile_NAME[] = "CACHEFILE";
  439. tSCC zCachefile_Name[] = "cachefile";
  440. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  441. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  442. /*
  443. * Verbose option description:
  444. */
  445. #ifdef ENABLE_VERBOSE
  446. tSCC zVerboseText[] =
  447. "Print decoded packets via tcpdump to STDOUT";
  448. tSCC zVerbose_NAME[] = "VERBOSE";
  449. tSCC zVerbose_Name[] = "verbose";
  450. #define VERBOSE_FLAGS (OPTST_DISABLED | OPTST_IMM)
  451. #else /* disable Verbose */
  452. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  453. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  454. #define zVerboseText NULL
  455. #define zVerbose_NAME NULL
  456. #define zVerbose_Name NULL
  457. #endif /* ENABLE_VERBOSE */
  458. /*
  459. * Decode option description with
  460. * "Must also have options" and "Incompatible options":
  461. */
  462. #ifdef ENABLE_VERBOSE
  463. tSCC zDecodeText[] =
  464. "Arguments passed to tcpdump decoder";
  465. tSCC zDecode_NAME[] = "DECODE";
  466. tSCC zDecode_Name[] = "decode";
  467. static const int
  468. aDecodeMustList[] = {
  469. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  470. #define DECODE_FLAGS (OPTST_DISABLED \
  471. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  472. #else /* disable Decode */
  473. #define VALUE_OPT_DECODE NO_EQUIVALENT
  474. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  475. #define aDecodeMustList NULL
  476. #define zDecodeText NULL
  477. #define zDecode_NAME NULL
  478. #define zDecode_Name NULL
  479. #endif /* ENABLE_VERBOSE */
  480. /*
  481. * Fragroute option description:
  482. */
  483. #ifdef ENABLE_FRAGROUTE
  484. tSCC zFragrouteText[] =
  485. "Parse fragroute configuration file";
  486. tSCC zFragroute_NAME[] = "FRAGROUTE";
  487. tSCC zFragroute_Name[] = "fragroute";
  488. #define FRAGROUTE_FLAGS (OPTST_DISABLED \
  489. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  490. #else /* disable Fragroute */
  491. #define VALUE_OPT_FRAGROUTE NO_EQUIVALENT
  492. #define FRAGROUTE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  493. #define zFragrouteText NULL
  494. #define zFragroute_NAME NULL
  495. #define zFragroute_Name NULL
  496. #endif /* ENABLE_FRAGROUTE */
  497. /*
  498. * Fragdir option description with
  499. * "Must also have options" and "Incompatible options":
  500. */
  501. #ifdef ENABLE_FRAGROUTE
  502. tSCC zFragdirText[] =
  503. "Which flows to apply fragroute to: c2s, s2c, both";
  504. tSCC zFragdir_NAME[] = "FRAGDIR";
  505. tSCC zFragdir_Name[] = "fragdir";
  506. static const int
  507. aFragdirMustList[] = {
  508. INDEX_OPT_CACHEFILE, NO_EQUIVALENT };
  509. #define FRAGDIR_FLAGS (OPTST_DISABLED \
  510. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  511. #else /* disable Fragdir */
  512. #define VALUE_OPT_FRAGDIR NO_EQUIVALENT
  513. #define FRAGDIR_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  514. #define aFragdirMustList NULL
  515. #define zFragdirText NULL
  516. #define zFragdir_NAME NULL
  517. #define zFragdir_Name NULL
  518. #endif /* ENABLE_FRAGROUTE */
  519. /*
  520. * Skip_Soft_Errors option description:
  521. */
  522. tSCC zSkip_Soft_ErrorsText[] =
  523. "Skip writing packets with soft errors";
  524. tSCC zSkip_Soft_Errors_NAME[] = "SKIP_SOFT_ERRORS";
  525. tSCC zSkip_Soft_Errors_Name[] = "skip-soft-errors";
  526. #define SKIP_SOFT_ERRORS_FLAGS (OPTST_DISABLED)
  527. /*
  528. * Version option description:
  529. */
  530. tSCC zVersionText[] =
  531. "Print version information";
  532. tSCC zVersion_NAME[] = "VERSION";
  533. tSCC zVersion_Name[] = "version";
  534. #define VERSION_FLAGS (OPTST_DISABLED)
  535. /*
  536. * Less_Help option description:
  537. */
  538. tSCC zLess_HelpText[] =
  539. "Display less usage information and exit";
  540. tSCC zLess_Help_NAME[] = "LESS_HELP";
  541. tSCC zLess_Help_Name[] = "less-help";
  542. #define LESS_HELP_FLAGS (OPTST_DISABLED | OPTST_IMM)
  543. /*
  544. * Help/More_Help option descriptions:
  545. */
  546. tSCC zHelpText[] = "Display usage information and exit";
  547. tSCC zHelp_Name[] = "help";
  548. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  549. tSCC zMore_Help_Name[] = "more-help";
  550. tSCC zSave_OptsText[] = "Save the option state to a config file";
  551. tSCC zSave_Opts_Name[] = "save-opts";
  552. tSCC zLoad_OptsText[] = "Load options from a config file";
  553. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  554. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  555. tSCC zNotLoad_Opts_Pfx[] = "no";
  556. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  557. /*
  558. * Declare option callback procedures
  559. */
  560. #ifdef DEBUG
  561. static tOptProc doOptDbug;
  562. #else /* not DEBUG */
  563. # define doOptDbug NULL
  564. #endif /* def/not DEBUG */
  565. extern tOptProc
  566. optionNumericVal, optionPagedUsage, optionStackArg;
  567. static tOptProc
  568. doOptCachefile, doOptEnet_Vlan_Cfi, doOptEnet_Vlan_Pri,
  569. doOptEnet_Vlan_Tag, doOptFlowlabel, doOptLess_Help,
  570. doOptMtu, doOptTclass, doOptTos,
  571. doOptVersion, doUsageOpt;
  572. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  573. *
  574. * Define the Tcprewrite Option Descriptions.
  575. */
  576. static tOptDesc optDesc[ OPTION_CT ] = {
  577. { /* entry idx, value */ 0, 0,
  578. /* equiv idx, value */ 0, 0,
  579. /* equivalenced to */ NO_EQUIVALENT,
  580. /* min, max, act ct */ 0, 0, 0,
  581. /* opt state flags */ TCPEDIT_FLAGS, 0,
  582. /* last opt argumnt */ { NULL },
  583. /* arg list/cookie */ NULL,
  584. /* must/cannot opts */ NULL, NULL,
  585. /* option proc */ NULL,
  586. /* desc, NAME, name */ zTcpeditText, NULL, NULL,
  587. /* disablement strs */ NULL, NULL },
  588. { /* entry idx, value */ 1, VALUE_OPT_PORTMAP,
  589. /* equiv idx, value */ 1, VALUE_OPT_PORTMAP,
  590. /* equivalenced to */ NO_EQUIVALENT,
  591. /* min, max, act ct */ 0, -1, 0,
  592. /* opt state flags */ PORTMAP_FLAGS, 0,
  593. /* last opt argumnt */ { NULL },
  594. /* arg list/cookie */ NULL,
  595. /* must/cannot opts */ NULL, NULL,
  596. /* option proc */ optionStackArg,
  597. /* desc, NAME, name */ zPortmapText, zPortmap_NAME, zPortmap_Name,
  598. /* disablement strs */ NULL, NULL },
  599. { /* entry idx, value */ 2, VALUE_OPT_SEED,
  600. /* equiv idx, value */ 2, VALUE_OPT_SEED,
  601. /* equivalenced to */ NO_EQUIVALENT,
  602. /* min, max, act ct */ 0, 1, 0,
  603. /* opt state flags */ SEED_FLAGS, 0,
  604. /* last opt argumnt */ { NULL },
  605. /* arg list/cookie */ NULL,
  606. /* must/cannot opts */ NULL, NULL,
  607. /* option proc */ optionNumericVal,
  608. /* desc, NAME, name */ zSeedText, zSeed_NAME, zSeed_Name,
  609. /* disablement strs */ NULL, NULL },
  610. { /* entry idx, value */ 3, VALUE_OPT_PNAT,
  611. /* equiv idx, value */ 3, VALUE_OPT_PNAT,
  612. /* equivalenced to */ NO_EQUIVALENT,
  613. /* min, max, act ct */ 0, 2, 0,
  614. /* opt state flags */ PNAT_FLAGS, 0,
  615. /* last opt argumnt */ { NULL },
  616. /* arg list/cookie */ NULL,
  617. /* must/cannot opts */ NULL, aPnatCantList,
  618. /* option proc */ optionStackArg,
  619. /* desc, NAME, name */ zPnatText, zPnat_NAME, zPnat_Name,
  620. /* disablement strs */ NULL, NULL },
  621. { /* entry idx, value */ 4, VALUE_OPT_SRCIPMAP,
  622. /* equiv idx, value */ 4, VALUE_OPT_SRCIPMAP,
  623. /* equivalenced to */ NO_EQUIVALENT,
  624. /* min, max, act ct */ 0, 1, 0,
  625. /* opt state flags */ SRCIPMAP_FLAGS, 0,
  626. /* last opt argumnt */ { NULL },
  627. /* arg list/cookie */ NULL,
  628. /* must/cannot opts */ NULL, aSrcipmapCantList,
  629. /* option proc */ NULL,
  630. /* desc, NAME, name */ zSrcipmapText, zSrcipmap_NAME, zSrcipmap_Name,
  631. /* disablement strs */ NULL, NULL },
  632. { /* entry idx, value */ 5, VALUE_OPT_DSTIPMAP,
  633. /* equiv idx, value */ 5, VALUE_OPT_DSTIPMAP,
  634. /* equivalenced to */ NO_EQUIVALENT,
  635. /* min, max, act ct */ 0, 1, 0,
  636. /* opt state flags */ DSTIPMAP_FLAGS, 0,
  637. /* last opt argumnt */ { NULL },
  638. /* arg list/cookie */ NULL,
  639. /* must/cannot opts */ NULL, aDstipmapCantList,
  640. /* option proc */ NULL,
  641. /* desc, NAME, name */ zDstipmapText, zDstipmap_NAME, zDstipmap_Name,
  642. /* disablement strs */ NULL, NULL },
  643. { /* entry idx, value */ 6, VALUE_OPT_ENDPOINTS,
  644. /* equiv idx, value */ 6, VALUE_OPT_ENDPOINTS,
  645. /* equivalenced to */ NO_EQUIVALENT,
  646. /* min, max, act ct */ 0, 1, 0,
  647. /* opt state flags */ ENDPOINTS_FLAGS, 0,
  648. /* last opt argumnt */ { NULL },
  649. /* arg list/cookie */ NULL,
  650. /* must/cannot opts */ aEndpointsMustList, NULL,
  651. /* option proc */ NULL,
  652. /* desc, NAME, name */ zEndpointsText, zEndpoints_NAME, zEndpoints_Name,
  653. /* disablement strs */ NULL, NULL },
  654. { /* entry idx, value */ 7, VALUE_OPT_SKIPBROADCAST,
  655. /* equiv idx, value */ 7, VALUE_OPT_SKIPBROADCAST,
  656. /* equivalenced to */ NO_EQUIVALENT,
  657. /* min, max, act ct */ 0, 1, 0,
  658. /* opt state flags */ SKIPBROADCAST_FLAGS, 0,
  659. /* last opt argumnt */ { NULL },
  660. /* arg list/cookie */ NULL,
  661. /* must/cannot opts */ NULL, NULL,
  662. /* option proc */ NULL,
  663. /* desc, NAME, name */ zSkipbroadcastText, zSkipbroadcast_NAME, zSkipbroadcast_Name,
  664. /* disablement strs */ NULL, NULL },
  665. { /* entry idx, value */ 8, VALUE_OPT_FIXCSUM,
  666. /* equiv idx, value */ 8, VALUE_OPT_FIXCSUM,
  667. /* equivalenced to */ NO_EQUIVALENT,
  668. /* min, max, act ct */ 0, 1, 0,
  669. /* opt state flags */ FIXCSUM_FLAGS, 0,
  670. /* last opt argumnt */ { NULL },
  671. /* arg list/cookie */ NULL,
  672. /* must/cannot opts */ NULL, NULL,
  673. /* option proc */ NULL,
  674. /* desc, NAME, name */ zFixcsumText, zFixcsum_NAME, zFixcsum_Name,
  675. /* disablement strs */ NULL, NULL },
  676. { /* entry idx, value */ 9, VALUE_OPT_MTU,
  677. /* equiv idx, value */ 9, VALUE_OPT_MTU,
  678. /* equivalenced to */ NO_EQUIVALENT,
  679. /* min, max, act ct */ 0, 1, 0,
  680. /* opt state flags */ MTU_FLAGS, 0,
  681. /* last opt argumnt */ { NULL },
  682. /* arg list/cookie */ NULL,
  683. /* must/cannot opts */ NULL, NULL,
  684. /* option proc */ doOptMtu,
  685. /* desc, NAME, name */ zMtuText, zMtu_NAME, zMtu_Name,
  686. /* disablement strs */ NULL, NULL },
  687. { /* entry idx, value */ 10, VALUE_OPT_MTU_TRUNC,
  688. /* equiv idx, value */ 10, VALUE_OPT_MTU_TRUNC,
  689. /* equivalenced to */ NO_EQUIVALENT,
  690. /* min, max, act ct */ 0, 1, 0,
  691. /* opt state flags */ MTU_TRUNC_FLAGS, 0,
  692. /* last opt argumnt */ { NULL },
  693. /* arg list/cookie */ NULL,
  694. /* must/cannot opts */ NULL, NULL,
  695. /* option proc */ NULL,
  696. /* desc, NAME, name */ zMtu_TruncText, zMtu_Trunc_NAME, zMtu_Trunc_Name,
  697. /* disablement strs */ NULL, NULL },
  698. { /* entry idx, value */ 11, VALUE_OPT_EFCS,
  699. /* equiv idx, value */ 11, VALUE_OPT_EFCS,
  700. /* equivalenced to */ NO_EQUIVALENT,
  701. /* min, max, act ct */ 0, 1, 0,
  702. /* opt state flags */ EFCS_FLAGS, 0,
  703. /* last opt argumnt */ { NULL },
  704. /* arg list/cookie */ NULL,
  705. /* must/cannot opts */ NULL, NULL,
  706. /* option proc */ NULL,
  707. /* desc, NAME, name */ zEfcsText, zEfcs_NAME, zEfcs_Name,
  708. /* disablement strs */ NULL, NULL },
  709. { /* entry idx, value */ 12, VALUE_OPT_TTL,
  710. /* equiv idx, value */ 12, VALUE_OPT_TTL,
  711. /* equivalenced to */ NO_EQUIVALENT,
  712. /* min, max, act ct */ 0, 1, 0,
  713. /* opt state flags */ TTL_FLAGS, 0,
  714. /* last opt argumnt */ { NULL },
  715. /* arg list/cookie */ NULL,
  716. /* must/cannot opts */ NULL, NULL,
  717. /* option proc */ NULL,
  718. /* desc, NAME, name */ zTtlText, zTtl_NAME, zTtl_Name,
  719. /* disablement strs */ NULL, NULL },
  720. { /* entry idx, value */ 13, VALUE_OPT_TOS,
  721. /* equiv idx, value */ 13, VALUE_OPT_TOS,
  722. /* equivalenced to */ NO_EQUIVALENT,
  723. /* min, max, act ct */ 0, 1, 0,
  724. /* opt state flags */ TOS_FLAGS, 0,
  725. /* last opt argumnt */ { NULL },
  726. /* arg list/cookie */ NULL,
  727. /* must/cannot opts */ NULL, NULL,
  728. /* option proc */ doOptTos,
  729. /* desc, NAME, name */ zTosText, zTos_NAME, zTos_Name,
  730. /* disablement strs */ NULL, NULL },
  731. { /* entry idx, value */ 14, VALUE_OPT_TCLASS,
  732. /* equiv idx, value */ 14, VALUE_OPT_TCLASS,
  733. /* equivalenced to */ NO_EQUIVALENT,
  734. /* min, max, act ct */ 0, 1, 0,
  735. /* opt state flags */ TCLASS_FLAGS, 0,
  736. /* last opt argumnt */ { NULL },
  737. /* arg list/cookie */ NULL,
  738. /* must/cannot opts */ NULL, NULL,
  739. /* option proc */ doOptTclass,
  740. /* desc, NAME, name */ zTclassText, zTclass_NAME, zTclass_Name,
  741. /* disablement strs */ NULL, NULL },
  742. { /* entry idx, value */ 15, VALUE_OPT_FLOWLABEL,
  743. /* equiv idx, value */ 15, VALUE_OPT_FLOWLABEL,
  744. /* equivalenced to */ NO_EQUIVALENT,
  745. /* min, max, act ct */ 0, 1, 0,
  746. /* opt state flags */ FLOWLABEL_FLAGS, 0,
  747. /* last opt argumnt */ { NULL },
  748. /* arg list/cookie */ NULL,
  749. /* must/cannot opts */ NULL, NULL,
  750. /* option proc */ doOptFlowlabel,
  751. /* desc, NAME, name */ zFlowlabelText, zFlowlabel_NAME, zFlowlabel_Name,
  752. /* disablement strs */ NULL, NULL },
  753. { /* entry idx, value */ 16, VALUE_OPT_FIXLEN,
  754. /* equiv idx, value */ 16, VALUE_OPT_FIXLEN,
  755. /* equivalenced to */ NO_EQUIVALENT,
  756. /* min, max, act ct */ 0, 1, 0,
  757. /* opt state flags */ FIXLEN_FLAGS, 0,
  758. /* last opt argumnt */ { NULL },
  759. /* arg list/cookie */ NULL,
  760. /* must/cannot opts */ NULL, NULL,
  761. /* option proc */ NULL,
  762. /* desc, NAME, name */ zFixlenText, zFixlen_NAME, zFixlen_Name,
  763. /* disablement strs */ NULL, NULL },
  764. { /* entry idx, value */ 17, VALUE_OPT_SKIPL2BROADCAST,
  765. /* equiv idx, value */ 17, VALUE_OPT_SKIPL2BROADCAST,
  766. /* equivalenced to */ NO_EQUIVALENT,
  767. /* min, max, act ct */ 0, 1, 0,
  768. /* opt state flags */ SKIPL2BROADCAST_FLAGS, 0,
  769. /* last opt argumnt */ { NULL },
  770. /* arg list/cookie */ NULL,
  771. /* must/cannot opts */ NULL, NULL,
  772. /* option proc */ NULL,
  773. /* desc, NAME, name */ zSkipl2broadcastText, zSkipl2broadcast_NAME, zSkipl2broadcast_Name,
  774. /* disablement strs */ NULL, NULL },
  775. { /* entry idx, value */ 18, VALUE_OPT_DLT,
  776. /* equiv idx, value */ 18, VALUE_OPT_DLT,
  777. /* equivalenced to */ NO_EQUIVALENT,
  778. /* min, max, act ct */ 0, 1, 0,
  779. /* opt state flags */ DLT_FLAGS, 0,
  780. /* last opt argumnt */ { NULL },
  781. /* arg list/cookie */ NULL,
  782. /* must/cannot opts */ NULL, NULL,
  783. /* option proc */ NULL,
  784. /* desc, NAME, name */ zDltText, zDlt_NAME, zDlt_Name,
  785. /* disablement strs */ NULL, NULL },
  786. { /* entry idx, value */ 19, VALUE_OPT_ENET_DMAC,
  787. /* equiv idx, value */ 19, VALUE_OPT_ENET_DMAC,
  788. /* equivalenced to */ NO_EQUIVALENT,
  789. /* min, max, act ct */ 0, 1, 0,
  790. /* opt state flags */ ENET_DMAC_FLAGS, 0,
  791. /* last opt argumnt */ { NULL },
  792. /* arg list/cookie */ NULL,
  793. /* must/cannot opts */ NULL, NULL,
  794. /* option proc */ NULL,
  795. /* desc, NAME, name */ zEnet_DmacText, zEnet_Dmac_NAME, zEnet_Dmac_Name,
  796. /* disablement strs */ NULL, NULL },
  797. { /* entry idx, value */ 20, VALUE_OPT_ENET_SMAC,
  798. /* equiv idx, value */ 20, VALUE_OPT_ENET_SMAC,
  799. /* equivalenced to */ NO_EQUIVALENT,
  800. /* min, max, act ct */ 0, 1, 0,
  801. /* opt state flags */ ENET_SMAC_FLAGS, 0,
  802. /* last opt argumnt */ { NULL },
  803. /* arg list/cookie */ NULL,
  804. /* must/cannot opts */ NULL, NULL,
  805. /* option proc */ NULL,
  806. /* desc, NAME, name */ zEnet_SmacText, zEnet_Smac_NAME, zEnet_Smac_Name,
  807. /* disablement strs */ NULL, NULL },
  808. { /* entry idx, value */ 21, VALUE_OPT_ENET_VLAN,
  809. /* equiv idx, value */ 21, VALUE_OPT_ENET_VLAN,
  810. /* equivalenced to */ NO_EQUIVALENT,
  811. /* min, max, act ct */ 0, 1, 0,
  812. /* opt state flags */ ENET_VLAN_FLAGS, 0,
  813. /* last opt argumnt */ { NULL },
  814. /* arg list/cookie */ NULL,
  815. /* must/cannot opts */ NULL, NULL,
  816. /* option proc */ NULL,
  817. /* desc, NAME, name */ zEnet_VlanText, zEnet_Vlan_NAME, zEnet_Vlan_Name,
  818. /* disablement strs */ NULL, NULL },
  819. { /* entry idx, value */ 22, VALUE_OPT_ENET_VLAN_TAG,
  820. /* equiv idx, value */ 22, VALUE_OPT_ENET_VLAN_TAG,
  821. /* equivalenced to */ NO_EQUIVALENT,
  822. /* min, max, act ct */ 0, 1, 0,
  823. /* opt state flags */ ENET_VLAN_TAG_FLAGS, 0,
  824. /* last opt argumnt */ { NULL },
  825. /* arg list/cookie */ NULL,
  826. /* must/cannot opts */ aEnet_Vlan_TagMustList, NULL,
  827. /* option proc */ doOptEnet_Vlan_Tag,
  828. /* desc, NAME, name */ zEnet_Vlan_TagText, zEnet_Vlan_Tag_NAME, zEnet_Vlan_Tag_Name,
  829. /* disablement strs */ NULL, NULL },
  830. { /* entry idx, value */ 23, VALUE_OPT_ENET_VLAN_CFI,
  831. /* equiv idx, value */ 23, VALUE_OPT_ENET_VLAN_CFI,
  832. /* equivalenced to */ NO_EQUIVALENT,
  833. /* min, max, act ct */ 0, 1, 0,
  834. /* opt state flags */ ENET_VLAN_CFI_FLAGS, 0,
  835. /* last opt argumnt */ { NULL },
  836. /* arg list/cookie */ NULL,
  837. /* must/cannot opts */ aEnet_Vlan_CfiMustList, NULL,
  838. /* option proc */ doOptEnet_Vlan_Cfi,
  839. /* desc, NAME, name */ zEnet_Vlan_CfiText, zEnet_Vlan_Cfi_NAME, zEnet_Vlan_Cfi_Name,
  840. /* disablement strs */ NULL, NULL },
  841. { /* entry idx, value */ 24, VALUE_OPT_ENET_VLAN_PRI,
  842. /* equiv idx, value */ 24, VALUE_OPT_ENET_VLAN_PRI,
  843. /* equivalenced to */ NO_EQUIVALENT,
  844. /* min, max, act ct */ 0, 1, 0,
  845. /* opt state flags */ ENET_VLAN_PRI_FLAGS, 0,
  846. /* last opt argumnt */ { NULL },
  847. /* arg list/cookie */ NULL,
  848. /* must/cannot opts */ aEnet_Vlan_PriMustList, NULL,
  849. /* option proc */ doOptEnet_Vlan_Pri,
  850. /* desc, NAME, name */ zEnet_Vlan_PriText, zEnet_Vlan_Pri_NAME, zEnet_Vlan_Pri_Name,
  851. /* disablement strs */ NULL, NULL },
  852. { /* entry idx, value */ 25, VALUE_OPT_HDLC_CONTROL,
  853. /* equiv idx, value */ 25, VALUE_OPT_HDLC_CONTROL,
  854. /* equivalenced to */ NO_EQUIVALENT,
  855. /* min, max, act ct */ 0, 1, 0,
  856. /* opt state flags */ HDLC_CONTROL_FLAGS, 0,
  857. /* last opt argumnt */ { NULL },
  858. /* arg list/cookie */ NULL,
  859. /* must/cannot opts */ NULL, NULL,
  860. /* option proc */ optionNumericVal,
  861. /* desc, NAME, name */ zHdlc_ControlText, zHdlc_Control_NAME, zHdlc_Control_Name,
  862. /* disablement strs */ NULL, NULL },
  863. { /* entry idx, value */ 26, VALUE_OPT_HDLC_ADDRESS,
  864. /* equiv idx, value */ 26, VALUE_OPT_HDLC_ADDRESS,
  865. /* equivalenced to */ NO_EQUIVALENT,
  866. /* min, max, act ct */ 0, 1, 0,
  867. /* opt state flags */ HDLC_ADDRESS_FLAGS, 0,
  868. /* last opt argumnt */ { NULL },
  869. /* arg list/cookie */ NULL,
  870. /* must/cannot opts */ NULL, NULL,
  871. /* option proc */ optionNumericVal,
  872. /* desc, NAME, name */ zHdlc_AddressText, zHdlc_Address_NAME, zHdlc_Address_Name,
  873. /* disablement strs */ NULL, NULL },
  874. { /* entry idx, value */ 27, VALUE_OPT_USER_DLT,
  875. /* equiv idx, value */ 27, VALUE_OPT_USER_DLT,
  876. /* equivalenced to */ NO_EQUIVALENT,
  877. /* min, max, act ct */ 0, 1, 0,
  878. /* opt state flags */ USER_DLT_FLAGS, 0,
  879. /* last opt argumnt */ { NULL },
  880. /* arg list/cookie */ NULL,
  881. /* must/cannot opts */ NULL, NULL,
  882. /* option proc */ optionNumericVal,
  883. /* desc, NAME, name */ zUser_DltText, zUser_Dlt_NAME, zUser_Dlt_Name,
  884. /* disablement strs */ NULL, NULL },
  885. { /* entry idx, value */ 28, VALUE_OPT_USER_DLINK,
  886. /* equiv idx, value */ 28, VALUE_OPT_USER_DLINK,
  887. /* equivalenced to */ NO_EQUIVALENT,
  888. /* min, max, act ct */ 0, 2, 0,
  889. /* opt state flags */ USER_DLINK_FLAGS, 0,
  890. /* last opt argumnt */ { NULL },
  891. /* arg list/cookie */ NULL,
  892. /* must/cannot opts */ NULL, NULL,
  893. /* option proc */ optionStackArg,
  894. /* desc, NAME, name */ zUser_DlinkText, zUser_Dlink_NAME, zUser_Dlink_Name,
  895. /* disablement strs */ NULL, NULL },
  896. { /* entry idx, value */ 29, VALUE_OPT_DBUG,
  897. /* equiv idx, value */ 29, VALUE_OPT_DBUG,
  898. /* equivalenced to */ NO_EQUIVALENT,
  899. /* min, max, act ct */ 0, 1, 0,
  900. /* opt state flags */ DBUG_FLAGS, 0,
  901. /* last opt argumnt */ { zDbugDefaultArg },
  902. /* arg list/cookie */ NULL,
  903. /* must/cannot opts */ NULL, NULL,
  904. /* option proc */ doOptDbug,
  905. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  906. /* disablement strs */ NULL, NULL },
  907. { /* entry idx, value */ 30, VALUE_OPT_INFILE,
  908. /* equiv idx, value */ 30, VALUE_OPT_INFILE,
  909. /* equivalenced to */ NO_EQUIVALENT,
  910. /* min, max, act ct */ 1, 1, 0,
  911. /* opt state flags */ INFILE_FLAGS, 0,
  912. /* last opt argumnt */ { NULL },
  913. /* arg list/cookie */ NULL,
  914. /* must/cannot opts */ NULL, NULL,
  915. /* option proc */ NULL,
  916. /* desc, NAME, name */ zInfileText, zInfile_NAME, zInfile_Name,
  917. /* disablement strs */ NULL, NULL },
  918. { /* entry idx, value */ 31, VALUE_OPT_OUTFILE,
  919. /* equiv idx, value */ 31, VALUE_OPT_OUTFILE,
  920. /* equivalenced to */ NO_EQUIVALENT,
  921. /* min, max, act ct */ 1, 1, 0,
  922. /* opt state flags */ OUTFILE_FLAGS, 0,
  923. /* last opt argumnt */ { NULL },
  924. /* arg list/cookie */ NULL,
  925. /* must/cannot opts */ NULL, NULL,
  926. /* option proc */ NULL,
  927. /* desc, NAME, name */ zOutfileText, zOutfile_NAME, zOutfile_Name,
  928. /* disablement strs */ NULL, NULL },
  929. { /* entry idx, value */ 32, VALUE_OPT_CACHEFILE,
  930. /* equiv idx, value */ 32, VALUE_OPT_CACHEFILE,
  931. /* equivalenced to */ NO_EQUIVALENT,
  932. /* min, max, act ct */ 0, 1, 0,
  933. /* opt state flags */ CACHEFILE_FLAGS, 0,
  934. /* last opt argumnt */ { NULL },
  935. /* arg list/cookie */ NULL,
  936. /* must/cannot opts */ NULL, NULL,
  937. /* option proc */ doOptCachefile,
  938. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  939. /* disablement strs */ NULL, NULL },
  940. { /* entry idx, value */ 33, VALUE_OPT_VERBOSE,
  941. /* equiv idx, value */ 33, VALUE_OPT_VERBOSE,
  942. /* equivalenced to */ NO_EQUIVALENT,
  943. /* min, max, act ct */ 0, 1, 0,
  944. /* opt state flags */ VERBOSE_FLAGS, 0,
  945. /* last opt argumnt */ { NULL },
  946. /* arg list/cookie */ NULL,
  947. /* must/cannot opts */ NULL, NULL,
  948. /* option proc */ NULL,
  949. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  950. /* disablement strs */ NULL, NULL },
  951. { /* entry idx, value */ 34, VALUE_OPT_DECODE,
  952. /* equiv idx, value */ 34, VALUE_OPT_DECODE,
  953. /* equivalenced to */ NO_EQUIVALENT,
  954. /* min, max, act ct */ 0, 1, 0,
  955. /* opt state flags */ DECODE_FLAGS, 0,
  956. /* last opt argumnt */ { NULL },
  957. /* arg list/cookie */ NULL,
  958. /* must/cannot opts */ aDecodeMustList, NULL,
  959. /* option proc */ NULL,
  960. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  961. /* disablement strs */ NULL, NULL },
  962. { /* entry idx, value */ 35, VALUE_OPT_FRAGROUTE,
  963. /* equiv idx, value */ 35, VALUE_OPT_FRAGROUTE,
  964. /* equivalenced to */ NO_EQUIVALENT,
  965. /* min, max, act ct */ 0, 1, 0,
  966. /* opt state flags */ FRAGROUTE_FLAGS, 0,
  967. /* last opt argumnt */ { NULL },
  968. /* arg list/cookie */ NULL,
  969. /* must/cannot opts */ NULL, NULL,
  970. /* option proc */ NULL,
  971. /* desc, NAME, name */ zFragrouteText, zFragroute_NAME, zFragroute_Name,
  972. /* disablement strs */ NULL, NULL },
  973. { /* entry idx, value */ 36, VALUE_OPT_FRAGDIR,
  974. /* equiv idx, value */ 36, VALUE_OPT_FRAGDIR,
  975. /* equivalenced to */ NO_EQUIVALENT,
  976. /* min, max, act ct */ 0, 1, 0,
  977. /* opt state flags */ FRAGDIR_FLAGS, 0,
  978. /* last opt argumnt */ { NULL },
  979. /* arg list/cookie */ NULL,
  980. /* must/cannot opts */ aFragdirMustList, NULL,
  981. /* option proc */ NULL,
  982. /* desc, NAME, name */ zFragdirText, zFragdir_NAME, zFragdir_Name,
  983. /* disablement strs */ NULL, NULL },
  984. { /* entry idx, value */ 37, VALUE_OPT_SKIP_SOFT_ERRORS,
  985. /* equiv idx, value */ 37, VALUE_OPT_SKIP_SOFT_ERRORS,
  986. /* equivalenced to */ NO_EQUIVALENT,
  987. /* min, max, act ct */ 0, 1, 0,
  988. /* opt state flags */ SKIP_SOFT_ERRORS_FLAGS, 0,
  989. /* last opt argumnt */ { NULL },
  990. /* arg list/cookie */ NULL,
  991. /* must/cannot opts */ NULL, NULL,
  992. /* option proc */ NULL,
  993. /* desc, NAME, name */ zSkip_Soft_ErrorsText, zSkip_Soft_Errors_NAME, zSkip_Soft_Errors_Name,
  994. /* disablement strs */ NULL, NULL },
  995. { /* entry idx, value */ 38, VALUE_OPT_VERSION,
  996. /* equiv idx, value */ 38, VALUE_OPT_VERSION,
  997. /* equivalenced to */ NO_EQUIVALENT,
  998. /* min, max, act ct */ 0, 1, 0,
  999. /* opt state flags */ VERSION_FLAGS, 0,
  1000. /* last opt argumnt */ { NULL },
  1001. /* arg list/cookie */ NULL,
  1002. /* must/cannot opts */ NULL, NULL,
  1003. /* option proc */ doOptVersion,
  1004. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  1005. /* disablement strs */ NULL, NULL },
  1006. { /* entry idx, value */ 39, VALUE_OPT_LESS_HELP,
  1007. /* equiv idx, value */ 39, VALUE_OPT_LESS_HELP,
  1008. /* equivalenced to */ NO_EQUIVALENT,
  1009. /* min, max, act ct */ 0, 1, 0,
  1010. /* opt state flags */ LESS_HELP_FLAGS, 0,
  1011. /* last opt argumnt */ { NULL },
  1012. /* arg list/cookie */ NULL,
  1013. /* must/cannot opts */ NULL, NULL,
  1014. /* option proc */ doOptLess_Help,
  1015. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  1016. /* disablement strs */ NULL, NULL },
  1017. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  1018. /* equiv idx value */ NO_EQUIVALENT, 0,
  1019. /* equivalenced to */ NO_EQUIVALENT,
  1020. /* min, max, act ct */ 0, 1, 0,
  1021. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  1022. /* last opt argumnt */ { NULL },
  1023. /* arg list/cookie */ NULL,
  1024. /* must/cannot opts */ NULL, NULL,
  1025. /* option proc */ doUsageOpt,
  1026. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  1027. /* disablement strs */ NULL, NULL },
  1028. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  1029. /* equiv idx value */ NO_EQUIVALENT, 0,
  1030. /* equivalenced to */ NO_EQUIVALENT,
  1031. /* min, max, act ct */ 0, 1, 0,
  1032. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  1033. /* last opt argumnt */ { NULL },
  1034. /* arg list/cookie */ NULL,
  1035. /* must/cannot opts */ NULL, NULL,
  1036. /* option proc */ optionPagedUsage,
  1037. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  1038. /* disablement strs */ NULL, NULL },
  1039. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  1040. /* equiv idx value */ NO_EQUIVALENT, 0,
  1041. /* equivalenced to */ NO_EQUIVALENT,
  1042. /* min, max, act ct */ 0, 1, 0,
  1043. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  1044. | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
  1045. /* last opt argumnt */ { NULL },
  1046. /* arg list/cookie */ NULL,
  1047. /* must/cannot opts */ NULL, NULL,
  1048. /* option proc */ NULL,
  1049. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  1050. /* disablement strs */ NULL, NULL },
  1051. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  1052. /* equiv idx value */ NO_EQUIVALENT, 0,
  1053. /* equivalenced to */ NO_EQUIVALENT,
  1054. /* min, max, act ct */ 0, NOLIMIT, 0,
  1055. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  1056. | OPTST_DISABLE_IMM, 0,
  1057. /* last opt argumnt */ { NULL },
  1058. /* arg list/cookie */ NULL,
  1059. /* must/cannot opts */ NULL, NULL,
  1060. /* option proc */ optionLoadOpt,
  1061. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  1062. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  1063. };
  1064. tOptDesc * const tcpedit_tcpedit_optDesc_p = optDesc + 0;
  1065. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1066. *
  1067. * Define the Tcprewrite Option Environment
  1068. */
  1069. tSCC zPROGNAME[] = "TCPREWRITE";
  1070. tSCC zUsageTitle[] =
  1071. "tcprewrite (tcprewrite) - Rewrite the packets in a pcap file.\n\
  1072. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  1073. tSCC zRcName[] = ".tcprewriterc";
  1074. tSCC* apzHomeList[] = {
  1075. "$$/",
  1076. NULL };
  1077. #define zBugsAddr NULL
  1078. #define zExplain NULL
  1079. tSCC zDetail[] = "\n\
  1080. Tcprewrite is a tool to rewrite packets stored in ``pcap(3)'' file format,\n\
  1081. such as crated by tools such as ``tcpdump(1)'' and ``ethereal(1)''.\n\
  1082. Once a pcap file has had it's packets rewritten, they can be replayed back\n\
  1083. out on the network using ``tcpreplay(1)''.\n\n\
  1084. tcprewrite currently supports reading the following DLT types:\n\n\n\
  1085. ``DLT_C_HDLC'' aka Cisco HDLC\n\n\n\
  1086. ``DLT_EN10MB'' aka Ethernet\n\n\n\
  1087. ``DLT_LINUX_SLL'' aka Linux Cooked Socket\n\n\n\
  1088. ``DLT_RAW'' aka RAW IP\n\n\n\
  1089. ``DLT_NULL'' aka BSD Loopback\n\n\n\
  1090. ``DLT_LOOP'' aka OpenBSD Loopback\n\n\n\
  1091. ``DLT_IEEE802_11'' aka 802.11a/b/g\n\n\n\
  1092. ``DLT_IEEE802_11_RADIO'' aka 802.11a/b/g with Radiotap headers\n\n\
  1093. Please see the --dlt option for supported DLT types for writing.\n\n\
  1094. The packet editing features of tcprewrite which distinguish between \"client\"\n\
  1095. and \"server\" traffic requires a tcpprep(1) cache file.\n\n\
  1096. For more details, please see the Tcpreplay Manual at:\n\
  1097. http://tcpreplay.synfin.net/trac/wiki/manual\n";
  1098. #define zFullVersion NULL
  1099. /* extracted from /usr/local/share/autogen/optcode.tpl near line 501 */
  1100. #if defined(ENABLE_NLS)
  1101. # define OPTPROC_BASE OPTPROC_TRANSLATE
  1102. static tOptionXlateProc translate_option_strings;
  1103. #else
  1104. # define OPTPROC_BASE OPTPROC_NONE
  1105. # define translate_option_strings NULL
  1106. #endif /* ENABLE_NLS */
  1107. #define tcprewrite_full_usage NULL
  1108. #define tcprewrite_short_usage NULL
  1109. tOptions tcprewriteOptions = {
  1110. OPTIONS_STRUCT_VERSION,
  1111. 0, NULL, /* original argc + argv */
  1112. ( OPTPROC_BASE
  1113. + OPTPROC_ERRSTOP
  1114. + OPTPROC_SHORTOPT
  1115. + OPTPROC_LONGOPT
  1116. + OPTPROC_NO_REQ_OPT
  1117. + OPTPROC_NO_ARGS
  1118. + OPTPROC_GNUUSAGE ),
  1119. 0, NULL, /* current option index, current option */
  1120. NULL, NULL, zPROGNAME,
  1121. zRcName, zCopyright, zCopyrightNotice,
  1122. zFullVersion, apzHomeList, zUsageTitle,
  1123. zExplain, zDetail, optDesc,
  1124. zBugsAddr, /* address to send bugs to */
  1125. NULL, NULL, /* extensions/saved state */
  1126. optionUsage, /* usage procedure */
  1127. translate_option_strings, /* translation procedure */
  1128. /*
  1129. * Indexes to special options
  1130. */
  1131. { INDEX_OPT_MORE_HELP, /* more-help option index */
  1132. INDEX_OPT_SAVE_OPTS, /* save option index */
  1133. NO_EQUIVALENT, /* '-#' option index */
  1134. 9 /* index of default opt */
  1135. },
  1136. 44 /* full option count */, 40 /* user option count */,
  1137. tcprewrite_full_usage, tcprewrite_short_usage,
  1138. NULL, NULL
  1139. };
  1140. /*
  1141. * Create the static procedure(s) declared above.
  1142. */
  1143. static void
  1144. doUsageOpt(
  1145. tOptions* pOptions,
  1146. tOptDesc* pOptDesc )
  1147. {
  1148. (void)pOptions;
  1149. USAGE( EXIT_SUCCESS );
  1150. }
  1151. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1152. *
  1153. * For the mtu option.
  1154. */
  1155. static void
  1156. doOptMtu(tOptions* pOptions, tOptDesc* pOptDesc)
  1157. {
  1158. static const struct {long const rmin, rmax;} rng[1] = {
  1159. { 1, MAXPACKET } };
  1160. long val;
  1161. int ix;
  1162. char * pzEnd;
  1163. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1164. goto emit_ranges;
  1165. errno = 0;
  1166. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1167. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1168. goto bad_value;
  1169. if (*pzEnd != '\0')
  1170. goto bad_value;
  1171. for (ix = 0; ix < 1; ix++) {
  1172. if (val < rng[ix].rmin)
  1173. continue; /* ranges need not be ordered. */
  1174. if (val == rng[ix].rmin)
  1175. goto valid_return;
  1176. if (rng[ix].rmax == LONG_MIN)
  1177. continue;
  1178. if (val <= rng[ix].rmax)
  1179. goto valid_return;
  1180. }
  1181. bad_value:
  1182. option_usage_fp = stderr;
  1183. emit_ranges:
  1184. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1185. return;
  1186. valid_return:
  1187. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1188. free((void *)pOptDesc->optArg.argString);
  1189. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1190. }
  1191. pOptDesc->optArg.argInt = val;
  1192. }
  1193. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1194. *
  1195. * For the tos option.
  1196. */
  1197. static void
  1198. doOptTos(tOptions* pOptions, tOptDesc* pOptDesc)
  1199. {
  1200. static const struct {long const rmin, rmax;} rng[1] = {
  1201. { 0, 255 } };
  1202. long val;
  1203. int ix;
  1204. char * pzEnd;
  1205. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1206. goto emit_ranges;
  1207. errno = 0;
  1208. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1209. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1210. goto bad_value;
  1211. if (*pzEnd != '\0')
  1212. goto bad_value;
  1213. for (ix = 0; ix < 1; ix++) {
  1214. if (val < rng[ix].rmin)
  1215. continue; /* ranges need not be ordered. */
  1216. if (val == rng[ix].rmin)
  1217. goto valid_return;
  1218. if (rng[ix].rmax == LONG_MIN)
  1219. continue;
  1220. if (val <= rng[ix].rmax)
  1221. goto valid_return;
  1222. }
  1223. bad_value:
  1224. option_usage_fp = stderr;
  1225. emit_ranges:
  1226. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1227. return;
  1228. valid_return:
  1229. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1230. free((void *)pOptDesc->optArg.argString);
  1231. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1232. }
  1233. pOptDesc->optArg.argInt = val;
  1234. }
  1235. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1236. *
  1237. * For the tclass option.
  1238. */
  1239. static void
  1240. doOptTclass(tOptions* pOptions, tOptDesc* pOptDesc)
  1241. {
  1242. static const struct {long const rmin, rmax;} rng[1] = {
  1243. { 0, 255 } };
  1244. long val;
  1245. int ix;
  1246. char * pzEnd;
  1247. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1248. goto emit_ranges;
  1249. errno = 0;
  1250. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1251. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1252. goto bad_value;
  1253. if (*pzEnd != '\0')
  1254. goto bad_value;
  1255. for (ix = 0; ix < 1; ix++) {
  1256. if (val < rng[ix].rmin)
  1257. continue; /* ranges need not be ordered. */
  1258. if (val == rng[ix].rmin)
  1259. goto valid_return;
  1260. if (rng[ix].rmax == LONG_MIN)
  1261. continue;
  1262. if (val <= rng[ix].rmax)
  1263. goto valid_return;
  1264. }
  1265. bad_value:
  1266. option_usage_fp = stderr;
  1267. emit_ranges:
  1268. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1269. return;
  1270. valid_return:
  1271. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1272. free((void *)pOptDesc->optArg.argString);
  1273. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1274. }
  1275. pOptDesc->optArg.argInt = val;
  1276. }
  1277. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1278. *
  1279. * For the flowlabel option.
  1280. */
  1281. static void
  1282. doOptFlowlabel(tOptions* pOptions, tOptDesc* pOptDesc)
  1283. {
  1284. static const struct {long const rmin, rmax;} rng[1] = {
  1285. { 0, 1048575 } };
  1286. long val;
  1287. int ix;
  1288. char * pzEnd;
  1289. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1290. goto emit_ranges;
  1291. errno = 0;
  1292. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1293. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1294. goto bad_value;
  1295. if (*pzEnd != '\0')
  1296. goto bad_value;
  1297. for (ix = 0; ix < 1; ix++) {
  1298. if (val < rng[ix].rmin)
  1299. continue; /* ranges need not be ordered. */
  1300. if (val == rng[ix].rmin)
  1301. goto valid_return;
  1302. if (rng[ix].rmax == LONG_MIN)
  1303. continue;
  1304. if (val <= rng[ix].rmax)
  1305. goto valid_return;
  1306. }
  1307. bad_value:
  1308. option_usage_fp = stderr;
  1309. emit_ranges:
  1310. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1311. return;
  1312. valid_return:
  1313. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1314. free((void *)pOptDesc->optArg.argString);
  1315. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1316. }
  1317. pOptDesc->optArg.argInt = val;
  1318. }
  1319. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1320. *
  1321. * For the enet-vlan-tag option.
  1322. */
  1323. static void
  1324. doOptEnet_Vlan_Tag(tOptions* pOptions, tOptDesc* pOptDesc)
  1325. {
  1326. static const struct {long const rmin, rmax;} rng[1] = {
  1327. { 0, 4095 } };
  1328. long val;
  1329. int ix;
  1330. char * pzEnd;
  1331. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1332. goto emit_ranges;
  1333. errno = 0;
  1334. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1335. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1336. goto bad_value;
  1337. if (*pzEnd != '\0')
  1338. goto bad_value;
  1339. for (ix = 0; ix < 1; ix++) {
  1340. if (val < rng[ix].rmin)
  1341. continue; /* ranges need not be ordered. */
  1342. if (val == rng[ix].rmin)
  1343. goto valid_return;
  1344. if (rng[ix].rmax == LONG_MIN)
  1345. continue;
  1346. if (val <= rng[ix].rmax)
  1347. goto valid_return;
  1348. }
  1349. bad_value:
  1350. option_usage_fp = stderr;
  1351. emit_ranges:
  1352. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1353. return;
  1354. valid_return:
  1355. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1356. free((void *)pOptDesc->optArg.argString);
  1357. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1358. }
  1359. pOptDesc->optArg.argInt = val;
  1360. }
  1361. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1362. *
  1363. * For the enet-vlan-cfi option.
  1364. */
  1365. static void
  1366. doOptEnet_Vlan_Cfi(tOptions* pOptions, tOptDesc* pOptDesc)
  1367. {
  1368. static const struct {long const rmin, rmax;} rng[1] = {
  1369. { 0, 1 } };
  1370. long val;
  1371. int ix;
  1372. char * pzEnd;
  1373. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1374. goto emit_ranges;
  1375. errno = 0;
  1376. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1377. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1378. goto bad_value;
  1379. if (*pzEnd != '\0')
  1380. goto bad_value;
  1381. for (ix = 0; ix < 1; ix++) {
  1382. if (val < rng[ix].rmin)
  1383. continue; /* ranges need not be ordered. */
  1384. if (val == rng[ix].rmin)
  1385. goto valid_return;
  1386. if (rng[ix].rmax == LONG_MIN)
  1387. continue;
  1388. if (val <= rng[ix].rmax)
  1389. goto valid_return;
  1390. }
  1391. bad_value:
  1392. option_usage_fp = stderr;
  1393. emit_ranges:
  1394. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1395. return;
  1396. valid_return:
  1397. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1398. free((void *)pOptDesc->optArg.argString);
  1399. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1400. }
  1401. pOptDesc->optArg.argInt = val;
  1402. }
  1403. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1404. *
  1405. * For the enet-vlan-pri option.
  1406. */
  1407. static void
  1408. doOptEnet_Vlan_Pri(tOptions* pOptions, tOptDesc* pOptDesc)
  1409. {
  1410. static const struct {long const rmin, rmax;} rng[1] = {
  1411. { 0, 7 } };
  1412. long val;
  1413. int ix;
  1414. char * pzEnd;
  1415. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1416. goto emit_ranges;
  1417. errno = 0;
  1418. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1419. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1420. goto bad_value;
  1421. if (*pzEnd != '\0')
  1422. goto bad_value;
  1423. for (ix = 0; ix < 1; ix++) {
  1424. if (val < rng[ix].rmin)
  1425. continue; /* ranges need not be ordered. */
  1426. if (val == rng[ix].rmin)
  1427. goto valid_return;
  1428. if (rng[ix].rmax == LONG_MIN)
  1429. continue;
  1430. if (val <= rng[ix].rmax)
  1431. goto valid_return;
  1432. }
  1433. bad_value:
  1434. option_usage_fp = stderr;
  1435. emit_ranges:
  1436. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1437. return;
  1438. valid_return:
  1439. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1440. free((void *)pOptDesc->optArg.argString);
  1441. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1442. }
  1443. pOptDesc->optArg.argInt = val;
  1444. }
  1445. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1446. *
  1447. * For the dbug option, when DEBUG is #define-d.
  1448. */
  1449. #ifdef DEBUG
  1450. static void
  1451. doOptDbug(tOptions* pOptions, tOptDesc* pOptDesc)
  1452. {
  1453. static const struct {long const rmin, rmax;} rng[1] = {
  1454. { 0, 5 } };
  1455. long val;
  1456. int ix;
  1457. char * pzEnd;
  1458. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1459. goto emit_ranges;
  1460. errno = 0;
  1461. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1462. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1463. goto bad_value;
  1464. if (*pzEnd != '\0')
  1465. goto bad_value;
  1466. for (ix = 0; ix < 1; ix++) {
  1467. if (val < rng[ix].rmin)
  1468. continue; /* ranges need not be ordered. */
  1469. if (val == rng[ix].rmin)
  1470. goto valid_return;
  1471. if (rng[ix].rmax == LONG_MIN)
  1472. continue;
  1473. if (val <= rng[ix].rmax)
  1474. goto valid_return;
  1475. }
  1476. bad_value:
  1477. option_usage_fp = stderr;
  1478. emit_ranges:
  1479. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1480. return;
  1481. valid_return:
  1482. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1483. free((void *)pOptDesc->optArg.argString);
  1484. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1485. }
  1486. pOptDesc->optArg.argInt = val;
  1487. }
  1488. #endif /* defined DEBUG */
  1489. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1490. *
  1491. * For the cachefile option.
  1492. */
  1493. static void
  1494. doOptCachefile(tOptions* pOptions, tOptDesc* pOptDesc)
  1495. {
  1496. /* extracted from tcprewrite_opts.def, line 128 */
  1497. options.cache_packets =
  1498. read_cache(&options.cachedata, OPT_ARG(CACHEFILE), &options.comment);
  1499. }
  1500. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1501. *
  1502. * For the version option.
  1503. */
  1504. static void
  1505. doOptVersion(tOptions* pOptions, tOptDesc* pOptDesc)
  1506. {
  1507. /* extracted from tcprewrite_opts.def, line 219 */
  1508. fprintf(stderr, "tcprewrite version: %s (build %s)", VERSION, svn_version());
  1509. #ifdef DEBUG
  1510. fprintf(stderr, " (debug)");
  1511. #endif
  1512. fprintf(stderr, "\n");
  1513. fprintf(stderr, "Copyright 2000-2010 by Aaron Turner <aturner at synfin dot net>\n");
  1514. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  1515. #ifdef HAVE_LIBDNET
  1516. fprintf(stderr, "Compiled against libdnet: %s\n", LIBDNET_VERSION);
  1517. #else
  1518. fprintf(stderr, "Not compiled with libdnet.\n");
  1519. #endif
  1520. #ifdef HAVE_WINPCAP
  1521. fprintf(stderr, "Compiled against winpcap: %s\n", get_pcap_version());
  1522. #else
  1523. fprintf(stderr, "Compiled against libpcap: %s\n", get_pcap_version());
  1524. #endif
  1525. #ifdef ENABLE_64BITS
  1526. fprintf(stderr, "64 bit packet counters: enabled\n");
  1527. #else
  1528. fprintf(stderr, "64 bit packet counters: disabled\n");
  1529. #endif
  1530. #ifdef ENABLE_VERBOSE
  1531. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  1532. #else
  1533. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  1534. #endif
  1535. #ifdef ENABLE_FRAGROUTE
  1536. fprintf(stderr, "Fragroute engine: enabled\n");
  1537. #else
  1538. fprintf(stderr, "Fragroute engine: disabled\n");
  1539. #endif
  1540. exit(0);
  1541. }
  1542. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1543. *
  1544. * For the less-help option.
  1545. */
  1546. static void
  1547. doOptLess_Help(tOptions* pOptions, tOptDesc* pOptDesc)
  1548. {
  1549. /* extracted from tcprewrite_opts.def, line 264 */
  1550. USAGE(EXIT_FAILURE);
  1551. }
  1552. /* extracted from /usr/local/share/autogen/optcode.tpl near line 633 */
  1553. #if ENABLE_NLS
  1554. #include <stdio.h>
  1555. #include <stdlib.h>
  1556. #include <string.h>
  1557. #include <unistd.h>
  1558. #include <autoopts/usage-txt.h>
  1559. static char* AO_gettext( char const* pz );
  1560. static void coerce_it(void** s);
  1561. static char*
  1562. AO_gettext( char const* pz )
  1563. {
  1564. char* pzRes;
  1565. if (pz == NULL)
  1566. return NULL;
  1567. pzRes = _(pz);
  1568. if (pzRes == pz)
  1569. return pzRes;
  1570. pzRes = strdup( pzRes );
  1571. if (pzRes == NULL) {
  1572. fputs( _("No memory for duping translated strings\n"), stderr );
  1573. exit( EXIT_FAILURE );
  1574. }
  1575. return pzRes;
  1576. }
  1577. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  1578. #define COERSION(_f) \
  1579. coerce_it((void*)&(tcprewriteOptions._f))
  1580. /*
  1581. * This invokes the translation code (e.g. gettext(3)).
  1582. */
  1583. static void
  1584. translate_option_strings( void )
  1585. {
  1586. /*
  1587. * Guard against re-translation. It won't work. The strings will have
  1588. * been changed by the first pass through this code. One shot only.
  1589. */
  1590. if (option_usage_text.field_ct != 0) {
  1591. /*
  1592. * Do the translations. The first pointer follows the field count
  1593. * field. The field count field is the size of a pointer.
  1594. */
  1595. tOptDesc* pOD = tcprewriteOptions.pOptDesc;
  1596. char** ppz = (char**)(void*)&(option_usage_text);
  1597. int ix = option_usage_text.field_ct;
  1598. do {
  1599. ppz++;
  1600. *ppz = AO_gettext(*ppz);
  1601. } while (--ix > 0);
  1602. COERSION(pzCopyright);
  1603. COERSION(pzCopyNotice);
  1604. COERSION(pzFullVersion);
  1605. COERSION(pzUsageTitle);
  1606. COERSION(pzExplain);
  1607. COERSION(pzDetail);
  1608. option_usage_text.field_ct = 0;
  1609. for (ix = tcprewriteOptions.optCt; ix > 0; ix--, pOD++)
  1610. coerce_it((void*)&(pOD->pzText));
  1611. }
  1612. if ((tcprewriteOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
  1613. tOptDesc* pOD = tcprewriteOptions.pOptDesc;
  1614. int ix;
  1615. for (ix = tcprewriteOptions.optCt; ix > 0; ix--, pOD++) {
  1616. coerce_it((void*)&(pOD->pz_Name));
  1617. coerce_it((void*)&(pOD->pz_DisableName));
  1618. coerce_it((void*)&(pOD->pz_DisablePfx));
  1619. }
  1620. /* prevent re-translation */
  1621. tcprewriteOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
  1622. }
  1623. }
  1624. #endif /* ENABLE_NLS */
  1625. #ifdef __cplusplus
  1626. }
  1627. #endif
  1628. /* tcprewrite_opts.c ends here */