tcpprep_opts.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (tcpprep_opts.c)
  4. *
  5. * It has been AutoGen-ed Sunday January 18, 2009 at 10:08:06 AM PST
  6. * From the definitions tcpprep_opts.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 32:0:7 templates.
  10. */
  11. /*
  12. * This file was produced by an AutoOpts template. AutoOpts is a
  13. * copyrighted work. This source file is not encumbered by AutoOpts
  14. * licensing, but is provided under the licensing terms chosen by the
  15. * tcpprep author or copyright holder. AutoOpts is licensed under
  16. * the terms of the LGPL. The redistributable library (``libopts'') is
  17. * licensed under the terms of either the LGPL or, at the users discretion,
  18. * the BSD license. See the AutoOpts and/or libopts sources for details.
  19. *
  20. * This source file is copyrighted and licensed under the following terms:
  21. *
  22. * tcpprep copyright 2000-2008 Aaron Turner - all rights reserved
  23. *
  24. * tcpprep is free software copyrighted by Aaron Turner.
  25. *
  26. * Redistribution and use in source and binary forms, with or without
  27. * modification, are permitted provided that the following conditions
  28. * are met:
  29. * 1. Redistributions of source code must retain the above copyright
  30. * notice, this list of conditions and the following disclaimer.
  31. * 2. Redistributions in binary form must reproduce the above copyright
  32. * notice, this list of conditions and the following disclaimer in the
  33. * documentation and/or other materials provided with the distribution.
  34. * 3. Neither the name ``Aaron Turner'' nor the name of any other
  35. * contributor may be used to endorse or promote products derived
  36. * from this software without specific prior written permission.
  37. *
  38. * tcpprep IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS
  39. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  40. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  41. * ARE DISCLAIMED. IN NO EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS
  42. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  43. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  44. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  45. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  46. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  47. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  48. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50. #include <sys/types.h>
  51. #include <limits.h>
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <errno.h>
  55. extern FILE * option_usage_fp;
  56. #define OPTION_CODE_COMPILE 1
  57. #include "tcpprep_opts.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /* TRANSLATORS: choose the translation for option names wisely because you
  62. cannot ever change your mind. */
  63. tSCC zCopyright[] =
  64. "tcpprep copyright (c) 2000-2008 Aaron Turner, all rights reserved";
  65. tSCC zCopyrightNotice[1454] =
  66. "tcpprep is free software copyrighted by Aaron Turner.\n\n\
  67. Redistribution and use in source and binary forms, with or without\n\
  68. modification, are permitted provided that the following conditions are met: 1.\n\
  69. Redistributions of source code must retain the above copyright notice, this\n\
  70. list of conditions and the following disclaimer. 2. Redistributions in binary\n\
  71. form must reproduce the above copyright notice, this list of conditions and the\n\
  72. following disclaimer in the documentation and/or other materials provided with\n\
  73. the distribution. 3. Neither the name ``Aaron Turner'' nor the name of any\n\
  74. other contributor may be used to endorse or promote products derived from this\n\
  75. software without specific prior written permission.\n\n\
  76. tcpprep IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS OR IMPLIED\n\
  77. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n\
  78. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n\
  79. EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n\
  80. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n\
  81. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
  82. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n\
  83. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n\
  84. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n\
  85. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
  86. extern tUsageProc optionUsage;
  87. /*
  88. * global included definitions
  89. */
  90. #include "defines.h"
  91. #include "common.h"
  92. #include "config.h"
  93. #include "tcpprep.h"
  94. #include <stdlib.h>
  95. #include <string.h>
  96. extern tcpprep_opt_t options;
  97. #ifndef NULL
  98. # define NULL 0
  99. #endif
  100. #ifndef EXIT_SUCCESS
  101. # define EXIT_SUCCESS 0
  102. #endif
  103. #ifndef EXIT_FAILURE
  104. # define EXIT_FAILURE 1
  105. #endif
  106. /*
  107. * Dbug option description:
  108. */
  109. #ifdef DEBUG
  110. tSCC zDbugText[] =
  111. "Enable debugging output";
  112. tSCC zDbug_NAME[] = "DBUG";
  113. tSCC zDbug_Name[] = "dbug";
  114. #define zDbugDefaultArg ((char const*)0)
  115. #define DBUG_FLAGS (OPTST_DISABLED | OPTST_IMM \
  116. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  117. #else /* disable Dbug */
  118. #define VALUE_OPT_DBUG NO_EQUIVALENT
  119. #define DBUG_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  120. #define zDbugDefaultArg NULL
  121. #define zDbugText NULL
  122. #define zDbug_NAME NULL
  123. #define zDbug_Name NULL
  124. #endif /* DEBUG */
  125. /*
  126. * Auto option description with
  127. * "Must also have options" and "Incompatible options":
  128. */
  129. tSCC zAutoText[] =
  130. "Auto-split mode";
  131. tSCC zAuto_NAME[] = "AUTO";
  132. tSCC zAuto_Name[] = "auto";
  133. static const int
  134. aAutoCantList[] = {
  135. INDEX_OPT_CIDR,
  136. INDEX_OPT_PORT,
  137. INDEX_OPT_REGEX,
  138. INDEX_OPT_MAC, NO_EQUIVALENT };
  139. #define AUTO_FLAGS (OPTST_DISABLED \
  140. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  141. /*
  142. * Cidr option description with
  143. * "Must also have options" and "Incompatible options":
  144. */
  145. tSCC zCidrText[] =
  146. "CIDR-split mode";
  147. tSCC zCidr_NAME[] = "CIDR";
  148. tSCC zCidr_Name[] = "cidr";
  149. static const int
  150. aCidrCantList[] = {
  151. INDEX_OPT_AUTO,
  152. INDEX_OPT_PORT,
  153. INDEX_OPT_REGEX,
  154. INDEX_OPT_MAC, NO_EQUIVALENT };
  155. #define CIDR_FLAGS (OPTST_DISABLED \
  156. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  157. /*
  158. * Regex option description with
  159. * "Must also have options" and "Incompatible options":
  160. */
  161. tSCC zRegexText[] =
  162. "Regex-split mode";
  163. tSCC zRegex_NAME[] = "REGEX";
  164. tSCC zRegex_Name[] = "regex";
  165. static const int
  166. aRegexCantList[] = {
  167. INDEX_OPT_AUTO,
  168. INDEX_OPT_PORT,
  169. INDEX_OPT_CIDR,
  170. INDEX_OPT_MAC, NO_EQUIVALENT };
  171. #define REGEX_FLAGS (OPTST_DISABLED \
  172. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  173. /*
  174. * Port option description with
  175. * "Must also have options" and "Incompatible options":
  176. */
  177. tSCC zPortText[] =
  178. "Port-split mode";
  179. tSCC zPort_NAME[] = "PORT";
  180. tSCC zPort_Name[] = "port";
  181. static const int
  182. aPortCantList[] = {
  183. INDEX_OPT_AUTO,
  184. INDEX_OPT_REGEX,
  185. INDEX_OPT_CIDR,
  186. INDEX_OPT_MAC, NO_EQUIVALENT };
  187. #define PORT_FLAGS (OPTST_DISABLED)
  188. /*
  189. * Mac option description with
  190. * "Must also have options" and "Incompatible options":
  191. */
  192. tSCC zMacText[] =
  193. "Source MAC split mode";
  194. tSCC zMac_NAME[] = "MAC";
  195. tSCC zMac_Name[] = "mac";
  196. static const int
  197. aMacCantList[] = {
  198. INDEX_OPT_AUTO,
  199. INDEX_OPT_REGEX,
  200. INDEX_OPT_CIDR,
  201. INDEX_OPT_PORT, NO_EQUIVALENT };
  202. #define MAC_FLAGS (OPTST_DISABLED \
  203. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  204. /*
  205. * Reverse option description:
  206. */
  207. tSCC zReverseText[] =
  208. "Matches to be client instead of server";
  209. tSCC zReverse_NAME[] = "REVERSE";
  210. tSCC zReverse_Name[] = "reverse";
  211. #define REVERSE_FLAGS (OPTST_DISABLED)
  212. /*
  213. * Comment option description:
  214. */
  215. tSCC zCommentText[] =
  216. "Embeded cache file comment";
  217. tSCC zComment_NAME[] = "COMMENT";
  218. tSCC zComment_Name[] = "comment";
  219. #define COMMENT_FLAGS (OPTST_DISABLED \
  220. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  221. /*
  222. * No_Arg_Comment option description:
  223. */
  224. tSCC zNo_Arg_CommentText[] =
  225. "Do not embed any cache file comment";
  226. tSCC zNo_Arg_Comment_NAME[] = "NO_ARG_COMMENT";
  227. tSCC zNo_Arg_Comment_Name[] = "no-arg-comment";
  228. #define NO_ARG_COMMENT_FLAGS (OPTST_DISABLED)
  229. /*
  230. * Include option description with
  231. * "Must also have options" and "Incompatible options":
  232. */
  233. tSCC zIncludeText[] =
  234. "Include only packets matching rule";
  235. tSCC zInclude_NAME[] = "INCLUDE";
  236. tSCC zInclude_Name[] = "include";
  237. static const int
  238. aIncludeCantList[] = {
  239. INDEX_OPT_EXCLUDE, NO_EQUIVALENT };
  240. #define INCLUDE_FLAGS (OPTST_DISABLED \
  241. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  242. /*
  243. * Exclude option description with
  244. * "Must also have options" and "Incompatible options":
  245. */
  246. tSCC zExcludeText[] =
  247. "Exclude any packet matching this rule";
  248. tSCC zExclude_NAME[] = "EXCLUDE";
  249. tSCC zExclude_Name[] = "exclude";
  250. static const int
  251. aExcludeCantList[] = {
  252. INDEX_OPT_INCLUDE, NO_EQUIVALENT };
  253. #define EXCLUDE_FLAGS (OPTST_DISABLED \
  254. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  255. /*
  256. * Cachefile option description:
  257. */
  258. tSCC zCachefileText[] =
  259. "Output cache file";
  260. tSCC zCachefile_NAME[] = "CACHEFILE";
  261. tSCC zCachefile_Name[] = "cachefile";
  262. #define CACHEFILE_FLAGS (OPTST_DISABLED \
  263. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  264. /*
  265. * Pcap option description:
  266. */
  267. tSCC zPcapText[] =
  268. "Input pcap file to process";
  269. tSCC zPcap_NAME[] = "PCAP";
  270. tSCC zPcap_Name[] = "pcap";
  271. #define PCAP_FLAGS (OPTST_DISABLED \
  272. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  273. /*
  274. * Print_Comment option description:
  275. */
  276. tSCC zPrint_CommentText[] =
  277. "Print embedded comment in the specified cache file";
  278. tSCC zPrint_Comment_NAME[] = "PRINT_COMMENT";
  279. tSCC zPrint_Comment_Name[] = "print-comment";
  280. #define PRINT_COMMENT_FLAGS (OPTST_DISABLED \
  281. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  282. /*
  283. * Print_Info option description:
  284. */
  285. tSCC zPrint_InfoText[] =
  286. "Print basic info from the specified cache file";
  287. tSCC zPrint_Info_NAME[] = "PRINT_INFO";
  288. tSCC zPrint_Info_Name[] = "print-info";
  289. #define PRINT_INFO_FLAGS (OPTST_DISABLED \
  290. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  291. /*
  292. * Print_Stats option description:
  293. */
  294. tSCC zPrint_StatsText[] =
  295. "Print statistical information about the specified cache file";
  296. tSCC zPrint_Stats_NAME[] = "PRINT_STATS";
  297. tSCC zPrint_Stats_Name[] = "print-stats";
  298. #define PRINT_STATS_FLAGS (OPTST_DISABLED \
  299. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  300. /*
  301. * Services option description with
  302. * "Must also have options" and "Incompatible options":
  303. */
  304. tSCC zServicesText[] =
  305. "Load services file for server ports";
  306. tSCC zServices_NAME[] = "SERVICES";
  307. tSCC zServices_Name[] = "services";
  308. static const int
  309. aServicesMustList[] = {
  310. INDEX_OPT_PORT, NO_EQUIVALENT };
  311. #define SERVICES_FLAGS (OPTST_DISABLED \
  312. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  313. /*
  314. * Nonip option description:
  315. */
  316. tSCC zNonipText[] =
  317. "Send non-IP traffic out server interface";
  318. tSCC zNonip_NAME[] = "NONIP";
  319. tSCC zNonip_Name[] = "nonip";
  320. #define NONIP_FLAGS (OPTST_DISABLED)
  321. /*
  322. * Ratio option description with
  323. * "Must also have options" and "Incompatible options":
  324. */
  325. tSCC zRatioText[] =
  326. "Ratio of client to server packets";
  327. tSCC zRatio_NAME[] = "RATIO";
  328. tSCC zRatio_Name[] = "ratio";
  329. tSCC zRatioDefaultArg[] = "2.0";
  330. static const int
  331. aRatioMustList[] = {
  332. INDEX_OPT_AUTO, NO_EQUIVALENT };
  333. #define RATIO_FLAGS (OPTST_DISABLED \
  334. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  335. /*
  336. * Minmask option description with
  337. * "Must also have options" and "Incompatible options":
  338. */
  339. tSCC zMinmaskText[] =
  340. "Minimum network mask length in auto mode";
  341. tSCC zMinmask_NAME[] = "MINMASK";
  342. tSCC zMinmask_Name[] = "minmask";
  343. #define zMinmaskDefaultArg ((char const*)30)
  344. static const int
  345. aMinmaskMustList[] = {
  346. INDEX_OPT_AUTO, NO_EQUIVALENT };
  347. #define MINMASK_FLAGS (OPTST_DISABLED \
  348. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  349. /*
  350. * Maxmask option description with
  351. * "Must also have options" and "Incompatible options":
  352. */
  353. tSCC zMaxmaskText[] =
  354. "Maximum network mask length in auto mode";
  355. tSCC zMaxmask_NAME[] = "MAXMASK";
  356. tSCC zMaxmask_Name[] = "maxmask";
  357. #define zMaxmaskDefaultArg ((char const*)8)
  358. static const int
  359. aMaxmaskMustList[] = {
  360. INDEX_OPT_AUTO, NO_EQUIVALENT };
  361. #define MAXMASK_FLAGS (OPTST_DISABLED \
  362. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  363. /*
  364. * Verbose option description:
  365. */
  366. #ifdef ENABLE_VERBOSE
  367. tSCC zVerboseText[] =
  368. "Print decoded packets via tcpdump to STDOUT";
  369. tSCC zVerbose_NAME[] = "VERBOSE";
  370. tSCC zVerbose_Name[] = "verbose";
  371. #define VERBOSE_FLAGS (OPTST_DISABLED | OPTST_IMM)
  372. #else /* disable Verbose */
  373. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  374. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  375. #define zVerboseText NULL
  376. #define zVerbose_NAME NULL
  377. #define zVerbose_Name NULL
  378. #endif /* ENABLE_VERBOSE */
  379. /*
  380. * Decode option description with
  381. * "Must also have options" and "Incompatible options":
  382. */
  383. #ifdef ENABLE_VERBOSE
  384. tSCC zDecodeText[] =
  385. "Arguments passed to tcpdump decoder";
  386. tSCC zDecode_NAME[] = "DECODE";
  387. tSCC zDecode_Name[] = "decode";
  388. static const int
  389. aDecodeMustList[] = {
  390. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  391. #define DECODE_FLAGS (OPTST_DISABLED \
  392. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  393. #else /* disable Decode */
  394. #define VALUE_OPT_DECODE NO_EQUIVALENT
  395. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  396. #define aDecodeMustList NULL
  397. #define zDecodeText NULL
  398. #define zDecode_NAME NULL
  399. #define zDecode_Name NULL
  400. #endif /* ENABLE_VERBOSE */
  401. /*
  402. * Version option description:
  403. */
  404. tSCC zVersionText[] =
  405. "Print version information";
  406. tSCC zVersion_NAME[] = "VERSION";
  407. tSCC zVersion_Name[] = "version";
  408. #define VERSION_FLAGS (OPTST_DISABLED)
  409. /*
  410. * Less_Help option description:
  411. */
  412. tSCC zLess_HelpText[] =
  413. "Display less usage information and exit";
  414. tSCC zLess_Help_NAME[] = "LESS_HELP";
  415. tSCC zLess_Help_Name[] = "less-help";
  416. #define LESS_HELP_FLAGS (OPTST_DISABLED | OPTST_IMM)
  417. /*
  418. * Help/More_Help option descriptions:
  419. */
  420. tSCC zHelpText[] = "Display usage information and exit";
  421. tSCC zHelp_Name[] = "help";
  422. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  423. tSCC zMore_Help_Name[] = "more-help";
  424. tSCC zSave_OptsText[] = "Save the option state to a config file";
  425. tSCC zSave_Opts_Name[] = "save-opts";
  426. tSCC zLoad_OptsText[] = "Load options from a config file";
  427. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  428. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  429. tSCC zNotLoad_Opts_Pfx[] = "no";
  430. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  431. /*
  432. * Declare option callback procedures
  433. */
  434. #ifdef DEBUG
  435. static tOptProc doOptDbug;
  436. #else /* not DEBUG */
  437. # define doOptDbug NULL
  438. #endif /* def/not DEBUG */
  439. extern tOptProc
  440. optionPagedUsage;
  441. static tOptProc
  442. doOptAuto, doOptCidr, doOptComment,
  443. doOptExclude, doOptInclude, doOptLess_Help,
  444. doOptMac, doOptMaxmask, doOptMinmask,
  445. doOptNo_Arg_Comment, doOptNonip, doOptPort,
  446. doOptRegex, doOptServices, doOptVersion,
  447. doUsageOpt;
  448. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  449. *
  450. * Define the Tcpprep Option Descriptions.
  451. */
  452. static tOptDesc optDesc[ OPTION_CT ] = {
  453. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  454. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  455. /* equivalenced to */ NO_EQUIVALENT,
  456. /* min, max, act ct */ 0, 1, 0,
  457. /* opt state flags */ DBUG_FLAGS, 0,
  458. /* last opt argumnt */ { zDbugDefaultArg },
  459. /* arg list/cookie */ NULL,
  460. /* must/cannot opts */ NULL, NULL,
  461. /* option proc */ doOptDbug,
  462. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  463. /* disablement strs */ NULL, NULL },
  464. { /* entry idx, value */ 1, VALUE_OPT_AUTO,
  465. /* equiv idx, value */ 1, VALUE_OPT_AUTO,
  466. /* equivalenced to */ NO_EQUIVALENT,
  467. /* min, max, act ct */ 0, 1, 0,
  468. /* opt state flags */ AUTO_FLAGS, 0,
  469. /* last opt argumnt */ { NULL },
  470. /* arg list/cookie */ NULL,
  471. /* must/cannot opts */ NULL, aAutoCantList,
  472. /* option proc */ doOptAuto,
  473. /* desc, NAME, name */ zAutoText, zAuto_NAME, zAuto_Name,
  474. /* disablement strs */ NULL, NULL },
  475. { /* entry idx, value */ 2, VALUE_OPT_CIDR,
  476. /* equiv idx, value */ 2, VALUE_OPT_CIDR,
  477. /* equivalenced to */ NO_EQUIVALENT,
  478. /* min, max, act ct */ 0, 1, 0,
  479. /* opt state flags */ CIDR_FLAGS, 0,
  480. /* last opt argumnt */ { NULL },
  481. /* arg list/cookie */ NULL,
  482. /* must/cannot opts */ NULL, aCidrCantList,
  483. /* option proc */ doOptCidr,
  484. /* desc, NAME, name */ zCidrText, zCidr_NAME, zCidr_Name,
  485. /* disablement strs */ NULL, NULL },
  486. { /* entry idx, value */ 3, VALUE_OPT_REGEX,
  487. /* equiv idx, value */ 3, VALUE_OPT_REGEX,
  488. /* equivalenced to */ NO_EQUIVALENT,
  489. /* min, max, act ct */ 0, 1, 0,
  490. /* opt state flags */ REGEX_FLAGS, 0,
  491. /* last opt argumnt */ { NULL },
  492. /* arg list/cookie */ NULL,
  493. /* must/cannot opts */ NULL, aRegexCantList,
  494. /* option proc */ doOptRegex,
  495. /* desc, NAME, name */ zRegexText, zRegex_NAME, zRegex_Name,
  496. /* disablement strs */ NULL, NULL },
  497. { /* entry idx, value */ 4, VALUE_OPT_PORT,
  498. /* equiv idx, value */ 4, VALUE_OPT_PORT,
  499. /* equivalenced to */ NO_EQUIVALENT,
  500. /* min, max, act ct */ 0, 1, 0,
  501. /* opt state flags */ PORT_FLAGS, 0,
  502. /* last opt argumnt */ { NULL },
  503. /* arg list/cookie */ NULL,
  504. /* must/cannot opts */ NULL, aPortCantList,
  505. /* option proc */ doOptPort,
  506. /* desc, NAME, name */ zPortText, zPort_NAME, zPort_Name,
  507. /* disablement strs */ NULL, NULL },
  508. { /* entry idx, value */ 5, VALUE_OPT_MAC,
  509. /* equiv idx, value */ 5, VALUE_OPT_MAC,
  510. /* equivalenced to */ NO_EQUIVALENT,
  511. /* min, max, act ct */ 0, 1, 0,
  512. /* opt state flags */ MAC_FLAGS, 0,
  513. /* last opt argumnt */ { NULL },
  514. /* arg list/cookie */ NULL,
  515. /* must/cannot opts */ NULL, aMacCantList,
  516. /* option proc */ doOptMac,
  517. /* desc, NAME, name */ zMacText, zMac_NAME, zMac_Name,
  518. /* disablement strs */ NULL, NULL },
  519. { /* entry idx, value */ 6, VALUE_OPT_REVERSE,
  520. /* equiv idx, value */ 6, VALUE_OPT_REVERSE,
  521. /* equivalenced to */ NO_EQUIVALENT,
  522. /* min, max, act ct */ 0, 1, 0,
  523. /* opt state flags */ REVERSE_FLAGS, 0,
  524. /* last opt argumnt */ { NULL },
  525. /* arg list/cookie */ NULL,
  526. /* must/cannot opts */ NULL, NULL,
  527. /* option proc */ NULL,
  528. /* desc, NAME, name */ zReverseText, zReverse_NAME, zReverse_Name,
  529. /* disablement strs */ NULL, NULL },
  530. { /* entry idx, value */ 7, VALUE_OPT_COMMENT,
  531. /* equiv idx, value */ 7, VALUE_OPT_COMMENT,
  532. /* equivalenced to */ NO_EQUIVALENT,
  533. /* min, max, act ct */ 0, 1, 0,
  534. /* opt state flags */ COMMENT_FLAGS, 0,
  535. /* last opt argumnt */ { NULL },
  536. /* arg list/cookie */ NULL,
  537. /* must/cannot opts */ NULL, NULL,
  538. /* option proc */ doOptComment,
  539. /* desc, NAME, name */ zCommentText, zComment_NAME, zComment_Name,
  540. /* disablement strs */ NULL, NULL },
  541. { /* entry idx, value */ 8, VALUE_OPT_NO_ARG_COMMENT,
  542. /* equiv idx, value */ 8, VALUE_OPT_NO_ARG_COMMENT,
  543. /* equivalenced to */ NO_EQUIVALENT,
  544. /* min, max, act ct */ 0, 1, 0,
  545. /* opt state flags */ NO_ARG_COMMENT_FLAGS, 0,
  546. /* last opt argumnt */ { NULL },
  547. /* arg list/cookie */ NULL,
  548. /* must/cannot opts */ NULL, NULL,
  549. /* option proc */ doOptNo_Arg_Comment,
  550. /* desc, NAME, name */ zNo_Arg_CommentText, zNo_Arg_Comment_NAME, zNo_Arg_Comment_Name,
  551. /* disablement strs */ NULL, NULL },
  552. { /* entry idx, value */ 9, VALUE_OPT_INCLUDE,
  553. /* equiv idx, value */ 9, VALUE_OPT_INCLUDE,
  554. /* equivalenced to */ NO_EQUIVALENT,
  555. /* min, max, act ct */ 0, 1, 0,
  556. /* opt state flags */ INCLUDE_FLAGS, 0,
  557. /* last opt argumnt */ { NULL },
  558. /* arg list/cookie */ NULL,
  559. /* must/cannot opts */ NULL, aIncludeCantList,
  560. /* option proc */ doOptInclude,
  561. /* desc, NAME, name */ zIncludeText, zInclude_NAME, zInclude_Name,
  562. /* disablement strs */ NULL, NULL },
  563. { /* entry idx, value */ 10, VALUE_OPT_EXCLUDE,
  564. /* equiv idx, value */ 10, VALUE_OPT_EXCLUDE,
  565. /* equivalenced to */ NO_EQUIVALENT,
  566. /* min, max, act ct */ 0, 1, 0,
  567. /* opt state flags */ EXCLUDE_FLAGS, 0,
  568. /* last opt argumnt */ { NULL },
  569. /* arg list/cookie */ NULL,
  570. /* must/cannot opts */ NULL, aExcludeCantList,
  571. /* option proc */ doOptExclude,
  572. /* desc, NAME, name */ zExcludeText, zExclude_NAME, zExclude_Name,
  573. /* disablement strs */ NULL, NULL },
  574. { /* entry idx, value */ 11, VALUE_OPT_CACHEFILE,
  575. /* equiv idx, value */ 11, VALUE_OPT_CACHEFILE,
  576. /* equivalenced to */ NO_EQUIVALENT,
  577. /* min, max, act ct */ 0, 1, 0,
  578. /* opt state flags */ CACHEFILE_FLAGS, 0,
  579. /* last opt argumnt */ { NULL },
  580. /* arg list/cookie */ NULL,
  581. /* must/cannot opts */ NULL, NULL,
  582. /* option proc */ NULL,
  583. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  584. /* disablement strs */ NULL, NULL },
  585. { /* entry idx, value */ 12, VALUE_OPT_PCAP,
  586. /* equiv idx, value */ 12, VALUE_OPT_PCAP,
  587. /* equivalenced to */ NO_EQUIVALENT,
  588. /* min, max, act ct */ 0, 1, 0,
  589. /* opt state flags */ PCAP_FLAGS, 0,
  590. /* last opt argumnt */ { NULL },
  591. /* arg list/cookie */ NULL,
  592. /* must/cannot opts */ NULL, NULL,
  593. /* option proc */ NULL,
  594. /* desc, NAME, name */ zPcapText, zPcap_NAME, zPcap_Name,
  595. /* disablement strs */ NULL, NULL },
  596. { /* entry idx, value */ 13, VALUE_OPT_PRINT_COMMENT,
  597. /* equiv idx, value */ 13, VALUE_OPT_PRINT_COMMENT,
  598. /* equivalenced to */ NO_EQUIVALENT,
  599. /* min, max, act ct */ 0, 1, 0,
  600. /* opt state flags */ PRINT_COMMENT_FLAGS, 0,
  601. /* last opt argumnt */ { NULL },
  602. /* arg list/cookie */ NULL,
  603. /* must/cannot opts */ NULL, NULL,
  604. /* option proc */ NULL,
  605. /* desc, NAME, name */ zPrint_CommentText, zPrint_Comment_NAME, zPrint_Comment_Name,
  606. /* disablement strs */ NULL, NULL },
  607. { /* entry idx, value */ 14, VALUE_OPT_PRINT_INFO,
  608. /* equiv idx, value */ 14, VALUE_OPT_PRINT_INFO,
  609. /* equivalenced to */ NO_EQUIVALENT,
  610. /* min, max, act ct */ 0, 1, 0,
  611. /* opt state flags */ PRINT_INFO_FLAGS, 0,
  612. /* last opt argumnt */ { NULL },
  613. /* arg list/cookie */ NULL,
  614. /* must/cannot opts */ NULL, NULL,
  615. /* option proc */ NULL,
  616. /* desc, NAME, name */ zPrint_InfoText, zPrint_Info_NAME, zPrint_Info_Name,
  617. /* disablement strs */ NULL, NULL },
  618. { /* entry idx, value */ 15, VALUE_OPT_PRINT_STATS,
  619. /* equiv idx, value */ 15, VALUE_OPT_PRINT_STATS,
  620. /* equivalenced to */ NO_EQUIVALENT,
  621. /* min, max, act ct */ 0, 1, 0,
  622. /* opt state flags */ PRINT_STATS_FLAGS, 0,
  623. /* last opt argumnt */ { NULL },
  624. /* arg list/cookie */ NULL,
  625. /* must/cannot opts */ NULL, NULL,
  626. /* option proc */ NULL,
  627. /* desc, NAME, name */ zPrint_StatsText, zPrint_Stats_NAME, zPrint_Stats_Name,
  628. /* disablement strs */ NULL, NULL },
  629. { /* entry idx, value */ 16, VALUE_OPT_SERVICES,
  630. /* equiv idx, value */ 16, VALUE_OPT_SERVICES,
  631. /* equivalenced to */ NO_EQUIVALENT,
  632. /* min, max, act ct */ 0, 1, 0,
  633. /* opt state flags */ SERVICES_FLAGS, 0,
  634. /* last opt argumnt */ { NULL },
  635. /* arg list/cookie */ NULL,
  636. /* must/cannot opts */ aServicesMustList, NULL,
  637. /* option proc */ doOptServices,
  638. /* desc, NAME, name */ zServicesText, zServices_NAME, zServices_Name,
  639. /* disablement strs */ NULL, NULL },
  640. { /* entry idx, value */ 17, VALUE_OPT_NONIP,
  641. /* equiv idx, value */ 17, VALUE_OPT_NONIP,
  642. /* equivalenced to */ NO_EQUIVALENT,
  643. /* min, max, act ct */ 0, 1, 0,
  644. /* opt state flags */ NONIP_FLAGS, 0,
  645. /* last opt argumnt */ { NULL },
  646. /* arg list/cookie */ NULL,
  647. /* must/cannot opts */ NULL, NULL,
  648. /* option proc */ doOptNonip,
  649. /* desc, NAME, name */ zNonipText, zNonip_NAME, zNonip_Name,
  650. /* disablement strs */ NULL, NULL },
  651. { /* entry idx, value */ 18, VALUE_OPT_RATIO,
  652. /* equiv idx, value */ 18, VALUE_OPT_RATIO,
  653. /* equivalenced to */ NO_EQUIVALENT,
  654. /* min, max, act ct */ 0, 1, 0,
  655. /* opt state flags */ RATIO_FLAGS, 0,
  656. /* last opt argumnt */ { zRatioDefaultArg },
  657. /* arg list/cookie */ NULL,
  658. /* must/cannot opts */ aRatioMustList, NULL,
  659. /* option proc */ NULL,
  660. /* desc, NAME, name */ zRatioText, zRatio_NAME, zRatio_Name,
  661. /* disablement strs */ NULL, NULL },
  662. { /* entry idx, value */ 19, VALUE_OPT_MINMASK,
  663. /* equiv idx, value */ 19, VALUE_OPT_MINMASK,
  664. /* equivalenced to */ NO_EQUIVALENT,
  665. /* min, max, act ct */ 0, 1, 0,
  666. /* opt state flags */ MINMASK_FLAGS, 0,
  667. /* last opt argumnt */ { zMinmaskDefaultArg },
  668. /* arg list/cookie */ NULL,
  669. /* must/cannot opts */ aMinmaskMustList, NULL,
  670. /* option proc */ doOptMinmask,
  671. /* desc, NAME, name */ zMinmaskText, zMinmask_NAME, zMinmask_Name,
  672. /* disablement strs */ NULL, NULL },
  673. { /* entry idx, value */ 20, VALUE_OPT_MAXMASK,
  674. /* equiv idx, value */ 20, VALUE_OPT_MAXMASK,
  675. /* equivalenced to */ NO_EQUIVALENT,
  676. /* min, max, act ct */ 0, 1, 0,
  677. /* opt state flags */ MAXMASK_FLAGS, 0,
  678. /* last opt argumnt */ { zMaxmaskDefaultArg },
  679. /* arg list/cookie */ NULL,
  680. /* must/cannot opts */ aMaxmaskMustList, NULL,
  681. /* option proc */ doOptMaxmask,
  682. /* desc, NAME, name */ zMaxmaskText, zMaxmask_NAME, zMaxmask_Name,
  683. /* disablement strs */ NULL, NULL },
  684. { /* entry idx, value */ 21, VALUE_OPT_VERBOSE,
  685. /* equiv idx, value */ 21, VALUE_OPT_VERBOSE,
  686. /* equivalenced to */ NO_EQUIVALENT,
  687. /* min, max, act ct */ 0, 1, 0,
  688. /* opt state flags */ VERBOSE_FLAGS, 0,
  689. /* last opt argumnt */ { NULL },
  690. /* arg list/cookie */ NULL,
  691. /* must/cannot opts */ NULL, NULL,
  692. /* option proc */ NULL,
  693. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  694. /* disablement strs */ NULL, NULL },
  695. { /* entry idx, value */ 22, VALUE_OPT_DECODE,
  696. /* equiv idx, value */ 22, VALUE_OPT_DECODE,
  697. /* equivalenced to */ NO_EQUIVALENT,
  698. /* min, max, act ct */ 0, 1, 0,
  699. /* opt state flags */ DECODE_FLAGS, 0,
  700. /* last opt argumnt */ { NULL },
  701. /* arg list/cookie */ NULL,
  702. /* must/cannot opts */ aDecodeMustList, NULL,
  703. /* option proc */ NULL,
  704. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  705. /* disablement strs */ NULL, NULL },
  706. { /* entry idx, value */ 23, VALUE_OPT_VERSION,
  707. /* equiv idx, value */ 23, VALUE_OPT_VERSION,
  708. /* equivalenced to */ NO_EQUIVALENT,
  709. /* min, max, act ct */ 0, 1, 0,
  710. /* opt state flags */ VERSION_FLAGS, 0,
  711. /* last opt argumnt */ { NULL },
  712. /* arg list/cookie */ NULL,
  713. /* must/cannot opts */ NULL, NULL,
  714. /* option proc */ doOptVersion,
  715. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  716. /* disablement strs */ NULL, NULL },
  717. { /* entry idx, value */ 24, VALUE_OPT_LESS_HELP,
  718. /* equiv idx, value */ 24, VALUE_OPT_LESS_HELP,
  719. /* equivalenced to */ NO_EQUIVALENT,
  720. /* min, max, act ct */ 0, 1, 0,
  721. /* opt state flags */ LESS_HELP_FLAGS, 0,
  722. /* last opt argumnt */ { NULL },
  723. /* arg list/cookie */ NULL,
  724. /* must/cannot opts */ NULL, NULL,
  725. /* option proc */ doOptLess_Help,
  726. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  727. /* disablement strs */ NULL, NULL },
  728. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  729. /* equiv idx value */ NO_EQUIVALENT, 0,
  730. /* equivalenced to */ NO_EQUIVALENT,
  731. /* min, max, act ct */ 0, 1, 0,
  732. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  733. /* last opt argumnt */ { NULL },
  734. /* arg list/cookie */ NULL,
  735. /* must/cannot opts */ NULL, NULL,
  736. /* option proc */ doUsageOpt,
  737. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  738. /* disablement strs */ NULL, NULL },
  739. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  740. /* equiv idx value */ NO_EQUIVALENT, 0,
  741. /* equivalenced to */ NO_EQUIVALENT,
  742. /* min, max, act ct */ 0, 1, 0,
  743. /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
  744. /* last opt argumnt */ { NULL },
  745. /* arg list/cookie */ NULL,
  746. /* must/cannot opts */ NULL, NULL,
  747. /* option proc */ optionPagedUsage,
  748. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  749. /* disablement strs */ NULL, NULL },
  750. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  751. /* equiv idx value */ NO_EQUIVALENT, 0,
  752. /* equivalenced to */ NO_EQUIVALENT,
  753. /* min, max, act ct */ 0, 1, 0,
  754. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  755. | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0,
  756. /* last opt argumnt */ { NULL },
  757. /* arg list/cookie */ NULL,
  758. /* must/cannot opts */ NULL, NULL,
  759. /* option proc */ NULL,
  760. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  761. /* disablement strs */ NULL, NULL },
  762. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  763. /* equiv idx value */ NO_EQUIVALENT, 0,
  764. /* equivalenced to */ NO_EQUIVALENT,
  765. /* min, max, act ct */ 0, NOLIMIT, 0,
  766. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  767. | OPTST_DISABLE_IMM, 0,
  768. /* last opt argumnt */ { NULL },
  769. /* arg list/cookie */ NULL,
  770. /* must/cannot opts */ NULL, NULL,
  771. /* option proc */ optionLoadOpt,
  772. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  773. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  774. };
  775. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  776. *
  777. * Define the Tcpprep Option Environment
  778. */
  779. tSCC zPROGNAME[] = "TCPPREP";
  780. tSCC zUsageTitle[] =
  781. "tcpprep (tcpprep) - Create a tcpreplay cache cache file from a pcap file.\n\
  782. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  783. tSCC zRcName[] = ".tcppreprc";
  784. tSCC* apzHomeList[] = {
  785. "$$/",
  786. NULL };
  787. #define zBugsAddr NULL
  788. tSCC zExplain[] = "\n\
  789. tcpprep is a ``pcap(3)'' file pre-processor which creates a cache\n\
  790. file which provides \"rules\" for ``tcprewrite(1)'' and ``tcpreplay(1)''\n\
  791. on how to process and send packets.\n";
  792. tSCC zDetail[] = "\n\
  793. The basic operation of tcpreplay is to resend all packets from the\n\
  794. input file(s) out a single file. Tcpprep processes a pcap file and \n\
  795. applies a set of user-specified rules to create a cache file which \n\
  796. tells tcpreplay wether or not to send each packet and which interface the\n\
  797. packet should be sent out of.\n\n\
  798. For more details, please see the Tcpreplay Manual at:\n\
  799. http://tcpreplay.synfin.net/trac/wiki/manual\n";
  800. #define zFullVersion NULL
  801. /* extracted from /usr/local/share/autogen/optcode.tpl near line 496 */
  802. #if defined(ENABLE_NLS)
  803. # define OPTPROC_BASE OPTPROC_TRANSLATE
  804. static tOptionXlateProc translate_option_strings;
  805. #else
  806. # define OPTPROC_BASE OPTPROC_NONE
  807. # define translate_option_strings NULL
  808. #endif /* ENABLE_NLS */
  809. #define tcpprep_full_usage NULL
  810. #define tcpprep_short_usage NULL
  811. tOptions tcpprepOptions = {
  812. OPTIONS_STRUCT_VERSION,
  813. 0, NULL, /* original argc + argv */
  814. ( OPTPROC_BASE
  815. + OPTPROC_ERRSTOP
  816. + OPTPROC_SHORTOPT
  817. + OPTPROC_LONGOPT
  818. + OPTPROC_NO_REQ_OPT
  819. + OPTPROC_NO_ARGS
  820. + OPTPROC_GNUUSAGE
  821. + OPTPROC_HAS_IMMED ),
  822. 0, NULL, /* current option index, current option */
  823. NULL, NULL, zPROGNAME,
  824. zRcName, zCopyright, zCopyrightNotice,
  825. zFullVersion, apzHomeList, zUsageTitle,
  826. zExplain, zDetail, optDesc,
  827. zBugsAddr, /* address to send bugs to */
  828. NULL, NULL, /* extensions/saved state */
  829. optionUsage, /* usage procedure */
  830. translate_option_strings, /* translation procedure */
  831. /*
  832. * Indexes to special options
  833. */
  834. { INDEX_OPT_MORE_HELP, /* more-help option index */
  835. INDEX_OPT_SAVE_OPTS, /* save option index */
  836. NO_EQUIVALENT, /* '-#' option index */
  837. NO_EQUIVALENT /* index of default opt */
  838. },
  839. 29 /* full option count */, 25 /* user option count */,
  840. tcpprep_full_usage, tcpprep_short_usage,
  841. NULL, NULL
  842. };
  843. /*
  844. * Create the static procedure(s) declared above.
  845. */
  846. static void
  847. doUsageOpt(
  848. tOptions* pOptions,
  849. tOptDesc* pOptDesc )
  850. {
  851. USAGE( EXIT_SUCCESS );
  852. }
  853. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  854. *
  855. * For the dbug option, when DEBUG is #define-d.
  856. */
  857. #ifdef DEBUG
  858. static void
  859. doOptDbug(tOptions* pOptions, tOptDesc* pOptDesc)
  860. {
  861. static const struct {long const rmin, rmax;} rng[1] = {
  862. { 0, 5 } };
  863. long val;
  864. int ix;
  865. char * pzEnd;
  866. if (pOptions <= OPTPROC_EMIT_LIMIT)
  867. goto emit_ranges;
  868. errno = 0;
  869. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  870. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  871. goto bad_value;
  872. if (*pzEnd != '\0')
  873. goto bad_value;
  874. for (ix = 0; ix < 1; ix++) {
  875. if (val < rng[ix].rmin)
  876. continue; /* ranges need not be ordered. */
  877. if (val == rng[ix].rmin)
  878. goto valid_return;
  879. if (rng[ix].rmax == LONG_MIN)
  880. continue;
  881. if (val <= rng[ix].rmax)
  882. goto valid_return;
  883. }
  884. bad_value:
  885. option_usage_fp = stderr;
  886. emit_ranges:
  887. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  888. return;
  889. valid_return:
  890. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  891. free((void *)pOptDesc->optArg.argString);
  892. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  893. }
  894. pOptDesc->optArg.argInt = val;
  895. }
  896. #endif /* defined DEBUG */
  897. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  898. *
  899. * For the auto option.
  900. */
  901. static void
  902. doOptAuto(tOptions* pOptions, tOptDesc* pOptDesc)
  903. {
  904. /* extracted from tcpprep_opts.def, line 89 */
  905. options.mode = AUTO_MODE;
  906. if (strcmp(OPT_ARG(AUTO), "bridge") == 0) {
  907. options.automode = BRIDGE_MODE;
  908. }
  909. else if (strcmp(OPT_ARG(AUTO), "router") == 0) {
  910. options.automode = ROUTER_MODE;
  911. }
  912. else if (strcmp(OPT_ARG(AUTO), "client") == 0) {
  913. options.automode = CLIENT_MODE;
  914. }
  915. else if (strcmp(OPT_ARG(AUTO), "server") == 0) {
  916. options.automode = SERVER_MODE;
  917. }
  918. else if (strcmp(OPT_ARG(AUTO), "first") == 0) {
  919. options.automode = FIRST_MODE;
  920. }
  921. else {
  922. errx(-1, "Invalid auto mode type: %s", OPT_ARG(AUTO));
  923. }
  924. }
  925. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  926. *
  927. * For the cidr option.
  928. */
  929. static void
  930. doOptCidr(tOptions* pOptions, tOptDesc* pOptDesc)
  931. {
  932. /* extracted from tcpprep_opts.def, line 161 */
  933. char *cidr = safe_strdup(OPT_ARG(CIDR));
  934. options.mode = CIDR_MODE;
  935. if (!parse_cidr(&options.cidrdata, cidr, ","))
  936. errx(-1, "Unable to parse CIDR map: %s", OPT_ARG(CIDR));
  937. free(cidr);
  938. }
  939. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  940. *
  941. * For the regex option.
  942. */
  943. static void
  944. doOptRegex(tOptions* pOptions, tOptDesc* pOptDesc)
  945. {
  946. /* extracted from tcpprep_opts.def, line 187 */
  947. int regex_error;
  948. char ebuf[EBUF_SIZE];
  949. options.mode = REGEX_MODE;
  950. if ((regex_error = regcomp(&options.preg, OPT_ARG(REGEX),
  951. REG_EXTENDED|REG_NOSUB))) {
  952. regerror(regex_error, &options.preg, ebuf, EBUF_SIZE);
  953. errx(-1, "Unable to compile regex: %s", ebuf);
  954. }
  955. }
  956. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  957. *
  958. * For the port option.
  959. */
  960. static void
  961. doOptPort(tOptions* pOptions, tOptDesc* pOptDesc)
  962. {
  963. /* extracted from tcpprep_opts.def, line 215 */
  964. options.mode = PORT_MODE;
  965. }
  966. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  967. *
  968. * For the mac option.
  969. */
  970. static void
  971. doOptMac(tOptions* pOptions, tOptDesc* pOptDesc)
  972. {
  973. /* extracted from tcpprep_opts.def, line 236 */
  974. options.mode = MAC_MODE;
  975. options.maclist = safe_strdup(OPT_ARG(MAC));
  976. }
  977. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  978. *
  979. * For the comment option.
  980. */
  981. static void
  982. doOptComment(tOptions* pOptions, tOptDesc* pOptDesc)
  983. {
  984. /* extracted from tcpprep_opts.def, line 269 */
  985. /* our comment_len is only 16bit - myargs[] */
  986. if (strlen(OPT_ARG(COMMENT)) > ((1 << 16) - 1 - MYARGS_LEN))
  987. errx(-1, "Comment length %zu is longer then max allowed (%d)",
  988. strlen(OPT_ARG(COMMENT)), (1 << 16) - 1 - MYARGS_LEN);
  989. /* save the comment */
  990. options.comment = (char *)safe_malloc(strlen(OPT_ARG(COMMENT)) + 1);
  991. strcpy(options.comment, OPT_ARG(COMMENT));
  992. }
  993. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  994. *
  995. * For the no-arg-comment option.
  996. */
  997. static void
  998. doOptNo_Arg_Comment(tOptions* pOptions, tOptDesc* pOptDesc)
  999. {
  1000. /* extracted from tcpprep_opts.def, line 291 */
  1001. options.nocomment = 1;
  1002. }
  1003. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1004. *
  1005. * For the include option.
  1006. */
  1007. static void
  1008. doOptInclude(tOptions* pOptions, tOptDesc* pOptDesc)
  1009. {
  1010. /* extracted from tcpprep_opts.def, line 311 */
  1011. char *include;
  1012. include = safe_strdup(OPT_ARG(INCLUDE));
  1013. options.xX.mode = xX_MODE_INCLUDE;
  1014. if ((options.xX.mode = parse_xX_str(&options.xX, include, &options.bpf)) == xXError)
  1015. errx(-1, "Unable to parse include/exclude rule: %s", OPT_ARG(INCLUDE));
  1016. free(include);
  1017. }
  1018. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1019. *
  1020. * For the exclude option.
  1021. */
  1022. static void
  1023. doOptExclude(tOptions* pOptions, tOptDesc* pOptDesc)
  1024. {
  1025. /* extracted from tcpprep_opts.def, line 358 */
  1026. char *exclude;
  1027. exclude = safe_strdup(OPT_ARG(EXCLUDE));
  1028. options.xX.mode = xX_MODE_EXCLUDE;
  1029. if ((options.xX.mode = parse_xX_str(&options.xX, exclude, &options.bpf)) == xXError)
  1030. errx(-1, "Unable to parse include/exclude rule: %s", OPT_ARG(EXCLUDE));
  1031. free(exclude);
  1032. }
  1033. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1034. *
  1035. * For the services option.
  1036. */
  1037. static void
  1038. doOptServices(tOptions* pOptions, tOptDesc* pOptDesc)
  1039. {
  1040. /* extracted from tcpprep_opts.def, line 455 */
  1041. parse_services(OPT_ARG(SERVICES), &options.services);
  1042. }
  1043. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1044. *
  1045. * For the nonip option.
  1046. */
  1047. static void
  1048. doOptNonip(tOptions* pOptions, tOptDesc* pOptDesc)
  1049. {
  1050. /* extracted from tcpprep_opts.def, line 466 */
  1051. options.nonip = DIR_SERVER;
  1052. }
  1053. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1054. *
  1055. * For the minmask option.
  1056. */
  1057. static void
  1058. doOptMinmask(tOptions* pOptions, tOptDesc* pOptDesc)
  1059. {
  1060. static const struct {long const rmin, rmax;} rng[1] = {
  1061. { 0, 32 } };
  1062. long val;
  1063. int ix;
  1064. char * pzEnd;
  1065. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1066. goto emit_ranges;
  1067. errno = 0;
  1068. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1069. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1070. goto bad_value;
  1071. if (*pzEnd != '\0')
  1072. goto bad_value;
  1073. for (ix = 0; ix < 1; ix++) {
  1074. if (val < rng[ix].rmin)
  1075. continue; /* ranges need not be ordered. */
  1076. if (val == rng[ix].rmin)
  1077. goto valid_return;
  1078. if (rng[ix].rmax == LONG_MIN)
  1079. continue;
  1080. if (val <= rng[ix].rmax)
  1081. goto valid_return;
  1082. }
  1083. bad_value:
  1084. option_usage_fp = stderr;
  1085. emit_ranges:
  1086. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1087. return;
  1088. valid_return:
  1089. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1090. free((void *)pOptDesc->optArg.argString);
  1091. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1092. }
  1093. pOptDesc->optArg.argInt = val;
  1094. }
  1095. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1096. *
  1097. * For the maxmask option.
  1098. */
  1099. static void
  1100. doOptMaxmask(tOptions* pOptions, tOptDesc* pOptDesc)
  1101. {
  1102. static const struct {long const rmin, rmax;} rng[1] = {
  1103. { 0, 32 } };
  1104. long val;
  1105. int ix;
  1106. char * pzEnd;
  1107. if (pOptions <= OPTPROC_EMIT_LIMIT)
  1108. goto emit_ranges;
  1109. errno = 0;
  1110. val = strtol(pOptDesc->optArg.argString, &pzEnd, 0);
  1111. if ((pOptDesc->optArg.argString == pzEnd) || (errno != 0))
  1112. goto bad_value;
  1113. if (*pzEnd != '\0')
  1114. goto bad_value;
  1115. for (ix = 0; ix < 1; ix++) {
  1116. if (val < rng[ix].rmin)
  1117. continue; /* ranges need not be ordered. */
  1118. if (val == rng[ix].rmin)
  1119. goto valid_return;
  1120. if (rng[ix].rmax == LONG_MIN)
  1121. continue;
  1122. if (val <= rng[ix].rmax)
  1123. goto valid_return;
  1124. }
  1125. bad_value:
  1126. option_usage_fp = stderr;
  1127. emit_ranges:
  1128. optionShowRange(pOptions, pOptDesc, (void *)rng, 1);
  1129. return;
  1130. valid_return:
  1131. if ((pOptDesc->fOptState & OPTST_ALLOC_ARG) != 0) {
  1132. free((void *)pOptDesc->optArg.argString);
  1133. pOptDesc->fOptState &= ~OPTST_ALLOC_ARG;
  1134. }
  1135. pOptDesc->optArg.argInt = val;
  1136. }
  1137. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1138. *
  1139. * For the version option.
  1140. */
  1141. static void
  1142. doOptVersion(tOptions* pOptions, tOptDesc* pOptDesc)
  1143. {
  1144. /* extracted from tcpprep_opts.def, line 567 */
  1145. fprintf(stderr, "tcpprep version: %s (build %s)", VERSION, svn_version());
  1146. #ifdef DEBUG
  1147. fprintf(stderr, " (debug)");
  1148. #endif
  1149. fprintf(stderr, "\n");
  1150. fprintf(stderr, "Copyright 2001-2009 by Aaron Turner <aturner at synfin dot net>\n");
  1151. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  1152. #ifdef HAVE_LIBDNET
  1153. fprintf(stderr, "Compiled against libdnet: %s\n", LIBDNET_VERSION);
  1154. #else
  1155. fprintf(stderr, "Not compiled with libdnet.\n");
  1156. #endif
  1157. #ifdef HAVE_WINPCAP
  1158. fprintf(stderr, "Compiled against winpcap: %s\n", get_pcap_version());
  1159. #else
  1160. fprintf(stderr, "Compiled against libpcap: %s\n", get_pcap_version());
  1161. #endif
  1162. #ifdef ENABLE_64BITS
  1163. fprintf(stderr, "64 bit packet counters: enabled\n");
  1164. #else
  1165. fprintf(stderr, "64 bit packet counters: disabled\n");
  1166. #endif
  1167. #ifdef ENABLE_VERBOSE
  1168. fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
  1169. #else
  1170. fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
  1171. #endif
  1172. exit(0);
  1173. }
  1174. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1175. *
  1176. * For the less-help option.
  1177. */
  1178. static void
  1179. doOptLess_Help(tOptions* pOptions, tOptDesc* pOptDesc)
  1180. {
  1181. /* extracted from tcpprep_opts.def, line 607 */
  1182. USAGE(EXIT_FAILURE);
  1183. }
  1184. /* extracted from /usr/local/share/autogen/optcode.tpl near line 629 */
  1185. #if ENABLE_NLS
  1186. #include <stdio.h>
  1187. #include <stdlib.h>
  1188. #include <string.h>
  1189. #include <unistd.h>
  1190. #include <autoopts/usage-txt.h>
  1191. static char* AO_gettext( char const* pz );
  1192. static void coerce_it(void** s);
  1193. static char*
  1194. AO_gettext( char const* pz )
  1195. {
  1196. char* pzRes;
  1197. if (pz == NULL)
  1198. return NULL;
  1199. pzRes = _(pz);
  1200. if (pzRes == pz)
  1201. return pzRes;
  1202. pzRes = strdup( pzRes );
  1203. if (pzRes == NULL) {
  1204. fputs( _("No memory for duping translated strings\n"), stderr );
  1205. exit( EXIT_FAILURE );
  1206. }
  1207. return pzRes;
  1208. }
  1209. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  1210. #define COERSION(_f) \
  1211. coerce_it((void*)&(tcpprepOptions._f))
  1212. /*
  1213. * This invokes the translation code (e.g. gettext(3)).
  1214. */
  1215. static void
  1216. translate_option_strings( void )
  1217. {
  1218. /*
  1219. * Guard against re-translation. It won't work. The strings will have
  1220. * been changed by the first pass through this code. One shot only.
  1221. */
  1222. if (option_usage_text.field_ct != 0) {
  1223. /*
  1224. * Do the translations. The first pointer follows the field count
  1225. * field. The field count field is the size of a pointer.
  1226. */
  1227. tOptDesc* pOD = tcpprepOptions.pOptDesc;
  1228. char** ppz = (char**)(void*)&(option_usage_text);
  1229. int ix = option_usage_text.field_ct;
  1230. do {
  1231. ppz++;
  1232. *ppz = AO_gettext(*ppz);
  1233. } while (--ix > 0);
  1234. COERSION(pzCopyright);
  1235. COERSION(pzCopyNotice);
  1236. COERSION(pzFullVersion);
  1237. COERSION(pzUsageTitle);
  1238. COERSION(pzExplain);
  1239. COERSION(pzDetail);
  1240. option_usage_text.field_ct = 0;
  1241. for (ix = tcpprepOptions.optCt; ix > 0; ix--, pOD++)
  1242. coerce_it((void*)&(pOD->pzText));
  1243. }
  1244. if ((tcpprepOptions.fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
  1245. tOptDesc* pOD = tcpprepOptions.pOptDesc;
  1246. int ix;
  1247. for (ix = tcpprepOptions.optCt; ix > 0; ix--, pOD++) {
  1248. coerce_it((void*)&(pOD->pz_Name));
  1249. coerce_it((void*)&(pOD->pz_DisableName));
  1250. coerce_it((void*)&(pOD->pz_DisablePfx));
  1251. }
  1252. /* prevent re-translation */
  1253. tcpprepOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
  1254. }
  1255. }
  1256. #endif /* ENABLE_NLS */
  1257. #ifdef __cplusplus
  1258. }
  1259. #endif
  1260. /* tcpprep_opts.c ends here */