tcpprep_opts.c 44 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 Saturday April 21, 2007 at 06:52:20 PM PDT
  6. * From the definitions tcpprep_opts.def
  7. * and the template file options
  8. *
  9. * Generated from AutoOpts 28:0:3 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:
  291. */
  292. tSCC zServicesText[] =
  293. "Load services file for server ports";
  294. tSCC zServices_NAME[] = "SERVICES";
  295. tSCC zServices_Name[] = "services";
  296. #define SERVICES_FLAGS (OPTST_DISABLED \
  297. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  298. /*
  299. * Nonip option description:
  300. */
  301. tSCC zNonipText[] =
  302. "Send non-IP traffic out server interface";
  303. tSCC zNonip_NAME[] = "NONIP";
  304. tSCC zNonip_Name[] = "nonip";
  305. #define NONIP_FLAGS (OPTST_DISABLED)
  306. /*
  307. * Ratio option description with
  308. * "Must also have options" and "Incompatible options":
  309. */
  310. tSCC zRatioText[] =
  311. "Ratio of client to server packets";
  312. tSCC zRatio_NAME[] = "RATIO";
  313. tSCC zRatio_Name[] = "ratio";
  314. tSCC zRatioDefaultArg[] = "2.0";
  315. static const int
  316. aRatioMustList[] = {
  317. INDEX_OPT_AUTO, NO_EQUIVALENT };
  318. #define RATIO_FLAGS (OPTST_DISABLED \
  319. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  320. /*
  321. * Minmask option description with
  322. * "Must also have options" and "Incompatible options":
  323. */
  324. tSCC zMinmaskText[] =
  325. "Minimum network mask length in auto mode";
  326. tSCC zMinmask_NAME[] = "MINMASK";
  327. tSCC zMinmask_Name[] = "minmask";
  328. #define zMinmaskDefaultArg ((char const*)30)
  329. static const int
  330. aMinmaskMustList[] = {
  331. INDEX_OPT_AUTO, NO_EQUIVALENT };
  332. #define MINMASK_FLAGS (OPTST_DISABLED \
  333. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  334. /*
  335. * Maxmask option description with
  336. * "Must also have options" and "Incompatible options":
  337. */
  338. tSCC zMaxmaskText[] =
  339. "Maximum network mask length in auto mode";
  340. tSCC zMaxmask_NAME[] = "MAXMASK";
  341. tSCC zMaxmask_Name[] = "maxmask";
  342. #define zMaxmaskDefaultArg ((char const*)8)
  343. static const int
  344. aMaxmaskMustList[] = {
  345. INDEX_OPT_AUTO, NO_EQUIVALENT };
  346. #define MAXMASK_FLAGS (OPTST_DISABLED \
  347. | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
  348. /*
  349. * Verbose option description:
  350. */
  351. #ifdef ENABLE_VERBOSE
  352. tSCC zVerboseText[] =
  353. "Print decoded packets via tcpdump to STDOUT";
  354. tSCC zVerbose_NAME[] = "VERBOSE";
  355. tSCC zVerbose_Name[] = "verbose";
  356. #define VERBOSE_FLAGS (OPTST_DISABLED | OPTST_IMM)
  357. #else /* disable Verbose */
  358. #define VALUE_OPT_VERBOSE NO_EQUIVALENT
  359. #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  360. #define zVerboseText NULL
  361. #define zVerbose_NAME NULL
  362. #define zVerbose_Name NULL
  363. #endif /* ENABLE_VERBOSE */
  364. /*
  365. * Decode option description with
  366. * "Must also have options" and "Incompatible options":
  367. */
  368. #ifdef ENABLE_VERBOSE
  369. tSCC zDecodeText[] =
  370. "Arguments passed to tcpdump decoder";
  371. tSCC zDecode_NAME[] = "DECODE";
  372. tSCC zDecode_Name[] = "decode";
  373. static const int
  374. aDecodeMustList[] = {
  375. INDEX_OPT_VERBOSE, NO_EQUIVALENT };
  376. #define DECODE_FLAGS (OPTST_DISABLED \
  377. | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
  378. #else /* disable Decode */
  379. #define VALUE_OPT_DECODE NO_EQUIVALENT
  380. #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
  381. #define aDecodeMustList NULL
  382. #define zDecodeText NULL
  383. #define zDecode_NAME NULL
  384. #define zDecode_Name NULL
  385. #endif /* ENABLE_VERBOSE */
  386. /*
  387. * Version option description:
  388. */
  389. tSCC zVersionText[] =
  390. "Print version information";
  391. tSCC zVersion_NAME[] = "VERSION";
  392. tSCC zVersion_Name[] = "version";
  393. #define VERSION_FLAGS (OPTST_DISABLED)
  394. /*
  395. * Less_Help option description:
  396. */
  397. tSCC zLess_HelpText[] =
  398. "Display less usage information and exit";
  399. tSCC zLess_Help_NAME[] = "LESS_HELP";
  400. tSCC zLess_Help_Name[] = "less-help";
  401. #define LESS_HELP_FLAGS (OPTST_DISABLED | OPTST_IMM)
  402. /*
  403. * Help/More_Help option descriptions:
  404. */
  405. tSCC zHelpText[] = "Display usage information and exit";
  406. tSCC zHelp_Name[] = "help";
  407. tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
  408. tSCC zMore_Help_Name[] = "more-help";
  409. /*
  410. * Save/Load_Opts option description:
  411. */
  412. tSCC zSave_OptsText[] = "Save the option state to a config file";
  413. tSCC zSave_Opts_Name[] = "save-opts";
  414. tSCC zLoad_OptsText[] = "Load options from a config file";
  415. tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
  416. tSCC zNotLoad_Opts_Name[] = "no-load-opts";
  417. tSCC zNotLoad_Opts_Pfx[] = "no";
  418. #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
  419. /*
  420. * Declare option callback procedures
  421. */
  422. #ifdef DEBUG
  423. static tOptProc doOptDbug;
  424. #else /* not DEBUG */
  425. # define doOptDbug NULL
  426. #endif /* def/not DEBUG */
  427. extern tOptProc
  428. optionPagedUsage;
  429. static tOptProc
  430. doOptAuto, doOptCidr, doOptComment,
  431. doOptExclude, doOptInclude, doOptLess_Help,
  432. doOptMac, doOptMaxmask, doOptMinmask,
  433. doOptNo_Arg_Comment, doOptNonip, doOptPort,
  434. doOptRegex, doOptServices, doOptVersion,
  435. doUsageOpt;
  436. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  437. *
  438. * Define the Tcpprep Option Descriptions.
  439. */
  440. static tOptDesc optDesc[ OPTION_CT ] = {
  441. { /* entry idx, value */ 0, VALUE_OPT_DBUG,
  442. /* equiv idx, value */ 0, VALUE_OPT_DBUG,
  443. /* equivalenced to */ NO_EQUIVALENT,
  444. /* min, max, act ct */ 0, 1, 0,
  445. /* opt state flags */ DBUG_FLAGS, 0,
  446. /* last opt argumnt */ { zDbugDefaultArg },
  447. /* arg list/cookie */ NULL,
  448. /* must/cannot opts */ NULL, NULL,
  449. /* option proc */ doOptDbug,
  450. /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
  451. /* disablement strs */ NULL, NULL },
  452. { /* entry idx, value */ 1, VALUE_OPT_AUTO,
  453. /* equiv idx, value */ 1, VALUE_OPT_AUTO,
  454. /* equivalenced to */ NO_EQUIVALENT,
  455. /* min, max, act ct */ 0, 1, 0,
  456. /* opt state flags */ AUTO_FLAGS, 0,
  457. /* last opt argumnt */ { NULL },
  458. /* arg list/cookie */ NULL,
  459. /* must/cannot opts */ NULL, aAutoCantList,
  460. /* option proc */ doOptAuto,
  461. /* desc, NAME, name */ zAutoText, zAuto_NAME, zAuto_Name,
  462. /* disablement strs */ NULL, NULL },
  463. { /* entry idx, value */ 2, VALUE_OPT_CIDR,
  464. /* equiv idx, value */ 2, VALUE_OPT_CIDR,
  465. /* equivalenced to */ NO_EQUIVALENT,
  466. /* min, max, act ct */ 0, 1, 0,
  467. /* opt state flags */ CIDR_FLAGS, 0,
  468. /* last opt argumnt */ { NULL },
  469. /* arg list/cookie */ NULL,
  470. /* must/cannot opts */ NULL, aCidrCantList,
  471. /* option proc */ doOptCidr,
  472. /* desc, NAME, name */ zCidrText, zCidr_NAME, zCidr_Name,
  473. /* disablement strs */ NULL, NULL },
  474. { /* entry idx, value */ 3, VALUE_OPT_REGEX,
  475. /* equiv idx, value */ 3, VALUE_OPT_REGEX,
  476. /* equivalenced to */ NO_EQUIVALENT,
  477. /* min, max, act ct */ 0, 1, 0,
  478. /* opt state flags */ REGEX_FLAGS, 0,
  479. /* last opt argumnt */ { NULL },
  480. /* arg list/cookie */ NULL,
  481. /* must/cannot opts */ NULL, aRegexCantList,
  482. /* option proc */ doOptRegex,
  483. /* desc, NAME, name */ zRegexText, zRegex_NAME, zRegex_Name,
  484. /* disablement strs */ NULL, NULL },
  485. { /* entry idx, value */ 4, VALUE_OPT_PORT,
  486. /* equiv idx, value */ 4, VALUE_OPT_PORT,
  487. /* equivalenced to */ NO_EQUIVALENT,
  488. /* min, max, act ct */ 0, 1, 0,
  489. /* opt state flags */ PORT_FLAGS, 0,
  490. /* last opt argumnt */ { NULL },
  491. /* arg list/cookie */ NULL,
  492. /* must/cannot opts */ NULL, aPortCantList,
  493. /* option proc */ doOptPort,
  494. /* desc, NAME, name */ zPortText, zPort_NAME, zPort_Name,
  495. /* disablement strs */ NULL, NULL },
  496. { /* entry idx, value */ 5, VALUE_OPT_MAC,
  497. /* equiv idx, value */ 5, VALUE_OPT_MAC,
  498. /* equivalenced to */ NO_EQUIVALENT,
  499. /* min, max, act ct */ 0, 1, 0,
  500. /* opt state flags */ MAC_FLAGS, 0,
  501. /* last opt argumnt */ { NULL },
  502. /* arg list/cookie */ NULL,
  503. /* must/cannot opts */ NULL, aMacCantList,
  504. /* option proc */ doOptMac,
  505. /* desc, NAME, name */ zMacText, zMac_NAME, zMac_Name,
  506. /* disablement strs */ NULL, NULL },
  507. { /* entry idx, value */ 6, VALUE_OPT_COMMENT,
  508. /* equiv idx, value */ 6, VALUE_OPT_COMMENT,
  509. /* equivalenced to */ NO_EQUIVALENT,
  510. /* min, max, act ct */ 0, 1, 0,
  511. /* opt state flags */ COMMENT_FLAGS, 0,
  512. /* last opt argumnt */ { NULL },
  513. /* arg list/cookie */ NULL,
  514. /* must/cannot opts */ NULL, NULL,
  515. /* option proc */ doOptComment,
  516. /* desc, NAME, name */ zCommentText, zComment_NAME, zComment_Name,
  517. /* disablement strs */ NULL, NULL },
  518. { /* entry idx, value */ 7, VALUE_OPT_NO_ARG_COMMENT,
  519. /* equiv idx, value */ 7, VALUE_OPT_NO_ARG_COMMENT,
  520. /* equivalenced to */ NO_EQUIVALENT,
  521. /* min, max, act ct */ 0, 1, 0,
  522. /* opt state flags */ NO_ARG_COMMENT_FLAGS, 0,
  523. /* last opt argumnt */ { NULL },
  524. /* arg list/cookie */ NULL,
  525. /* must/cannot opts */ NULL, NULL,
  526. /* option proc */ doOptNo_Arg_Comment,
  527. /* desc, NAME, name */ zNo_Arg_CommentText, zNo_Arg_Comment_NAME, zNo_Arg_Comment_Name,
  528. /* disablement strs */ NULL, NULL },
  529. { /* entry idx, value */ 8, VALUE_OPT_INCLUDE,
  530. /* equiv idx, value */ 8, VALUE_OPT_INCLUDE,
  531. /* equivalenced to */ NO_EQUIVALENT,
  532. /* min, max, act ct */ 0, 1, 0,
  533. /* opt state flags */ INCLUDE_FLAGS, 0,
  534. /* last opt argumnt */ { NULL },
  535. /* arg list/cookie */ NULL,
  536. /* must/cannot opts */ NULL, aIncludeCantList,
  537. /* option proc */ doOptInclude,
  538. /* desc, NAME, name */ zIncludeText, zInclude_NAME, zInclude_Name,
  539. /* disablement strs */ NULL, NULL },
  540. { /* entry idx, value */ 9, VALUE_OPT_EXCLUDE,
  541. /* equiv idx, value */ 9, VALUE_OPT_EXCLUDE,
  542. /* equivalenced to */ NO_EQUIVALENT,
  543. /* min, max, act ct */ 0, 1, 0,
  544. /* opt state flags */ EXCLUDE_FLAGS, 0,
  545. /* last opt argumnt */ { NULL },
  546. /* arg list/cookie */ NULL,
  547. /* must/cannot opts */ NULL, aExcludeCantList,
  548. /* option proc */ doOptExclude,
  549. /* desc, NAME, name */ zExcludeText, zExclude_NAME, zExclude_Name,
  550. /* disablement strs */ NULL, NULL },
  551. { /* entry idx, value */ 10, VALUE_OPT_CACHEFILE,
  552. /* equiv idx, value */ 10, VALUE_OPT_CACHEFILE,
  553. /* equivalenced to */ NO_EQUIVALENT,
  554. /* min, max, act ct */ 0, 1, 0,
  555. /* opt state flags */ CACHEFILE_FLAGS, 0,
  556. /* last opt argumnt */ { NULL },
  557. /* arg list/cookie */ NULL,
  558. /* must/cannot opts */ NULL, NULL,
  559. /* option proc */ NULL,
  560. /* desc, NAME, name */ zCachefileText, zCachefile_NAME, zCachefile_Name,
  561. /* disablement strs */ NULL, NULL },
  562. { /* entry idx, value */ 11, VALUE_OPT_PCAP,
  563. /* equiv idx, value */ 11, VALUE_OPT_PCAP,
  564. /* equivalenced to */ NO_EQUIVALENT,
  565. /* min, max, act ct */ 0, 1, 0,
  566. /* opt state flags */ PCAP_FLAGS, 0,
  567. /* last opt argumnt */ { NULL },
  568. /* arg list/cookie */ NULL,
  569. /* must/cannot opts */ NULL, NULL,
  570. /* option proc */ NULL,
  571. /* desc, NAME, name */ zPcapText, zPcap_NAME, zPcap_Name,
  572. /* disablement strs */ NULL, NULL },
  573. { /* entry idx, value */ 12, VALUE_OPT_PRINT_COMMENT,
  574. /* equiv idx, value */ 12, VALUE_OPT_PRINT_COMMENT,
  575. /* equivalenced to */ NO_EQUIVALENT,
  576. /* min, max, act ct */ 0, 1, 0,
  577. /* opt state flags */ PRINT_COMMENT_FLAGS, 0,
  578. /* last opt argumnt */ { NULL },
  579. /* arg list/cookie */ NULL,
  580. /* must/cannot opts */ NULL, NULL,
  581. /* option proc */ NULL,
  582. /* desc, NAME, name */ zPrint_CommentText, zPrint_Comment_NAME, zPrint_Comment_Name,
  583. /* disablement strs */ NULL, NULL },
  584. { /* entry idx, value */ 13, VALUE_OPT_PRINT_INFO,
  585. /* equiv idx, value */ 13, VALUE_OPT_PRINT_INFO,
  586. /* equivalenced to */ NO_EQUIVALENT,
  587. /* min, max, act ct */ 0, 1, 0,
  588. /* opt state flags */ PRINT_INFO_FLAGS, 0,
  589. /* last opt argumnt */ { NULL },
  590. /* arg list/cookie */ NULL,
  591. /* must/cannot opts */ NULL, NULL,
  592. /* option proc */ NULL,
  593. /* desc, NAME, name */ zPrint_InfoText, zPrint_Info_NAME, zPrint_Info_Name,
  594. /* disablement strs */ NULL, NULL },
  595. { /* entry idx, value */ 14, VALUE_OPT_PRINT_STATS,
  596. /* equiv idx, value */ 14, VALUE_OPT_PRINT_STATS,
  597. /* equivalenced to */ NO_EQUIVALENT,
  598. /* min, max, act ct */ 0, 1, 0,
  599. /* opt state flags */ PRINT_STATS_FLAGS, 0,
  600. /* last opt argumnt */ { NULL },
  601. /* arg list/cookie */ NULL,
  602. /* must/cannot opts */ NULL, NULL,
  603. /* option proc */ NULL,
  604. /* desc, NAME, name */ zPrint_StatsText, zPrint_Stats_NAME, zPrint_Stats_Name,
  605. /* disablement strs */ NULL, NULL },
  606. { /* entry idx, value */ 15, VALUE_OPT_SERVICES,
  607. /* equiv idx, value */ 15, VALUE_OPT_SERVICES,
  608. /* equivalenced to */ NO_EQUIVALENT,
  609. /* min, max, act ct */ 0, 1, 0,
  610. /* opt state flags */ SERVICES_FLAGS, 0,
  611. /* last opt argumnt */ { NULL },
  612. /* arg list/cookie */ NULL,
  613. /* must/cannot opts */ NULL, NULL,
  614. /* option proc */ doOptServices,
  615. /* desc, NAME, name */ zServicesText, zServices_NAME, zServices_Name,
  616. /* disablement strs */ NULL, NULL },
  617. { /* entry idx, value */ 16, VALUE_OPT_NONIP,
  618. /* equiv idx, value */ 16, VALUE_OPT_NONIP,
  619. /* equivalenced to */ NO_EQUIVALENT,
  620. /* min, max, act ct */ 0, 1, 0,
  621. /* opt state flags */ NONIP_FLAGS, 0,
  622. /* last opt argumnt */ { NULL },
  623. /* arg list/cookie */ NULL,
  624. /* must/cannot opts */ NULL, NULL,
  625. /* option proc */ doOptNonip,
  626. /* desc, NAME, name */ zNonipText, zNonip_NAME, zNonip_Name,
  627. /* disablement strs */ NULL, NULL },
  628. { /* entry idx, value */ 17, VALUE_OPT_RATIO,
  629. /* equiv idx, value */ 17, VALUE_OPT_RATIO,
  630. /* equivalenced to */ NO_EQUIVALENT,
  631. /* min, max, act ct */ 0, 1, 0,
  632. /* opt state flags */ RATIO_FLAGS, 0,
  633. /* last opt argumnt */ { zRatioDefaultArg },
  634. /* arg list/cookie */ NULL,
  635. /* must/cannot opts */ aRatioMustList, NULL,
  636. /* option proc */ NULL,
  637. /* desc, NAME, name */ zRatioText, zRatio_NAME, zRatio_Name,
  638. /* disablement strs */ NULL, NULL },
  639. { /* entry idx, value */ 18, VALUE_OPT_MINMASK,
  640. /* equiv idx, value */ 18, VALUE_OPT_MINMASK,
  641. /* equivalenced to */ NO_EQUIVALENT,
  642. /* min, max, act ct */ 0, 1, 0,
  643. /* opt state flags */ MINMASK_FLAGS, 0,
  644. /* last opt argumnt */ { zMinmaskDefaultArg },
  645. /* arg list/cookie */ NULL,
  646. /* must/cannot opts */ aMinmaskMustList, NULL,
  647. /* option proc */ doOptMinmask,
  648. /* desc, NAME, name */ zMinmaskText, zMinmask_NAME, zMinmask_Name,
  649. /* disablement strs */ NULL, NULL },
  650. { /* entry idx, value */ 19, VALUE_OPT_MAXMASK,
  651. /* equiv idx, value */ 19, VALUE_OPT_MAXMASK,
  652. /* equivalenced to */ NO_EQUIVALENT,
  653. /* min, max, act ct */ 0, 1, 0,
  654. /* opt state flags */ MAXMASK_FLAGS, 0,
  655. /* last opt argumnt */ { zMaxmaskDefaultArg },
  656. /* arg list/cookie */ NULL,
  657. /* must/cannot opts */ aMaxmaskMustList, NULL,
  658. /* option proc */ doOptMaxmask,
  659. /* desc, NAME, name */ zMaxmaskText, zMaxmask_NAME, zMaxmask_Name,
  660. /* disablement strs */ NULL, NULL },
  661. { /* entry idx, value */ 20, VALUE_OPT_VERBOSE,
  662. /* equiv idx, value */ 20, VALUE_OPT_VERBOSE,
  663. /* equivalenced to */ NO_EQUIVALENT,
  664. /* min, max, act ct */ 0, 1, 0,
  665. /* opt state flags */ VERBOSE_FLAGS, 0,
  666. /* last opt argumnt */ { NULL },
  667. /* arg list/cookie */ NULL,
  668. /* must/cannot opts */ NULL, NULL,
  669. /* option proc */ NULL,
  670. /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
  671. /* disablement strs */ NULL, NULL },
  672. { /* entry idx, value */ 21, VALUE_OPT_DECODE,
  673. /* equiv idx, value */ 21, VALUE_OPT_DECODE,
  674. /* equivalenced to */ NO_EQUIVALENT,
  675. /* min, max, act ct */ 0, 1, 0,
  676. /* opt state flags */ DECODE_FLAGS, 0,
  677. /* last opt argumnt */ { NULL },
  678. /* arg list/cookie */ NULL,
  679. /* must/cannot opts */ aDecodeMustList, NULL,
  680. /* option proc */ NULL,
  681. /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
  682. /* disablement strs */ NULL, NULL },
  683. { /* entry idx, value */ 22, VALUE_OPT_VERSION,
  684. /* equiv idx, value */ 22, VALUE_OPT_VERSION,
  685. /* equivalenced to */ NO_EQUIVALENT,
  686. /* min, max, act ct */ 0, 1, 0,
  687. /* opt state flags */ VERSION_FLAGS, 0,
  688. /* last opt argumnt */ { NULL },
  689. /* arg list/cookie */ NULL,
  690. /* must/cannot opts */ NULL, NULL,
  691. /* option proc */ doOptVersion,
  692. /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
  693. /* disablement strs */ NULL, NULL },
  694. { /* entry idx, value */ 23, VALUE_OPT_LESS_HELP,
  695. /* equiv idx, value */ 23, VALUE_OPT_LESS_HELP,
  696. /* equivalenced to */ NO_EQUIVALENT,
  697. /* min, max, act ct */ 0, 1, 0,
  698. /* opt state flags */ LESS_HELP_FLAGS, 0,
  699. /* last opt argumnt */ { NULL },
  700. /* arg list/cookie */ NULL,
  701. /* must/cannot opts */ NULL, NULL,
  702. /* option proc */ doOptLess_Help,
  703. /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
  704. /* disablement strs */ NULL, NULL },
  705. { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
  706. /* equiv idx value */ NO_EQUIVALENT, 0,
  707. /* equivalenced to */ NO_EQUIVALENT,
  708. /* min, max, act ct */ 0, 1, 0,
  709. /* opt state flags */ OPTST_IMM, 0,
  710. /* last opt argumnt */ { NULL },
  711. /* arg list/cookie */ NULL,
  712. /* must/cannot opts */ NULL, NULL,
  713. /* option proc */ doUsageOpt,
  714. /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
  715. /* disablement strs */ NULL, NULL },
  716. { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
  717. /* equiv idx value */ NO_EQUIVALENT, 0,
  718. /* equivalenced to */ NO_EQUIVALENT,
  719. /* min, max, act ct */ 0, 1, 0,
  720. /* opt state flags */ OPTST_IMM, 0,
  721. /* last opt argumnt */ { NULL },
  722. /* arg list/cookie */ NULL,
  723. /* must/cannot opts */ NULL, NULL,
  724. /* option proc */ optionPagedUsage,
  725. /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
  726. /* disablement strs */ NULL, NULL },
  727. { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
  728. /* equiv idx value */ NO_EQUIVALENT, 0,
  729. /* equivalenced to */ NO_EQUIVALENT,
  730. /* min, max, act ct */ 0, 1, 0,
  731. /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
  732. | OPTST_ARG_OPTIONAL, 0,
  733. /* last opt argumnt */ { NULL },
  734. /* arg list/cookie */ NULL,
  735. /* must/cannot opts */ NULL, NULL,
  736. /* option proc */ NULL,
  737. /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
  738. /* disablement strs */ NULL, NULL },
  739. { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
  740. /* equiv idx value */ NO_EQUIVALENT, 0,
  741. /* equivalenced to */ NO_EQUIVALENT,
  742. /* min, max, act ct */ 0, NOLIMIT, 0,
  743. /* opt state flags */ OPTST_DISABLE_IMM | \
  744. OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
  745. /* last opt argumnt */ { NULL },
  746. /* arg list/cookie */ NULL,
  747. /* must/cannot opts */ NULL, NULL,
  748. /* option proc */ optionLoadOpt,
  749. /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
  750. /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
  751. };
  752. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  753. *
  754. * Define the Tcpprep Option Environment
  755. */
  756. tSCC zPROGNAME[] = "TCPPREP";
  757. tSCC zUsageTitle[] =
  758. "tcpprep (tcpprep) - Create a tcpreplay cache cache file from a pcap file.\n\
  759. USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
  760. tSCC zRcName[] = ".tcppreprc";
  761. tSCC* apzHomeList[] = {
  762. "$$/",
  763. NULL };
  764. #define zBugsAddr NULL
  765. tSCC zExplain[] = "\n\
  766. tcpprep is a ``pcap(3)'' file pre-processor which creates a cache\n\
  767. file which provides \"rules\" for ``tcprewrite(1)'' and ``tcpreplay(1)''\n\
  768. on how to process and send packets.\n";
  769. tSCC zDetail[] = "\n\
  770. The basic operation of tcpreplay is to resend all packets from the\n\
  771. input file(s) out a single file. Tcpprep processes a pcap file and \n\
  772. applies a set of user-specified rules to create a cache file which \n\
  773. tells tcpreplay wether or not to send each packet and which interface the\n\
  774. packet should be sent out of.\n\n\
  775. For more details, please see the Tcpreplay Manual at:\n\
  776. http://tcpreplay.synfin.net/wiki/manual\n";
  777. #define zFullVersion NULL
  778. /* extracted from /opt/local/share/autogen/optcode.tpl near line 378 */
  779. #if defined(ENABLE_NLS)
  780. # define OPTPROC_BASE OPTPROC_TRANSLATE
  781. static tOptionXlateProc translate_option_strings;
  782. #else
  783. # define OPTPROC_BASE OPTPROC_NONE
  784. # define translate_option_strings NULL
  785. #endif /* ENABLE_NLS */
  786. tOptions tcpprepOptions = {
  787. OPTIONS_STRUCT_VERSION,
  788. 0, NULL, /* original argc + argv */
  789. ( OPTPROC_BASE
  790. + OPTPROC_ERRSTOP
  791. + OPTPROC_SHORTOPT
  792. + OPTPROC_LONGOPT
  793. + OPTPROC_NO_REQ_OPT
  794. + OPTPROC_NO_ARGS
  795. + OPTPROC_GNUUSAGE
  796. + OPTPROC_HAS_IMMED ),
  797. 0, NULL, /* current option index, current option */
  798. NULL, NULL, zPROGNAME,
  799. zRcName, zCopyright, zCopyrightNotice,
  800. zFullVersion, apzHomeList, zUsageTitle,
  801. zExplain, zDetail, optDesc,
  802. zBugsAddr, /* address to send bugs to */
  803. NULL, NULL, /* extensions/saved state */
  804. optionUsage, /* usage procedure */
  805. translate_option_strings, /* translation procedure */
  806. /*
  807. * Indexes to special options
  808. */
  809. { INDEX_OPT_MORE_HELP,
  810. INDEX_OPT_SAVE_OPTS,
  811. NO_EQUIVALENT /* index of '-#' option */,
  812. NO_EQUIVALENT /* index of default opt */
  813. },
  814. OPTION_CT, 24 /* user option count */
  815. };
  816. /*
  817. * Create the static procedure(s) declared above.
  818. */
  819. static void
  820. doUsageOpt(
  821. tOptions* pOptions,
  822. tOptDesc* pOptDesc )
  823. {
  824. USAGE( EXIT_SUCCESS );
  825. }
  826. /* * * * * * *
  827. *
  828. * For the dbug option, when DEBUG is #define-d.
  829. */
  830. #ifdef DEBUG
  831. static void
  832. doOptDbug(
  833. tOptions* pOptions,
  834. tOptDesc* pOptDesc )
  835. {
  836. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  837. { 0, 5 } };
  838. int val;
  839. int ix;
  840. char const* pzIndent = "\t\t\t\t ";
  841. extern FILE* option_usage_fp;
  842. if (pOptDesc == NULL) /* usage is requesting range list
  843. option_usage_fp has already been set */
  844. goto emit_ranges;
  845. val = atoi( pOptDesc->optArg.argString );
  846. for (ix = 0; ix < 1; ix++) {
  847. if (val < rng[ix].rmin)
  848. continue; /* ranges need not be ordered. */
  849. if (val == rng[ix].rmin)
  850. goto valid_return;
  851. if (rng[ix].rmax == INT_MIN)
  852. continue;
  853. if (val <= rng[ix].rmax)
  854. goto valid_return;
  855. }
  856. option_usage_fp = stderr;
  857. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  858. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  859. pzIndent = "\t";
  860. emit_ranges:
  861. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  862. pzIndent, rng[0].rmin, rng[0].rmax );
  863. if (pOptDesc == NULL)
  864. return;
  865. USAGE( EXIT_FAILURE );
  866. /* NOTREACHED */
  867. return;
  868. valid_return:
  869. pOptDesc->optArg.argInt = val;
  870. }
  871. #endif /* defined DEBUG */
  872. /* * * * * * *
  873. *
  874. * For the auto option.
  875. */
  876. static void
  877. doOptAuto(
  878. tOptions* pOptions,
  879. tOptDesc* pOptDesc )
  880. {
  881. /* extracted from tcpprep_opts.def, line 89 */
  882. options.mode = AUTO_MODE;
  883. if (strcmp(OPT_ARG(AUTO), "bridge") == 0) {
  884. options.automode = BRIDGE_MODE;
  885. }
  886. else if (strcmp(OPT_ARG(AUTO), "router") == 0) {
  887. options.automode = ROUTER_MODE;
  888. }
  889. else if (strcmp(OPT_ARG(AUTO), "client") == 0) {
  890. options.automode = CLIENT_MODE;
  891. }
  892. else if (strcmp(OPT_ARG(AUTO), "server") == 0) {
  893. options.automode = SERVER_MODE;
  894. }
  895. else {
  896. errx(1, "Invalid auto mode type: %s", OPT_ARG(AUTO));
  897. }
  898. }
  899. /* * * * * * *
  900. *
  901. * For the cidr option.
  902. */
  903. static void
  904. doOptCidr(
  905. tOptions* pOptions,
  906. tOptDesc* pOptDesc )
  907. {
  908. /* extracted from tcpprep_opts.def, line 151 */
  909. char *cidr = safe_strdup(OPT_ARG(CIDR));
  910. options.mode = CIDR_MODE;
  911. if (!parse_cidr(&options.cidrdata, cidr, ","))
  912. errx(1, "Unable to parse CIDR map: %s", OPT_ARG(CIDR));
  913. free(cidr);
  914. }
  915. /* * * * * * *
  916. *
  917. * For the regex option.
  918. */
  919. static void
  920. doOptRegex(
  921. tOptions* pOptions,
  922. tOptDesc* pOptDesc )
  923. {
  924. /* extracted from tcpprep_opts.def, line 177 */
  925. int regex_error;
  926. char ebuf[EBUF_SIZE];
  927. options.mode = REGEX_MODE;
  928. if ((regex_error = regcomp(&options.preg, OPT_ARG(REGEX),
  929. REG_EXTENDED|REG_NOSUB))) {
  930. regerror(regex_error, &options.preg, ebuf, EBUF_SIZE);
  931. errx(1, "Unable to compile regex: %s", ebuf);
  932. }
  933. }
  934. /* * * * * * *
  935. *
  936. * For the port option.
  937. */
  938. static void
  939. doOptPort(
  940. tOptions* pOptions,
  941. tOptDesc* pOptDesc )
  942. {
  943. /* extracted from tcpprep_opts.def, line 205 */
  944. options.mode = PORT_MODE;
  945. }
  946. /* * * * * * *
  947. *
  948. * For the mac option.
  949. */
  950. static void
  951. doOptMac(
  952. tOptions* pOptions,
  953. tOptDesc* pOptDesc )
  954. {
  955. /* extracted from tcpprep_opts.def, line 226 */
  956. options.mode = MAC_MODE;
  957. options.maclist = safe_strdup(OPT_ARG(MAC));
  958. }
  959. /* * * * * * *
  960. *
  961. * For the comment option.
  962. */
  963. static void
  964. doOptComment(
  965. tOptions* pOptions,
  966. tOptDesc* pOptDesc )
  967. {
  968. /* extracted from tcpprep_opts.def, line 247 */
  969. /* our comment_len is only 16bit - myargs[] */
  970. if (strlen(OPT_ARG(COMMENT)) > ((1 << 16) - 1 - MYARGS_LEN))
  971. errx(1, "Comment length %d is longer then max allowed (%d)",
  972. strlen(OPT_ARG(COMMENT)), (1 << 16) - 1 - MYARGS_LEN);
  973. /* save the comment */
  974. options.comment = (char *)safe_malloc(strlen(OPT_ARG(COMMENT)) + 1);
  975. strcpy(options.comment, OPT_ARG(COMMENT));
  976. }
  977. /* * * * * * *
  978. *
  979. * For the no-arg-comment option.
  980. */
  981. static void
  982. doOptNo_Arg_Comment(
  983. tOptions* pOptions,
  984. tOptDesc* pOptDesc )
  985. {
  986. /* extracted from tcpprep_opts.def, line 269 */
  987. options.nocomment = 1;
  988. }
  989. /* * * * * * *
  990. *
  991. * For the include option.
  992. */
  993. static void
  994. doOptInclude(
  995. tOptions* pOptions,
  996. tOptDesc* pOptDesc )
  997. {
  998. /* extracted from tcpprep_opts.def, line 289 */
  999. char *include;
  1000. include = safe_strdup(OPT_ARG(INCLUDE));
  1001. options.xX.mode = xX_MODE_INCLUDE;
  1002. if ((options.xX.mode = parse_xX_str(&options.xX, include, &options.bpf)) == xXError)
  1003. errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(INCLUDE));
  1004. free(include);
  1005. }
  1006. /* * * * * * *
  1007. *
  1008. * For the exclude option.
  1009. */
  1010. static void
  1011. doOptExclude(
  1012. tOptions* pOptions,
  1013. tOptDesc* pOptDesc )
  1014. {
  1015. /* extracted from tcpprep_opts.def, line 336 */
  1016. char *exclude;
  1017. exclude = safe_strdup(OPT_ARG(EXCLUDE));
  1018. options.xX.mode = xX_MODE_EXCLUDE;
  1019. if ((options.xX.mode = parse_xX_str(&options.xX, exclude, &options.bpf)) == xXError)
  1020. errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(EXCLUDE));
  1021. free(exclude);
  1022. }
  1023. /* * * * * * *
  1024. *
  1025. * For the services option.
  1026. */
  1027. static void
  1028. doOptServices(
  1029. tOptions* pOptions,
  1030. tOptDesc* pOptDesc )
  1031. {
  1032. /* extracted from tcpprep_opts.def, line 422 */
  1033. parse_services(OPT_ARG(SERVICES), &options.services);
  1034. }
  1035. /* * * * * * *
  1036. *
  1037. * For the nonip option.
  1038. */
  1039. static void
  1040. doOptNonip(
  1041. tOptions* pOptions,
  1042. tOptDesc* pOptDesc )
  1043. {
  1044. /* extracted from tcpprep_opts.def, line 433 */
  1045. options.nonip = DIR_SERVER;
  1046. }
  1047. /* * * * * * *
  1048. *
  1049. * For the minmask option.
  1050. */
  1051. static void
  1052. doOptMinmask(
  1053. tOptions* pOptions,
  1054. tOptDesc* pOptDesc )
  1055. {
  1056. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  1057. { 0, 32 } };
  1058. int val;
  1059. int ix;
  1060. char const* pzIndent = "\t\t\t\t ";
  1061. extern FILE* option_usage_fp;
  1062. if (pOptDesc == NULL) /* usage is requesting range list
  1063. option_usage_fp has already been set */
  1064. goto emit_ranges;
  1065. val = atoi( pOptDesc->optArg.argString );
  1066. for (ix = 0; ix < 1; ix++) {
  1067. if (val < rng[ix].rmin)
  1068. continue; /* ranges need not be ordered. */
  1069. if (val == rng[ix].rmin)
  1070. goto valid_return;
  1071. if (rng[ix].rmax == INT_MIN)
  1072. continue;
  1073. if (val <= rng[ix].rmax)
  1074. goto valid_return;
  1075. }
  1076. option_usage_fp = stderr;
  1077. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  1078. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  1079. pzIndent = "\t";
  1080. emit_ranges:
  1081. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  1082. pzIndent, rng[0].rmin, rng[0].rmax );
  1083. if (pOptDesc == NULL)
  1084. return;
  1085. USAGE( EXIT_FAILURE );
  1086. /* NOTREACHED */
  1087. return;
  1088. valid_return:
  1089. pOptDesc->optArg.argInt = val;
  1090. }
  1091. /* * * * * * *
  1092. *
  1093. * For the maxmask option.
  1094. */
  1095. static void
  1096. doOptMaxmask(
  1097. tOptions* pOptions,
  1098. tOptDesc* pOptDesc )
  1099. {
  1100. static const struct {const int rmin, rmax;} rng[ 1 ] = {
  1101. { 0, 32 } };
  1102. int val;
  1103. int ix;
  1104. char const* pzIndent = "\t\t\t\t ";
  1105. extern FILE* option_usage_fp;
  1106. if (pOptDesc == NULL) /* usage is requesting range list
  1107. option_usage_fp has already been set */
  1108. goto emit_ranges;
  1109. val = atoi( pOptDesc->optArg.argString );
  1110. for (ix = 0; ix < 1; ix++) {
  1111. if (val < rng[ix].rmin)
  1112. continue; /* ranges need not be ordered. */
  1113. if (val == rng[ix].rmin)
  1114. goto valid_return;
  1115. if (rng[ix].rmax == INT_MIN)
  1116. continue;
  1117. if (val <= rng[ix].rmax)
  1118. goto valid_return;
  1119. }
  1120. option_usage_fp = stderr;
  1121. fprintf(stderr, _("%s error: %s option value ``%s''is out of range.\n"),
  1122. pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->optArg.argString);
  1123. pzIndent = "\t";
  1124. emit_ranges:
  1125. fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
  1126. pzIndent, rng[0].rmin, rng[0].rmax );
  1127. if (pOptDesc == NULL)
  1128. return;
  1129. USAGE( EXIT_FAILURE );
  1130. /* NOTREACHED */
  1131. return;
  1132. valid_return:
  1133. pOptDesc->optArg.argInt = val;
  1134. }
  1135. /* * * * * * *
  1136. *
  1137. * For the version option.
  1138. */
  1139. static void
  1140. doOptVersion(
  1141. tOptions* pOptions,
  1142. tOptDesc* pOptDesc )
  1143. {
  1144. /* extracted from tcpprep_opts.def, line 533 */
  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-2007 by Aaron Turner <aturner at synfin dot net>\n");
  1151. fprintf(stderr, "Cache file supported: %s\n", CACHEVERSION);
  1152. #ifdef HAVE_LIBNET
  1153. fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
  1154. #else
  1155. fprintf(stderr, "Not compiled with libnet.\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(
  1180. tOptions* pOptions,
  1181. tOptDesc* pOptDesc )
  1182. {
  1183. /* extracted from tcpprep_opts.def, line 573 */
  1184. USAGE(EXIT_FAILURE);
  1185. }
  1186. /* extracted from /opt/local/share/autogen/optcode.tpl near line 475 */
  1187. #if ENABLE_NLS
  1188. #include <stdio.h>
  1189. #include <stdlib.h>
  1190. #include <string.h>
  1191. #include <unistd.h>
  1192. #include <autoopts/usage-txt.h>
  1193. static char* AO_gettext( char const* pz );
  1194. static void coerce_it(void** s);
  1195. static char*
  1196. AO_gettext( char const* pz )
  1197. {
  1198. char* pzRes;
  1199. if (pz == NULL)
  1200. return NULL;
  1201. pzRes = _(pz);
  1202. if (pzRes == pz)
  1203. return pzRes;
  1204. pzRes = strdup( pzRes );
  1205. if (pzRes == NULL) {
  1206. fputs( _("No memory for duping translated strings\n"), stderr );
  1207. exit( EXIT_FAILURE );
  1208. }
  1209. return pzRes;
  1210. }
  1211. static void coerce_it(void** s) { *s = AO_gettext(*s); }
  1212. #define COERSION(_f) \
  1213. coerce_it((void*)&(tcpprepOptions._f))
  1214. /*
  1215. * This invokes the translation code (e.g. gettext(3)).
  1216. */
  1217. static void
  1218. translate_option_strings( void )
  1219. {
  1220. /*
  1221. * Guard against re-translation. It won't work. The strings will have
  1222. * been changed by the first pass through this code. One shot only.
  1223. */
  1224. if (option_usage_text.field_ct == 0)
  1225. return;
  1226. /*
  1227. * Do the translations. The first pointer follows the field count field.
  1228. * The field count field is the size of a pointer.
  1229. */
  1230. {
  1231. char** ppz = (char**)(void*)&(option_usage_text);
  1232. int ix = option_usage_text.field_ct;
  1233. do {
  1234. ppz++;
  1235. *ppz = AO_gettext(*ppz);
  1236. } while (--ix > 0);
  1237. }
  1238. option_usage_text.field_ct = 0;
  1239. {
  1240. tOptDesc* pOD = tcpprepOptions.pOptDesc;
  1241. int ix = tcpprepOptions.optCt;
  1242. for (;;) {
  1243. pOD->pzText = AO_gettext(pOD->pzText);
  1244. pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
  1245. pOD->pz_Name = AO_gettext(pOD->pz_Name);
  1246. pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
  1247. pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
  1248. if (--ix <= 0)
  1249. break;
  1250. pOD++;
  1251. }
  1252. }
  1253. COERSION(pzCopyright);
  1254. COERSION(pzCopyNotice);
  1255. COERSION(pzFullVersion);
  1256. COERSION(pzUsageTitle);
  1257. COERSION(pzExplain);
  1258. COERSION(pzDetail);
  1259. }
  1260. #endif /* ENABLE_NLS */
  1261. #ifdef __cplusplus
  1262. }
  1263. #endif
  1264. /* tcpprep_opts.c ends here */