tcpprep_opts.c 44 KB

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