tcpprep_opts.c 40 KB

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