tcpbridge_opts.c 45 KB

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