tcpbridge_opts.c 44 KB

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