tcpbridge_opts.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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 Thursday July 28, 2005 at 09:57:20 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. * Dbug option description:
  63. */
  64. tSCC zDbugText[] =
  65. "Enable debugging output";
  66. tSCC zDbug_NAME[] = "DBUG";
  67. tSCC zDbug_Name[] = "dbug";
  68. #define zDbugDefaultArg ((tCC*)0)
  69. #define DBUG_FLAGS (OPTST_DISABLED \
  70. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  71. /*
  72. * Verbose option description:
  73. */
  74. #ifdef HAVE_TCPDUMP
  75. tSCC zVerboseText[] =
  76. "Print decoded packets via tcpdump to STDOUT";
  77. tSCC zVerbose_NAME[] = "VERBOSE";
  78. tSCC zVerbose_Name[] = "verbose";
  79. #define VERBOSE_FLAGS (OPTST_DISABLED)
  80. #else /* disable Verbose */
  81. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  82. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  83. #define zVerboseText NULL
  84. #define zVerbose_NAME NULL
  85. #define zVerbose_Name NULL
  86. #endif /* HAVE_TCPDUMP */
  87. /*
  88. * Decode option description with
  89. * "Must also have options" and "Incompatible options":
  90. */
  91. #ifdef HAVE_TCPDUMP
  92. tSCC zDecodeText[] =
  93. "Arguments passed to tcpdump decoder";
  94. tSCC zDecode_NAME[] = "DECODE";
  95. tSCC zDecode_Name[] = "decode";
  96. static const int
  97. aDecodeMustList[] = {
  98. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  99. #define DECODE_FLAGS (OPTST_DISABLED \
  100. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  101. #else /* disable Decode */
  102. #define VALUE_OPT_DECODE NO_EQUIVALENT
  103. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  104. #define aDecodeMustList NULL
  105. #define zDecodeText NULL
  106. #define zDecode_NAME NULL
  107. #define zDecode_Name NULL
  108. #endif /* HAVE_TCPDUMP */
  109. /*
  110. * Intf1 option description:
  111. */
  112. tSCC zIntf1Text[] =
  113. "Primary interface (listen in uni-directional mode)";
  114. tSCC zIntf1_NAME[] = "INTF1";
  115. tSCC zIntf1_Name[] = "intf1";
  116. #define INTF1_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
  117. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  118. /*
  119. * Intf2 option description:
  120. */
  121. tSCC zIntf2Text[] =
  122. "Secondary interface (send in uni-directional mode)";
  123. tSCC zIntf2_NAME[] = "INTF2";
  124. tSCC zIntf2_Name[] = "intf2";
  125. #define INTF2_FLAGS (OPTST_DISABLED \
  126. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  127. /*
  128. * Unidir option description:
  129. */
  130. tSCC zUnidirText[] =
  131. "Send and receive in only one direction";
  132. tSCC zUnidir_NAME[] = "UNIDIR";
  133. tSCC zUnidir_Name[] = "unidir";
  134. #define UNIDIR_FLAGS (OPTST_DISABLED)
  135. /*
  136. * Dmac option description:
  137. */
  138. tSCC zDmacText[] =
  139. "Rewrite destination MAC addresses";
  140. tSCC zDmac_NAME[] = "DMAC";
  141. tSCC zDmac_Name[] = "dmac";
  142. #define DMAC_FLAGS (OPTST_DISABLED \
  143. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  144. /*
  145. * Smac option description:
  146. */
  147. tSCC zSmacText[] =
  148. "Rewrite source MAC addresses";
  149. tSCC zSmac_NAME[] = "SMAC";
  150. tSCC zSmac_Name[] = "smac";
  151. #define SMAC_FLAGS (OPTST_DISABLED \
  152. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  153. /*
  154. * Limit option description:
  155. */
  156. tSCC zLimitText[] =
  157. "Limit the number of packets to send";
  158. tSCC zLimit_NAME[] = "LIMIT";
  159. tSCC zLimit_Name[] = "limit";
  160. #define zLimitDefaultArg ((tCC*)-1)
  161. #define LIMIT_FLAGS (OPTST_DISABLED \
  162. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  163. /*
  164. * Include option description with
  165. * "Must also have options" and "Incompatible options":
  166. */
  167. tSCC zIncludeText[] =
  168. "Include only packets matching rule";
  169. tSCC zInclude_NAME[] = "INCLUDE";
  170. tSCC zInclude_Name[] = "include";
  171. static const int
  172. aIncludeCantList[] = {
  173. INDEX_OPT_EXCLUDE, NO_EQUIVALENT };
  174. #define INCLUDE_FLAGS (OPTST_DISABLED \
  175. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  176. /*
  177. * Exclude option description with
  178. * "Must also have options" and "Incompatible options":
  179. */
  180. tSCC zExcludeText[] =
  181. "Exclude any packet matching this rule";
  182. tSCC zExclude_NAME[] = "EXCLUDE";
  183. tSCC zExclude_Name[] = "exclude";
  184. static const int
  185. aExcludeCantList[] = {
  186. INDEX_OPT_INCLUDE, NO_EQUIVALENT };
  187. #define EXCLUDE_FLAGS (OPTST_DISABLED \
  188. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  189. /*
  190. * Vlan option description:
  191. */
  192. tSCC zVlanText[] =
  193. "Specify 802.1q VLAN tag mode";
  194. tSCC zVlan_NAME[] = "VLAN";
  195. tSCC zVlan_Name[] = "vlan";
  196. #define VLAN_FLAGS (OPTST_DISABLED \
  197. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  198. /*
  199. * Vlan_Tag option description with
  200. * "Must also have options" and "Incompatible options":
  201. */
  202. tSCC zVlan_TagText[] =
  203. "Specify the new 802.1q VLAN tag value";
  204. tSCC zVlan_Tag_NAME[] = "VLAN_TAG";
  205. tSCC zVlan_Tag_Name[] = "vlan-tag";
  206. static const int
  207. aVlan_TagMustList[] = {
  208. INDEX_OPT_VLAN, NO_EQUIVALENT };
  209. #define VLAN_TAG_FLAGS (OPTST_DISABLED \
  210. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  211. /*
  212. * Vlan_Cfi option description with
  213. * "Must also have options" and "Incompatible options":
  214. */
  215. tSCC zVlan_CfiText[] =
  216. "Specify the 802.1q VLAN CFI value";
  217. tSCC zVlan_Cfi_NAME[] = "VLAN_CFI";
  218. tSCC zVlan_Cfi_Name[] = "vlan-cfi";
  219. static const int
  220. aVlan_CfiMustList[] = {
  221. INDEX_OPT_VLAN, NO_EQUIVALENT };
  222. #define VLAN_CFI_FLAGS (OPTST_DISABLED \
  223. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  224. /*
  225. * Vlan_Pri option description with
  226. * "Must also have options" and "Incompatible options":
  227. */
  228. tSCC zVlan_PriText[] =
  229. "Specify the 802.1q VLAN priority";
  230. tSCC zVlan_Pri_NAME[] = "VLAN_PRI";
  231. tSCC zVlan_Pri_Name[] = "vlan-pri";
  232. static const int
  233. aVlan_PriMustList[] = {
  234. INDEX_OPT_VLAN, NO_EQUIVALENT };
  235. #define VLAN_PRI_FLAGS (OPTST_DISABLED \
  236. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  237. /*
  238. * Pid option description:
  239. */
  240. tSCC zPidText[] =
  241. "Print the PID of tcpbridge at startup";
  242. tSCC zPid_NAME[] = "PID";
  243. tSCC zPid_Name[] = "pid";
  244. #define PID_FLAGS (OPTST_DISABLED)
  245. /*
  246. * Version option description:
  247. */
  248. tSCC zVersionText[] =
  249. "Print version information";
  250. tSCC zVersion_NAME[] = "VERSION";
  251. tSCC zVersion_Name[] = "version";
  252. #define VERSION_FLAGS (OPTST_DISABLED)
  253. /*
  254. * Less_Help option description:
  255. */
  256. tSCC zLess_HelpText[] =
  257. "Display less usage information and exit";
  258. tSCC zLess_Help_NAME[] = "LESS_HELP";
  259. tSCC zLess_Help_Name[] = "less-help";
  260. #define LESS_HELP_FLAGS (OPTST_DISABLED)
  261. /*
  262. * Help/More_Help option descriptions:
  263. */
  264. tSCC zHelpText[] = "Display usage information and exit";
  265. tSCC zHelp_Name[] = "help";
  266. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  267. tSCC zMore_Help_Name[] = "more-help";
  268. /*
  269. * Save/Load_Opts option description:
  270. */
  271. tSCC zSave_OptsText[] = "Save the option state to a config file";
  272. tSCC zSave_Opts_Name[] = "save-opts";
  273. tSCC zLoad_OptsText[] = "Load options from a config file";
  274. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  275. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  276. tSCC zNotLoad_Opts_Pfx[] = "no";
  277. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  278. /*
  279. * Declare option callback procedures
  280. */
  281. extern tOptProc
  282. optionPagedUsage;
  283. static tOptProc
  284. doOptDbug, doOptDmac, doOptExclude, doOptInclude,
  285. doOptLess_Help, doOptLimit, doOptPid, doOptSmac,
  286. doOptVersion, doOptVlan, doOptVlan_Cfi, doOptVlan_Pri,
  287. doOptVlan_Tag, doUsageOpt;
  288. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  289. *
  290. * Define the Tcpbridge Option Descriptions.
  291. */
  292. static tOptDesc optDesc[ OPTION_CT ] = {
  293. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  294. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  295. /* equivalenced to */ NO_EQUIVALENT,
  296. /* min, max, act ct */ 0, 1, 0,
  297. /* opt state flags */ DBUG_FLAGS, 0,
  298. /* last opt argumnt */ zDbugDefaultArg,
  299. /* arg list/cookie */ NULL,
  300. /* must/cannot opts */ NULL, NULL,
  301. /* option proc */ doOptDbug,
  302. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  303. /* disablement strs */ NULL, NULL },
  304. { /* entry idx, value */ 1, VALUE_OPT_VERBOSE,
  305. /* equiv idx, value */ 1, VALUE_OPT_VERBOSE,
  306. /* equivalenced to */ NO_EQUIVALENT,
  307. /* min, max, act ct */ 0, 1, 0,
  308. /* opt state flags */ VERBOSE_FLAGS, 0,
  309. /* last opt argumnt */ NULL,
  310. /* arg list/cookie */ NULL,
  311. /* must/cannot opts */ NULL, NULL,
  312. /* option proc */ NULL,
  313. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  314. /* disablement strs */ NULL, NULL },
  315. { /* entry idx, value */ 2, VALUE_OPT_DECODE,
  316. /* equiv idx, value */ 2, VALUE_OPT_DECODE,
  317. /* equivalenced to */ NO_EQUIVALENT,
  318. /* min, max, act ct */ 0, 1, 0,
  319. /* opt state flags */ DECODE_FLAGS, 0,
  320. /* last opt argumnt */ NULL,
  321. /* arg list/cookie */ NULL,
  322. /* must/cannot opts */ aDecodeMustList, NULL,
  323. /* option proc */ NULL,
  324. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  325. /* disablement strs */ NULL, NULL },
  326. { /* entry idx, value */ 3, VALUE_OPT_INTF1,
  327. /* equiv idx, value */ 3, VALUE_OPT_INTF1,
  328. /* equivalenced to */ NO_EQUIVALENT,
  329. /* min, max, act ct */ 1, 1, 0,
  330. /* opt state flags */ INTF1_FLAGS, 0,
  331. /* last opt argumnt */ NULL,
  332. /* arg list/cookie */ NULL,
  333. /* must/cannot opts */ NULL, NULL,
  334. /* option proc */ NULL,
  335. /* desc, NAME, name */ zIntf1Text, zIntf1_NAME, zIntf1_Name,
  336. /* disablement strs */ NULL, NULL },
  337. { /* entry idx, value */ 4, VALUE_OPT_INTF2,
  338. /* equiv idx, value */ 4, VALUE_OPT_INTF2,
  339. /* equivalenced to */ NO_EQUIVALENT,
  340. /* min, max, act ct */ 0, 1, 0,
  341. /* opt state flags */ INTF2_FLAGS, 0,
  342. /* last opt argumnt */ NULL,
  343. /* arg list/cookie */ NULL,
  344. /* must/cannot opts */ NULL, NULL,
  345. /* option proc */ NULL,
  346. /* desc, NAME, name */ zIntf2Text, zIntf2_NAME, zIntf2_Name,
  347. /* disablement strs */ NULL, NULL },
  348. { /* entry idx, value */ 5, VALUE_OPT_UNIDIR,
  349. /* equiv idx, value */ 5, VALUE_OPT_UNIDIR,
  350. /* equivalenced to */ NO_EQUIVALENT,
  351. /* min, max, act ct */ 0, 1, 0,
  352. /* opt state flags */ UNIDIR_FLAGS, 0,
  353. /* last opt argumnt */ NULL,
  354. /* arg list/cookie */ NULL,
  355. /* must/cannot opts */ NULL, NULL,
  356. /* option proc */ NULL,
  357. /* desc, NAME, name */ zUnidirText, zUnidir_NAME, zUnidir_Name,
  358. /* disablement strs */ NULL, NULL },
  359. { /* entry idx, value */ 6, VALUE_OPT_DMAC,
  360. /* equiv idx, value */ 6, VALUE_OPT_DMAC,
  361. /* equivalenced to */ NO_EQUIVALENT,
  362. /* min, max, act ct */ 0, 1, 0,
  363. /* opt state flags */ DMAC_FLAGS, 0,
  364. /* last opt argumnt */ NULL,
  365. /* arg list/cookie */ NULL,
  366. /* must/cannot opts */ NULL, NULL,
  367. /* option proc */ doOptDmac,
  368. /* desc, NAME, name */ zDmacText, zDmac_NAME, zDmac_Name,
  369. /* disablement strs */ NULL, NULL },
  370. { /* entry idx, value */ 7, VALUE_OPT_SMAC,
  371. /* equiv idx, value */ 7, VALUE_OPT_SMAC,
  372. /* equivalenced to */ NO_EQUIVALENT,
  373. /* min, max, act ct */ 0, 1, 0,
  374. /* opt state flags */ SMAC_FLAGS, 0,
  375. /* last opt argumnt */ NULL,
  376. /* arg list/cookie */ NULL,
  377. /* must/cannot opts */ NULL, NULL,
  378. /* option proc */ doOptSmac,
  379. /* desc, NAME, name */ zSmacText, zSmac_NAME, zSmac_Name,
  380. /* disablement strs */ NULL, NULL },
  381. { /* entry idx, value */ 8, VALUE_OPT_LIMIT,
  382. /* equiv idx, value */ 8, VALUE_OPT_LIMIT,
  383. /* equivalenced to */ NO_EQUIVALENT,
  384. /* min, max, act ct */ 0, 1, 0,
  385. /* opt state flags */ LIMIT_FLAGS, 0,
  386. /* last opt argumnt */ zLimitDefaultArg,
  387. /* arg list/cookie */ NULL,
  388. /* must/cannot opts */ NULL, NULL,
  389. /* option proc */ doOptLimit,
  390. /* desc, NAME, name */ zLimitText, zLimit_NAME, zLimit_Name,
  391. /* disablement strs */ NULL, NULL },
  392. { /* entry idx, value */ 9, VALUE_OPT_INCLUDE,
  393. /* equiv idx, value */ 9, VALUE_OPT_INCLUDE,
  394. /* equivalenced to */ NO_EQUIVALENT,
  395. /* min, max, act ct */ 0, 1, 0,
  396. /* opt state flags */ INCLUDE_FLAGS, 0,
  397. /* last opt argumnt */ NULL,
  398. /* arg list/cookie */ NULL,
  399. /* must/cannot opts */ NULL, aIncludeCantList,
  400. /* option proc */ doOptInclude,
  401. /* desc, NAME, name */ zIncludeText, zInclude_NAME, zInclude_Name,
  402. /* disablement strs */ NULL, NULL },
  403. { /* entry idx, value */ 10, VALUE_OPT_EXCLUDE,
  404. /* equiv idx, value */ 10, VALUE_OPT_EXCLUDE,
  405. /* equivalenced to */ NO_EQUIVALENT,
  406. /* min, max, act ct */ 0, 1, 0,
  407. /* opt state flags */ EXCLUDE_FLAGS, 0,
  408. /* last opt argumnt */ NULL,
  409. /* arg list/cookie */ NULL,
  410. /* must/cannot opts */ NULL, aExcludeCantList,
  411. /* option proc */ doOptExclude,
  412. /* desc, NAME, name */ zExcludeText, zExclude_NAME, zExclude_Name,
  413. /* disablement strs */ NULL, NULL },
  414. { /* entry idx, value */ 11, VALUE_OPT_VLAN,
  415. /* equiv idx, value */ 11, VALUE_OPT_VLAN,
  416. /* equivalenced to */ NO_EQUIVALENT,
  417. /* min, max, act ct */ 0, 1, 0,
  418. /* opt state flags */ VLAN_FLAGS, 0,
  419. /* last opt argumnt */ NULL,
  420. /* arg list/cookie */ NULL,
  421. /* must/cannot opts */ NULL, NULL,
  422. /* option proc */ doOptVlan,
  423. /* desc, NAME, name */ zVlanText, zVlan_NAME, zVlan_Name,
  424. /* disablement strs */ NULL, NULL },
  425. { /* entry idx, value */ 12, VALUE_OPT_VLAN_TAG,
  426. /* equiv idx, value */ 12, VALUE_OPT_VLAN_TAG,
  427. /* equivalenced to */ NO_EQUIVALENT,
  428. /* min, max, act ct */ 0, 1, 0,
  429. /* opt state flags */ VLAN_TAG_FLAGS, 0,
  430. /* last opt argumnt */ NULL,
  431. /* arg list/cookie */ NULL,
  432. /* must/cannot opts */ aVlan_TagMustList, NULL,
  433. /* option proc */ doOptVlan_Tag,
  434. /* desc, NAME, name */ zVlan_TagText, zVlan_Tag_NAME, zVlan_Tag_Name,
  435. /* disablement strs */ NULL, NULL },
  436. { /* entry idx, value */ 13, VALUE_OPT_VLAN_CFI,
  437. /* equiv idx, value */ 13, VALUE_OPT_VLAN_CFI,
  438. /* equivalenced to */ NO_EQUIVALENT,
  439. /* min, max, act ct */ 0, 1, 0,
  440. /* opt state flags */ VLAN_CFI_FLAGS, 0,
  441. /* last opt argumnt */ NULL,
  442. /* arg list/cookie */ NULL,
  443. /* must/cannot opts */ aVlan_CfiMustList, NULL,
  444. /* option proc */ doOptVlan_Cfi,
  445. /* desc, NAME, name */ zVlan_CfiText, zVlan_Cfi_NAME, zVlan_Cfi_Name,
  446. /* disablement strs */ NULL, NULL },
  447. { /* entry idx, value */ 14, VALUE_OPT_VLAN_PRI,
  448. /* equiv idx, value */ 14, VALUE_OPT_VLAN_PRI,
  449. /* equivalenced to */ NO_EQUIVALENT,
  450. /* min, max, act ct */ 0, 1, 0,
  451. /* opt state flags */ VLAN_PRI_FLAGS, 0,
  452. /* last opt argumnt */ NULL,
  453. /* arg list/cookie */ NULL,
  454. /* must/cannot opts */ aVlan_PriMustList, NULL,
  455. /* option proc */ doOptVlan_Pri,
  456. /* desc, NAME, name */ zVlan_PriText, zVlan_Pri_NAME, zVlan_Pri_Name,
  457. /* disablement strs */ NULL, NULL },
  458. { /* entry idx, value */ 15, VALUE_OPT_PID,
  459. /* equiv idx, value */ 15, VALUE_OPT_PID,
  460. /* equivalenced to */ NO_EQUIVALENT,
  461. /* min, max, act ct */ 0, 1, 0,
  462. /* opt state flags */ PID_FLAGS, 0,
  463. /* last opt argumnt */ NULL,
  464. /* arg list/cookie */ NULL,
  465. /* must/cannot opts */ NULL, NULL,
  466. /* option proc */ doOptPid,
  467. /* desc, NAME, name */ zPidText, zPid_NAME, zPid_Name,
  468. /* disablement strs */ NULL, NULL },
  469. { /* entry idx, value */ 16, VALUE_OPT_VERSION,
  470. /* equiv idx, value */ 16, VALUE_OPT_VERSION,
  471. /* equivalenced to */ NO_EQUIVALENT,
  472. /* min, max, act ct */ 0, 1, 0,
  473. /* opt state flags */ VERSION_FLAGS, 0,
  474. /* last opt argumnt */ NULL,
  475. /* arg list/cookie */ NULL,
  476. /* must/cannot opts */ NULL, NULL,
  477. /* option proc */ doOptVersion,
  478. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  479. /* disablement strs */ NULL, NULL },
  480. { /* entry idx, value */ 17, VALUE_OPT_LESS_HELP,
  481. /* equiv idx, value */ 17, VALUE_OPT_LESS_HELP,
  482. /* equivalenced to */ NO_EQUIVALENT,
  483. /* min, max, act ct */ 0, 1, 0,
  484. /* opt state flags */ LESS_HELP_FLAGS, 0,
  485. /* last opt argumnt */ NULL,
  486. /* arg list/cookie */ NULL,
  487. /* must/cannot opts */ NULL, NULL,
  488. /* option proc */ doOptLess_Help,
  489. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  490. /* disablement strs */ NULL, NULL },
  491. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  492. /* equiv idx value */ NO_EQUIVALENT, 0,
  493. /* equivalenced to */ NO_EQUIVALENT,
  494. /* min, max, act ct */ 0, 1, 0,
  495. /* opt state flags */ OPTST_IMM, 0,
  496. /* last opt argumnt */ NULL,
  497. /* arg list/cookie */ NULL,
  498. /* must/cannot opts */ NULL, NULL,
  499. /* option proc */ doUsageOpt,
  500. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  501. /* disablement strs */ NULL, NULL },
  502. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  503. /* equiv idx value */ NO_EQUIVALENT, 0,
  504. /* equivalenced to */ NO_EQUIVALENT,
  505. /* min, max, act ct */ 0, 1, 0,
  506. /* opt state flags */ OPTST_IMM, 0,
  507. /* last opt argumnt */ NULL,
  508. /* arg list/cookie */ NULL,
  509. /* must/cannot opts */ NULL, NULL,
  510. /* option proc */ optionPagedUsage,
  511. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  512. /* disablement strs */ NULL, NULL },
  513. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  514. /* equiv idx value */ NO_EQUIVALENT, 0,
  515. /* equivalenced to */ NO_EQUIVALENT,
  516. /* min, max, act ct */ 0, 1, 0,
  517. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  518. | OPTST_ARG_OPTIONAL, 0,
  519. /* last opt argumnt */ NULL,
  520. /* arg list/cookie */ NULL,
  521. /* must/cannot opts */ NULL, NULL,
  522. /* option proc */ NULL,
  523. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  524. /* disablement strs */ NULL, NULL },
  525. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  526. /* equiv idx value */ NO_EQUIVALENT, 0,
  527. /* equivalenced to */ NO_EQUIVALENT,
  528. /* min, max, act ct */ 0, NOLIMIT, 0,
  529. /* opt state flags */ OPTST_DISABLE_IMM | \
  530. OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
  531. /* last opt argumnt */ NULL,
  532. /* arg list/cookie */ NULL,
  533. /* must/cannot opts */ NULL, NULL,
  534. /* option proc */ optionLoadOpt,
  535. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  536. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  537. };
  538. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  539. *
  540. * Define the Tcpbridge Option Environment
  541. */
  542. tSCC zPROGNAME[] = "TCPBRIDGE";
  543. tSCC zUsageTitle[] =
  544. "tcpbridge - Bridge network traffic across two interfaces\n\
  545. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  546. tSCC zRcName[] = ".tcpbridgerc";
  547. tSCC* apzHomeList[] = {
  548. "$$/",
  549. NULL };
  550. #define zBugsAddr NULL
  551. tSCC zExplain[] = "\n\
  552. tcpbridge is a tool for briding network traffic across two interfaces\n\
  553. and optionally modifying the packets in betweeen\n";
  554. tSCC zDetail[] = "\n\
  555. The basic operation of tcpbridge is to be a network bridge between two\n\
  556. subnets. All packets recieved on one interface are sent via the other.\n\n\
  557. Optionally, packets can be edited in a variety of ways according to your needs.\n";
  558. #define zFullVersion NULL
  559. /* extracted from /usr/local/share/autogen/optcode.tpl near line 309 */
  560. #if defined(ENABLE_NLS)
  561. # define OPTPROC_BASE OPTPROC_TRANSLATE
  562. static tOptionXlateProc translate_option_strings;
  563. #else
  564. # define OPTPROC_BASE OPTPROC_NONE
  565. # define translate_option_strings NULL
  566. #endif /* ENABLE_NLS */
  567. tOptions tcpbridgeOptions = {
  568. OPTIONS_STRUCT_VERSION,
  569. 0, NULL, /* original argc + argv */
  570. ( OPTPROC_BASE
  571. + OPTPROC_ERRSTOP
  572. + OPTPROC_SHORTOPT
  573. + OPTPROC_LONGOPT
  574. + OPTPROC_NO_REQ_OPT
  575. + OPTPROC_NO_ARGS
  576. + OPTPROC_GNUUSAGE
  577. + OPTPROC_HAS_IMMED ),
  578. 0, NULL, /* current option index, current option */
  579. NULL, NULL, zPROGNAME,
  580. zRcName, zCopyright, zCopyrightNotice,
  581. zFullVersion, apzHomeList, zUsageTitle,
  582. zExplain, zDetail, optDesc,
  583. zBugsAddr, /* address to send bugs to */
  584. NULL, NULL, /* extensions/saved state */
  585. optionUsage, /* usage procedure */
  586. translate_option_strings, /* translation procedure */
  587. /*
  588. * Indexes to special options
  589. */
  590. { INDEX_OPT_MORE_HELP,
  591. INDEX_OPT_SAVE_OPTS,
  592. NO_EQUIVALENT /* index of '-#' option */,
  593. NO_EQUIVALENT /* index of default opt */
  594. },
  595. OPTION_CT, 18 /* user option count */
  596. };
  597. /*
  598. * Create the static procedure(s) declared above.
  599. */
  600. static void
  601. doUsageOpt(
  602. tOptions* pOptions,
  603. tOptDesc* pOptDesc )
  604. {
  605. USAGE( EXIT_SUCCESS );
  606. }
  607. /* * * * * * *
  608. *
  609. * For the dbug option.
  610. */
  611. static void
  612. doOptDbug(
  613. tOptions* pOptions,
  614. tOptDesc* pOptDesc )
  615. {
  616. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  617. { 0, 5 } };
  618. long val;
  619. int ix;
  620. tCC* pzIndent = "\t\t\t\t ";
  621. extern FILE* option_usage_fp;
  622. if (pOptDesc == NULL) /* usage is requesting range list
  623. option_usage_fp has already been set */
  624. goto emit_ranges;
  625. val = atoi( pOptDesc->pzLastArg );
  626. for (ix = 0; ix < 1; ix++) {
  627. if (val < rng[ix].rmin)
  628. continue; /* ranges need not be ordered. */
  629. if (val == rng[ix].rmin)
  630. goto valid_return;
  631. if (rng[ix].rmax == INT_MIN)
  632. continue;
  633. if (val <= rng[ix].rmax)
  634. goto valid_return;
  635. }
  636. option_usage_fp = stderr;
  637. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  638. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  639. pzIndent = "\t";
  640. emit_ranges:
  641. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  642. pzIndent, rng[0].rmin, rng[0].rmax );
  643. if (pOptDesc == NULL)
  644. return;
  645. USAGE( EXIT_FAILURE );
  646. /* NOTREACHED */
  647. return;
  648. valid_return:
  649. pOptDesc->pzLastArg = (char*)val;
  650. }
  651. /* * * * * * *
  652. *
  653. * For the dmac option.
  654. */
  655. static void
  656. doOptDmac(
  657. tOptions* pOptions,
  658. tOptDesc* pOptDesc )
  659. {
  660. int mask = 0;
  661. mask = dualmac2hex(OPT_ARG(DMAC), options.intf1_dmac, options.intf2_dmac,
  662. strlen(OPT_ARG(DMAC)));
  663. options.mac_mask ^= (mask << 2);
  664. }
  665. /* * * * * * *
  666. *
  667. * For the smac option.
  668. */
  669. static void
  670. doOptSmac(
  671. tOptions* pOptions,
  672. tOptDesc* pOptDesc )
  673. {
  674. int mask = 0;
  675. mask = dualmac2hex(OPT_ARG(SMAC), options.intf1_smac, options.intf2_smac,
  676. strlen(OPT_ARG(SMAC)));
  677. options.mac_mask ^= mask;
  678. }
  679. /* * * * * * *
  680. *
  681. * For the limit option.
  682. */
  683. static void
  684. doOptLimit(
  685. tOptions* pOptions,
  686. tOptDesc* pOptDesc )
  687. {
  688. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  689. { 0, INT_MAX } };
  690. long val;
  691. int ix;
  692. tCC* pzIndent = "\t\t\t\t ";
  693. extern FILE* option_usage_fp;
  694. if (pOptDesc == NULL) /* usage is requesting range list
  695. option_usage_fp has already been set */
  696. goto emit_ranges;
  697. val = atoi( pOptDesc->pzLastArg );
  698. for (ix = 0; ix < 1; ix++) {
  699. if (val < rng[ix].rmin)
  700. continue; /* ranges need not be ordered. */
  701. if (val == rng[ix].rmin)
  702. goto valid_return;
  703. if (rng[ix].rmax == INT_MIN)
  704. continue;
  705. if (val <= rng[ix].rmax)
  706. goto valid_return;
  707. }
  708. option_usage_fp = stderr;
  709. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  710. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  711. pzIndent = "\t";
  712. emit_ranges:
  713. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  714. pzIndent, rng[0].rmin, rng[0].rmax );
  715. if (pOptDesc == NULL)
  716. return;
  717. USAGE( EXIT_FAILURE );
  718. /* NOTREACHED */
  719. return;
  720. valid_return:
  721. pOptDesc->pzLastArg = (char*)val;
  722. }
  723. /* * * * * * *
  724. *
  725. * For the include option.
  726. */
  727. static void
  728. doOptInclude(
  729. tOptions* pOptions,
  730. tOptDesc* pOptDesc )
  731. {
  732. char *include;
  733. include = safe_strdup(OPT_ARG(INCLUDE));
  734. options.xX.mode = xX_MODE_INCLUDE;
  735. if ((options.xX.mode = parse_xX_str(&options.xX, include, &options.bpf)) == 0)
  736. errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(INCLUDE));
  737. free(include);
  738. }
  739. /* * * * * * *
  740. *
  741. * For the exclude option.
  742. */
  743. static void
  744. doOptExclude(
  745. tOptions* pOptions,
  746. tOptDesc* pOptDesc )
  747. {
  748. char *exclude;
  749. exclude = safe_strdup(OPT_ARG(EXCLUDE));
  750. options.xX.mode = xX_MODE_EXCLUDE;
  751. if ((options.xX.mode = parse_xX_str(&options.xX, exclude, &options.bpf)) == 0)
  752. errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(EXCLUDE));
  753. free(exclude);
  754. }
  755. /* * * * * * *
  756. *
  757. * For the vlan option.
  758. */
  759. static void
  760. doOptVlan(
  761. tOptions* pOptions,
  762. tOptDesc* pOptDesc )
  763. {
  764. if (strcmp(OPT_ARG(VLAN), "add") == 0) {
  765. options.vlan = VLAN_ADD;
  766. } else if (strcmp(OPT_ARG(VLAN), "del") == 0) {
  767. options.vlan = VLAN_DEL;
  768. } else {
  769. errx(1, "Invalid vlan argument '%s'. Must be 'add' or 'del'", OPT_ARG(VLAN));
  770. }
  771. }
  772. /* * * * * * *
  773. *
  774. * For the vlan_tag option.
  775. */
  776. static void
  777. doOptVlan_Tag(
  778. tOptions* pOptions,
  779. tOptDesc* pOptDesc )
  780. {
  781. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  782. { 0, 4095 } };
  783. long val;
  784. int ix;
  785. tCC* pzIndent = "\t\t\t\t ";
  786. extern FILE* option_usage_fp;
  787. if (pOptDesc == NULL) /* usage is requesting range list
  788. option_usage_fp has already been set */
  789. goto emit_ranges;
  790. val = atoi( pOptDesc->pzLastArg );
  791. for (ix = 0; ix < 1; ix++) {
  792. if (val < rng[ix].rmin)
  793. continue; /* ranges need not be ordered. */
  794. if (val == rng[ix].rmin)
  795. goto valid_return;
  796. if (rng[ix].rmax == INT_MIN)
  797. continue;
  798. if (val <= rng[ix].rmax)
  799. goto valid_return;
  800. }
  801. option_usage_fp = stderr;
  802. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  803. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  804. pzIndent = "\t";
  805. emit_ranges:
  806. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  807. pzIndent, rng[0].rmin, rng[0].rmax );
  808. if (pOptDesc == NULL)
  809. return;
  810. USAGE( EXIT_FAILURE );
  811. /* NOTREACHED */
  812. return;
  813. valid_return:
  814. pOptDesc->pzLastArg = (char*)val;
  815. }
  816. /* * * * * * *
  817. *
  818. * For the vlan_cfi option.
  819. */
  820. static void
  821. doOptVlan_Cfi(
  822. tOptions* pOptions,
  823. tOptDesc* pOptDesc )
  824. {
  825. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  826. { 0, 1 } };
  827. long val;
  828. int ix;
  829. tCC* pzIndent = "\t\t\t\t ";
  830. extern FILE* option_usage_fp;
  831. if (pOptDesc == NULL) /* usage is requesting range list
  832. option_usage_fp has already been set */
  833. goto emit_ranges;
  834. val = atoi( pOptDesc->pzLastArg );
  835. for (ix = 0; ix < 1; ix++) {
  836. if (val < rng[ix].rmin)
  837. continue; /* ranges need not be ordered. */
  838. if (val == rng[ix].rmin)
  839. goto valid_return;
  840. if (rng[ix].rmax == INT_MIN)
  841. continue;
  842. if (val <= rng[ix].rmax)
  843. goto valid_return;
  844. }
  845. option_usage_fp = stderr;
  846. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  847. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  848. pzIndent = "\t";
  849. emit_ranges:
  850. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  851. pzIndent, rng[0].rmin, rng[0].rmax );
  852. if (pOptDesc == NULL)
  853. return;
  854. USAGE( EXIT_FAILURE );
  855. /* NOTREACHED */
  856. return;
  857. valid_return:
  858. pOptDesc->pzLastArg = (char*)val;
  859. }
  860. /* * * * * * *
  861. *
  862. * For the vlan_pri option.
  863. */
  864. static void
  865. doOptVlan_Pri(
  866. tOptions* pOptions,
  867. tOptDesc* pOptDesc )
  868. {
  869. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  870. { 0, 7 } };
  871. long val;
  872. int ix;
  873. tCC* pzIndent = "\t\t\t\t ";
  874. extern FILE* option_usage_fp;
  875. if (pOptDesc == NULL) /* usage is requesting range list
  876. option_usage_fp has already been set */
  877. goto emit_ranges;
  878. val = atoi( pOptDesc->pzLastArg );
  879. for (ix = 0; ix < 1; ix++) {
  880. if (val < rng[ix].rmin)
  881. continue; /* ranges need not be ordered. */
  882. if (val == rng[ix].rmin)
  883. goto valid_return;
  884. if (rng[ix].rmax == INT_MIN)
  885. continue;
  886. if (val <= rng[ix].rmax)
  887. goto valid_return;
  888. }
  889. option_usage_fp = stderr;
  890. fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  891. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
  892. pzIndent = "\t";
  893. emit_ranges:
  894. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  895. pzIndent, rng[0].rmin, rng[0].rmax );
  896. if (pOptDesc == NULL)
  897. return;
  898. USAGE( EXIT_FAILURE );
  899. /* NOTREACHED */
  900. return;
  901. valid_return:
  902. pOptDesc->pzLastArg = (char*)val;
  903. }
  904. /* * * * * * *
  905. *
  906. * For the pid option.
  907. */
  908. static void
  909. doOptPid(
  910. tOptions* pOptions,
  911. tOptDesc* pOptDesc )
  912. {
  913. fprintf(stderr, "PID: %hu\n", getpid());
  914. }
  915. /* * * * * * *
  916. *
  917. * For the version option.
  918. */
  919. static void
  920. doOptVersion(
  921. tOptions* pOptions,
  922. tOptDesc* pOptDesc )
  923. {
  924. fprintf(stderr, "tcpbridge version: %s (build %s)", VERSION, svn_version());
  925. #ifdef DEBUG
  926. fprintf(stderr, " (debug)");
  927. #endif
  928. fprintf(stderr, "\n");
  929. fprintf(stderr, "Copyright 2001-2005 by Aaron Turner <aturner@pobox.com>\n");
  930. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  931. fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
  932. #ifdef ENABLE_64BITS
  933. fprintf(stderr, "64 bit packet counters: enabled\n");
  934. #else
  935. fprintf(stderr, "64 bit packet counters: disabled\n");
  936. #endif
  937. #ifdef HAVE_TCPDUMP
  938. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  939. #else
  940. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  941. #endif
  942. exit(0);
  943. }
  944. /* * * * * * *
  945. *
  946. * For the less-help option.
  947. */
  948. static void
  949. doOptLess_Help(
  950. tOptions* pOptions,
  951. tOptDesc* pOptDesc )
  952. {
  953. USAGE(EXIT_FAILURE);
  954. }
  955. /* extracted from /usr/local/share/autogen/optcode.tpl near line 396 */
  956. #if ENABLE_NLS
  957. #include <string.h>
  958. #include <stdio.h>
  959. #include <autoopts/usage-txt.h>
  960. static char*
  961. AO_gettext( const char* pz )
  962. {
  963. char* pzRes;
  964. if (pz == NULL)
  965. return NULL;
  966. pzRes = _(pz);
  967. if (pzRes == pz)
  968. return pzRes;
  969. pzRes = strdup( pzRes );
  970. if (pzRes == NULL) {
  971. fputs( _("No memory for duping translated strings\n"), stderr );
  972. exit( EXIT_FAILURE );
  973. }
  974. return pzRes;
  975. }
  976. /*
  977. * This invokes the translation code (e.g. gettext(3)).
  978. */
  979. static void
  980. translate_option_strings( void )
  981. {
  982. /*
  983. * Guard against re-translation. It won't work. The strings will have
  984. * been changed by the first pass through this code. One shot only.
  985. */
  986. if (option_usage_text.field_ct == 0)
  987. return;
  988. /*
  989. * Do the translations. The first pointer follows the field count field.
  990. * The field count field is the size of a pointer.
  991. */
  992. {
  993. char** ppz = (char**)(void*)&(option_usage_text);
  994. int ix = option_usage_text.field_ct;
  995. do {
  996. ppz++;
  997. *ppz = AO_gettext(*ppz);
  998. } while (--ix > 0);
  999. }
  1000. option_usage_text.field_ct = 0;
  1001. {
  1002. tOptDesc* pOD = tcpbridgeOptions.pOptDesc;
  1003. int ix = tcpbridgeOptions.optCt;
  1004. for (;;) {
  1005. pOD->pzText = AO_gettext(pOD->pzText);
  1006. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  1007. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  1008. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  1009. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  1010. if (--ix <= 0)
  1011. break;
  1012. pOD++;
  1013. }
  1014. }
  1015. tcpbridgeOptions.pzCopyright = AO_gettext(tcpbridgeOptions.pzCopyright);
  1016. tcpbridgeOptions.pzCopyNotice = AO_gettext(tcpbridgeOptions.pzCopyNotice);
  1017. tcpbridgeOptions.pzFullVersion = AO_gettext(tcpbridgeOptions.pzFullVersion);
  1018. tcpbridgeOptions.pzUsageTitle = AO_gettext(tcpbridgeOptions.pzUsageTitle);
  1019. tcpbridgeOptions.pzExplain = AO_gettext(tcpbridgeOptions.pzExplain);
  1020. tcpbridgeOptions.pzDetail = AO_gettext(tcpbridgeOptions.pzDetail);
  1021. }
  1022. #endif /* ENABLE_NLS */
  1023. #ifdef __cplusplus
  1024. }
  1025. #endif