tcpprep_opts.c 40 KB

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