tcpprep_opts.c 38 KB

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