12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157 |
- /* -*- buffer-read-only: t -*- vi: set ro:
- *
- * DO NOT EDIT THIS FILE (tcpbridge_opts.c)
- *
- * It has been AutoGen-ed Sunday June 12, 2005 at 10:24:27 PM PDT
- * From the definitions tcpbridge_opts.def
- * and the template file options
- */
- #include <stdio.h>
- #include <limits.h>
- #define OPTION_CODE_COMPILE 1
- #include "tcpbridge_opts.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- tSCC zCopyright[] =
- "tcpbridge copyright (c) 2005 Aaron Turner, all rights reserved";
- tSCC zCopyrightNotice[] =
- "tcpbridge is free software copyrighted by Aaron Turner.\n\n\
- Redistribution and use in source and binary forms, with or without\n\
- modification, are permitted provided that the following conditions\n\
- are met:\n\
- 1. Redistributions of source code must retain the above copyright\n\
- notice, this list of conditions and the following disclaimer.\n\
- 2. Redistributions in binary form must reproduce the above copyright\n\
- notice, this list of conditions and the following disclaimer in the\n\
- documentation and/or other materials provided with the distribution.\n\
- 3. Neither the name ``Aaron Turner'' nor the name of any other\n\
- contributor may be used to endorse or promote products derived\n\
- from this software without specific prior written permission.\n\n\
- tcpbridge IS PROVIDED BY Aaron Turner ``AS IS'' AND ANY EXPRESS\n\
- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n\
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\
- ARE DISCLAIMED. IN NO EVENT SHALL Aaron Turner OR ANY OTHER CONTRIBUTORS\n\
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n\
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n\
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n\
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n\
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n\
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n\
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
- extern tUsageProc optionUsage;
- /*
- * global included definitions
- */
- #include "defines.h"
- #include "tcpbridge.h"
- #include "common.h"
- #include "mac.h"
- extern char pcap_version[];
- extern tcpbridge_opt_t options;
- #ifndef NULL
- # define NULL 0
- #endif
- #ifndef EXIT_SUCCESS
- # define EXIT_SUCCESS 0
- #endif
- #ifndef EXIT_FAILURE
- # define EXIT_FAILURE 1
- #endif
- /*
- * Dbug option description:
- */
- tSCC zDbugText[] =
- "Enable debugging output";
- tSCC zDbug_NAME[] = "DBUG";
- tSCC zDbug_Name[] = "dbug";
- #define zDbugDefaultArg ((tCC*)0)
- #define DBUG_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
- /*
- * Verbose option description:
- */
- #ifdef HAVE_TCPDUMP
- tSCC zVerboseText[] =
- "Print decoded packets via tcpdump to STDOUT";
- tSCC zVerbose_NAME[] = "VERBOSE";
- tSCC zVerbose_Name[] = "verbose";
- #define VERBOSE_FLAGS (OPTST_DISABLED)
- #else /* disable Verbose */
- #define VALUE_OPT_VERBOSE NO_EQUIVALENT
- #define VERBOSE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
- #define zVerboseText NULL
- #define zVerbose_NAME NULL
- #define zVerbose_Name NULL
- #endif /* HAVE_TCPDUMP */
- /*
- * Decode option description with
- * "Must also have options" and "Incompatible options":
- */
- #ifdef HAVE_TCPDUMP
- tSCC zDecodeText[] =
- "Arguments passed to tcpdump decoder";
- tSCC zDecode_NAME[] = "DECODE";
- tSCC zDecode_Name[] = "decode";
- static const int
- aDecodeMustList[] = {
- INDEX_OPT_VERBOSE, NO_EQUIVALENT };
- #define DECODE_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- #else /* disable Decode */
- #define VALUE_OPT_DECODE NO_EQUIVALENT
- #define DECODE_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
- #define aDecodeMustList NULL
- #define zDecodeText NULL
- #define zDecode_NAME NULL
- #define zDecode_Name NULL
- #endif /* HAVE_TCPDUMP */
- /*
- * Intf1 option description:
- */
- tSCC zIntf1Text[] =
- "Primary interface (listen in uni-directional mode)";
- tSCC zIntf1_NAME[] = "INTF1";
- tSCC zIntf1_Name[] = "intf1";
- #define INTF1_FLAGS (OPTST_DISABLED | OPTST_MUST_SET \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Intf2 option description:
- */
- tSCC zIntf2Text[] =
- "Secondary interface (send in uni-directional mode)";
- tSCC zIntf2_NAME[] = "INTF2";
- tSCC zIntf2_Name[] = "intf2";
- #define INTF2_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Unidir option description:
- */
- tSCC zUnidirText[] =
- "Send and receive in only one direction";
- tSCC zUnidir_NAME[] = "UNIDIR";
- tSCC zUnidir_Name[] = "unidir";
- #define UNIDIR_FLAGS (OPTST_DISABLED)
- /*
- * Dmac option description:
- */
- tSCC zDmacText[] =
- "Rewrite destination MAC addresses";
- tSCC zDmac_NAME[] = "DMAC";
- tSCC zDmac_Name[] = "dmac";
- #define DMAC_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Smac option description:
- */
- tSCC zSmacText[] =
- "Rewrite source MAC addresses";
- tSCC zSmac_NAME[] = "SMAC";
- tSCC zSmac_Name[] = "smac";
- #define SMAC_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Limit option description:
- */
- tSCC zLimitText[] =
- "Limit the number of packets to send";
- tSCC zLimit_NAME[] = "LIMIT";
- tSCC zLimit_Name[] = "limit";
- #define zLimitDefaultArg ((tCC*)-1)
- #define LIMIT_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
- /*
- * Include option description with
- * "Must also have options" and "Incompatible options":
- */
- tSCC zIncludeText[] =
- "Include only packets matching rule";
- tSCC zInclude_NAME[] = "INCLUDE";
- tSCC zInclude_Name[] = "include";
- static const int
- aIncludeCantList[] = {
- INDEX_OPT_EXCLUDE, NO_EQUIVALENT };
- #define INCLUDE_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Exclude option description with
- * "Must also have options" and "Incompatible options":
- */
- tSCC zExcludeText[] =
- "Exclude any packet matching this rule";
- tSCC zExclude_NAME[] = "EXCLUDE";
- tSCC zExclude_Name[] = "exclude";
- static const int
- aExcludeCantList[] = {
- INDEX_OPT_INCLUDE, NO_EQUIVALENT };
- #define EXCLUDE_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Vlan option description:
- */
- tSCC zVlanText[] =
- "Specify 802.1q VLAN tag mode";
- tSCC zVlan_NAME[] = "VLAN";
- tSCC zVlan_Name[] = "vlan";
- #define VLAN_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
- /*
- * Vlan_Tag option description with
- * "Must also have options" and "Incompatible options":
- */
- tSCC zVlan_TagText[] =
- "Specify the new 802.1q VLAN tag value";
- tSCC zVlan_Tag_NAME[] = "VLAN_TAG";
- tSCC zVlan_Tag_Name[] = "vlan-tag";
- static const int
- aVlan_TagMustList[] = {
- INDEX_OPT_VLAN, NO_EQUIVALENT };
- #define VLAN_TAG_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
- /*
- * Vlan_Cfi option description with
- * "Must also have options" and "Incompatible options":
- */
- tSCC zVlan_CfiText[] =
- "Specify the 802.1q VLAN CFI value";
- tSCC zVlan_Cfi_NAME[] = "VLAN_CFI";
- tSCC zVlan_Cfi_Name[] = "vlan-cfi";
- static const int
- aVlan_CfiMustList[] = {
- INDEX_OPT_VLAN, NO_EQUIVALENT };
- #define VLAN_CFI_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
- /*
- * Vlan_Pri option description with
- * "Must also have options" and "Incompatible options":
- */
- tSCC zVlan_PriText[] =
- "Specify the 802.1q VLAN priority";
- tSCC zVlan_Pri_NAME[] = "VLAN_PRI";
- tSCC zVlan_Pri_Name[] = "vlan-pri";
- static const int
- aVlan_PriMustList[] = {
- INDEX_OPT_VLAN, NO_EQUIVALENT };
- #define VLAN_PRI_FLAGS (OPTST_DISABLED \
- | OPTST_SET_ARGTYPE(OPARG_TYPE_NUMERIC))
- /*
- * Pid option description:
- */
- tSCC zPidText[] =
- "Print the PID of tcpbridge at startup";
- tSCC zPid_NAME[] = "PID";
- tSCC zPid_Name[] = "pid";
- #define PID_FLAGS (OPTST_DISABLED)
- /*
- * Version option description:
- */
- tSCC zVersionText[] =
- "Print version information";
- tSCC zVersion_NAME[] = "VERSION";
- tSCC zVersion_Name[] = "version";
- #define VERSION_FLAGS (OPTST_DISABLED)
- /*
- * Less_Help option description:
- */
- tSCC zLess_HelpText[] =
- "Display less usage information and exit";
- tSCC zLess_Help_NAME[] = "LESS_HELP";
- tSCC zLess_Help_Name[] = "less-help";
- #define LESS_HELP_FLAGS (OPTST_DISABLED)
- /*
- * Help/More_Help option descriptions:
- */
- tSCC zHelpText[] = "Display usage information and exit";
- tSCC zHelp_Name[] = "help";
- tSCC zMore_HelpText[] = "Extended usage information passed thru pager";
- tSCC zMore_Help_Name[] = "more-help";
- /*
- * Save/Load_Opts option description:
- */
- tSCC zSave_OptsText[] = "Save the option state to a config file";
- tSCC zSave_Opts_Name[] = "save-opts";
- tSCC zLoad_OptsText[] = "Load options from a config file";
- tSCC zLoad_Opts_NAME[] = "LOAD_OPTS";
- tSCC zNotLoad_Opts_Name[] = "no-load-opts";
- tSCC zNotLoad_Opts_Pfx[] = "no";
- #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3)
- /*
- * Declare option callback procedures
- */
- extern tOptProc
- optionPagedUsage;
- static tOptProc
- doOptDbug, doOptDmac, doOptExclude, doOptInclude,
- doOptLess_Help, doOptLimit, doOptPid, doOptSmac,
- doOptVersion, doOptVlan, doOptVlan_Cfi, doOptVlan_Pri,
- doOptVlan_Tag, doUsageOpt;
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Tcpbridge Option Descriptions.
- */
- static tOptDesc optDesc[ OPTION_CT ] = {
- { /* entry idx, value */ 0, VALUE_OPT_DBUG,
- /* equiv idx, value */ 0, VALUE_OPT_DBUG,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ DBUG_FLAGS, 0,
- /* last opt argumnt */ zDbugDefaultArg,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptDbug,
- /* desc, NAME, name */ zDbugText, zDbug_NAME, zDbug_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 1, VALUE_OPT_VERBOSE,
- /* equiv idx, value */ 1, VALUE_OPT_VERBOSE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VERBOSE_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zVerboseText, zVerbose_NAME, zVerbose_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 2, VALUE_OPT_DECODE,
- /* equiv idx, value */ 2, VALUE_OPT_DECODE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ DECODE_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ aDecodeMustList, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zDecodeText, zDecode_NAME, zDecode_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 3, VALUE_OPT_INTF1,
- /* equiv idx, value */ 3, VALUE_OPT_INTF1,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 1, 1, 0,
- /* opt state flags */ INTF1_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zIntf1Text, zIntf1_NAME, zIntf1_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 4, VALUE_OPT_INTF2,
- /* equiv idx, value */ 4, VALUE_OPT_INTF2,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ INTF2_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zIntf2Text, zIntf2_NAME, zIntf2_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 5, VALUE_OPT_UNIDIR,
- /* equiv idx, value */ 5, VALUE_OPT_UNIDIR,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ UNIDIR_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zUnidirText, zUnidir_NAME, zUnidir_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 6, VALUE_OPT_DMAC,
- /* equiv idx, value */ 6, VALUE_OPT_DMAC,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ DMAC_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptDmac,
- /* desc, NAME, name */ zDmacText, zDmac_NAME, zDmac_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 7, VALUE_OPT_SMAC,
- /* equiv idx, value */ 7, VALUE_OPT_SMAC,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ SMAC_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptSmac,
- /* desc, NAME, name */ zSmacText, zSmac_NAME, zSmac_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 8, VALUE_OPT_LIMIT,
- /* equiv idx, value */ 8, VALUE_OPT_LIMIT,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ LIMIT_FLAGS, 0,
- /* last opt argumnt */ zLimitDefaultArg,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptLimit,
- /* desc, NAME, name */ zLimitText, zLimit_NAME, zLimit_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 9, VALUE_OPT_INCLUDE,
- /* equiv idx, value */ 9, VALUE_OPT_INCLUDE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ INCLUDE_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aIncludeCantList,
- /* option proc */ doOptInclude,
- /* desc, NAME, name */ zIncludeText, zInclude_NAME, zInclude_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 10, VALUE_OPT_EXCLUDE,
- /* equiv idx, value */ 10, VALUE_OPT_EXCLUDE,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ EXCLUDE_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, aExcludeCantList,
- /* option proc */ doOptExclude,
- /* desc, NAME, name */ zExcludeText, zExclude_NAME, zExclude_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 11, VALUE_OPT_VLAN,
- /* equiv idx, value */ 11, VALUE_OPT_VLAN,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VLAN_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptVlan,
- /* desc, NAME, name */ zVlanText, zVlan_NAME, zVlan_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 12, VALUE_OPT_VLAN_TAG,
- /* equiv idx, value */ 12, VALUE_OPT_VLAN_TAG,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VLAN_TAG_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ aVlan_TagMustList, NULL,
- /* option proc */ doOptVlan_Tag,
- /* desc, NAME, name */ zVlan_TagText, zVlan_Tag_NAME, zVlan_Tag_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 13, VALUE_OPT_VLAN_CFI,
- /* equiv idx, value */ 13, VALUE_OPT_VLAN_CFI,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VLAN_CFI_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ aVlan_CfiMustList, NULL,
- /* option proc */ doOptVlan_Cfi,
- /* desc, NAME, name */ zVlan_CfiText, zVlan_Cfi_NAME, zVlan_Cfi_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 14, VALUE_OPT_VLAN_PRI,
- /* equiv idx, value */ 14, VALUE_OPT_VLAN_PRI,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VLAN_PRI_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ aVlan_PriMustList, NULL,
- /* option proc */ doOptVlan_Pri,
- /* desc, NAME, name */ zVlan_PriText, zVlan_Pri_NAME, zVlan_Pri_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 15, VALUE_OPT_PID,
- /* equiv idx, value */ 15, VALUE_OPT_PID,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ PID_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptPid,
- /* desc, NAME, name */ zPidText, zPid_NAME, zPid_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 16, VALUE_OPT_VERSION,
- /* equiv idx, value */ 16, VALUE_OPT_VERSION,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ VERSION_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptVersion,
- /* desc, NAME, name */ zVersionText, zVersion_NAME, zVersion_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ 17, VALUE_OPT_LESS_HELP,
- /* equiv idx, value */ 17, VALUE_OPT_LESS_HELP,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ LESS_HELP_FLAGS, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doOptLess_Help,
- /* desc, NAME, name */ zLess_HelpText, zLess_Help_NAME, zLess_Help_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ doUsageOpt,
- /* desc, NAME, name */ zHelpText, NULL, zHelp_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_IMM, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionPagedUsage,
- /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
- /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)
- | OPTST_ARG_OPTIONAL, 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
- /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name,
- /* disablement strs */ NULL, NULL },
- { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS,
- /* equiv idx value */ NO_EQUIVALENT, 0,
- /* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, NOLIMIT, 0,
- /* opt state flags */ OPTST_DISABLE_IMM | \
- OPTST_SET_ARGTYPE(OPARG_TYPE_STRING), 0,
- /* last opt argumnt */ NULL,
- /* arg list/cookie */ NULL,
- /* must/cannot opts */ NULL, NULL,
- /* option proc */ optionLoadOpt,
- /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name,
- /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx }
- };
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * Define the Tcpbridge Option Environment
- */
- tSCC zPROGNAME[] = "TCPBRIDGE";
- tSCC zUsageTitle[] =
- "tcpbridge - Bridge network traffic across two interfaces\n\
- USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n";
- tSCC zRcName[] = ".tcpbridgerc";
- tSCC* apzHomeList[] = {
- "$$/",
- NULL };
- #define zBugsAddr NULL
- tSCC zExplain[] = "\n\
- tcpbridge is a tool for briding network traffic across two interfaces\n\
- and optionally modifying the packets in betweeen\n";
- tSCC zDetail[] = "\n\
- The basic operation of tcpbridge is to be a network bridge between two\n\
- subnets. All packets recieved on one interface are sent via the other.\n\n\
- Optionally, packets can be edited in a variety of ways according to your needs.\n";
- #define zFullVersion NULL
- /* extracted from /usr/local/share/autogen/optcode.tpl near line 309 */
- #if defined(ENABLE_NLS)
- # define OPTPROC_BASE OPTPROC_TRANSLATE
- static tOptionXlateProc translate_option_strings;
- #else
- # define OPTPROC_BASE OPTPROC_NONE
- # define translate_option_strings NULL
- #endif /* ENABLE_NLS */
- tOptions tcpbridgeOptions = {
- OPTIONS_STRUCT_VERSION,
- 0, NULL, /* original argc + argv */
- ( OPTPROC_BASE
- + OPTPROC_ERRSTOP
- + OPTPROC_SHORTOPT
- + OPTPROC_LONGOPT
- + OPTPROC_NO_REQ_OPT
- + OPTPROC_NO_ARGS
- + OPTPROC_GNUUSAGE
- + OPTPROC_HAS_IMMED ),
- 0, NULL, /* current option index, current option */
- NULL, NULL, zPROGNAME,
- zRcName, zCopyright, zCopyrightNotice,
- zFullVersion, apzHomeList, zUsageTitle,
- zExplain, zDetail, optDesc,
- zBugsAddr, /* address to send bugs to */
- NULL, NULL, /* extensions/saved state */
- optionUsage, /* usage procedure */
- translate_option_strings, /* translation procedure */
- /*
- * Indexes to special options
- */
- { INDEX_OPT_MORE_HELP,
- INDEX_OPT_SAVE_OPTS,
- NO_EQUIVALENT /* index of '-#' option */,
- NO_EQUIVALENT /* index of default opt */
- },
- OPTION_CT, 18 /* user option count */
- };
- /*
- * Create the static procedure(s) declared above.
- */
- static void
- doUsageOpt(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- USAGE( EXIT_SUCCESS );
- }
- /* * * * * * *
- *
- * For the dbug option.
- */
- static void
- doOptDbug(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- static const struct {const int rmin, rmax;} rng[ 1 ] = {
- { 0, 5 } };
- long val;
- int ix;
- tCC* pzIndent = "\t\t\t\t ";
- extern FILE* option_usage_fp;
- if (pOptDesc == NULL) /* usage is requesting range list
- option_usage_fp has already been set */
- goto emit_ranges;
- val = atoi( pOptDesc->pzLastArg );
- for (ix = 0; ix < 1; ix++) {
- if (val < rng[ix].rmin)
- continue; /* ranges need not be ordered. */
- if (val == rng[ix].rmin)
- goto valid_return;
- if (rng[ix].rmax == INT_MIN)
- continue;
- if (val <= rng[ix].rmax)
- goto valid_return;
- }
- option_usage_fp = stderr;
- fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
- pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
- pzIndent = "\t";
- emit_ranges:
- fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
- pzIndent, rng[0].rmin, rng[0].rmax );
- if (pOptDesc == NULL)
- return;
- USAGE( EXIT_FAILURE );
- /* NOTREACHED */
- return;
- valid_return:
- pOptDesc->pzLastArg = (char*)val;
- }
- /* * * * * * *
- *
- * For the dmac option.
- */
- static void
- doOptDmac(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- int mask = 0;
- mask = dualmac2hex(OPT_ARG(DMAC), options.intf1_dmac, options.intf2_dmac,
- strlen(OPT_ARG(DMAC)));
- options.mac_mask ^= (mask << 2);
- }
- /* * * * * * *
- *
- * For the smac option.
- */
- static void
- doOptSmac(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- int mask = 0;
- mask = dualmac2hex(OPT_ARG(SMAC), options.intf1_smac, options.intf2_smac,
- strlen(OPT_ARG(SMAC)));
- options.mac_mask ^= mask;
- }
- /* * * * * * *
- *
- * For the limit option.
- */
- static void
- doOptLimit(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- static const struct {const int rmin, rmax;} rng[ 1 ] = {
- { 0, INT_MAX } };
- long val;
- int ix;
- tCC* pzIndent = "\t\t\t\t ";
- extern FILE* option_usage_fp;
- if (pOptDesc == NULL) /* usage is requesting range list
- option_usage_fp has already been set */
- goto emit_ranges;
- val = atoi( pOptDesc->pzLastArg );
- for (ix = 0; ix < 1; ix++) {
- if (val < rng[ix].rmin)
- continue; /* ranges need not be ordered. */
- if (val == rng[ix].rmin)
- goto valid_return;
- if (rng[ix].rmax == INT_MIN)
- continue;
- if (val <= rng[ix].rmax)
- goto valid_return;
- }
- option_usage_fp = stderr;
- fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
- pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
- pzIndent = "\t";
- emit_ranges:
- fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
- pzIndent, rng[0].rmin, rng[0].rmax );
- if (pOptDesc == NULL)
- return;
- USAGE( EXIT_FAILURE );
- /* NOTREACHED */
- return;
- valid_return:
- pOptDesc->pzLastArg = (char*)val;
- }
- /* * * * * * *
- *
- * For the include option.
- */
- static void
- doOptInclude(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- char *include;
-
- include = safe_strdup(OPT_ARG(INCLUDE));
- options.xX.mode = xX_MODE_INCLUDE;
-
- if ((options.xX.mode = parse_xX_str(&options.xX, include, &options.bpf)) == 0)
- errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(INCLUDE));
- free(include);
-
- }
- /* * * * * * *
- *
- * For the exclude option.
- */
- static void
- doOptExclude(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- char *exclude;
-
- exclude = safe_strdup(OPT_ARG(EXCLUDE));
- options.xX.mode = xX_MODE_EXCLUDE;
-
- if ((options.xX.mode = parse_xX_str(&options.xX, exclude, &options.bpf)) == 0)
- errx(1, "Unable to parse include/exclude rule: %s", OPT_ARG(EXCLUDE));
-
- free(exclude);
-
- }
- /* * * * * * *
- *
- * For the vlan option.
- */
- static void
- doOptVlan(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- if (strcmp(OPT_ARG(VLAN), "add") == 0) {
- options.vlan = VLAN_ADD;
- } else if (strcmp(OPT_ARG(VLAN), "del") == 0) {
- options.vlan = VLAN_DEL;
- } else {
- errx(1, "Invalid vlan argument '%s'. Must be 'add' or 'del'", OPT_ARG(VLAN));
- }
- }
- /* * * * * * *
- *
- * For the vlan_tag option.
- */
- static void
- doOptVlan_Tag(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- static const struct {const int rmin, rmax;} rng[ 1 ] = {
- { 0, 4095 } };
- long val;
- int ix;
- tCC* pzIndent = "\t\t\t\t ";
- extern FILE* option_usage_fp;
- if (pOptDesc == NULL) /* usage is requesting range list
- option_usage_fp has already been set */
- goto emit_ranges;
- val = atoi( pOptDesc->pzLastArg );
- for (ix = 0; ix < 1; ix++) {
- if (val < rng[ix].rmin)
- continue; /* ranges need not be ordered. */
- if (val == rng[ix].rmin)
- goto valid_return;
- if (rng[ix].rmax == INT_MIN)
- continue;
- if (val <= rng[ix].rmax)
- goto valid_return;
- }
- option_usage_fp = stderr;
- fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
- pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
- pzIndent = "\t";
- emit_ranges:
- fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
- pzIndent, rng[0].rmin, rng[0].rmax );
- if (pOptDesc == NULL)
- return;
- USAGE( EXIT_FAILURE );
- /* NOTREACHED */
- return;
- valid_return:
- pOptDesc->pzLastArg = (char*)val;
- }
- /* * * * * * *
- *
- * For the vlan_cfi option.
- */
- static void
- doOptVlan_Cfi(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- static const struct {const int rmin, rmax;} rng[ 1 ] = {
- { 0, 1 } };
- long val;
- int ix;
- tCC* pzIndent = "\t\t\t\t ";
- extern FILE* option_usage_fp;
- if (pOptDesc == NULL) /* usage is requesting range list
- option_usage_fp has already been set */
- goto emit_ranges;
- val = atoi( pOptDesc->pzLastArg );
- for (ix = 0; ix < 1; ix++) {
- if (val < rng[ix].rmin)
- continue; /* ranges need not be ordered. */
- if (val == rng[ix].rmin)
- goto valid_return;
- if (rng[ix].rmax == INT_MIN)
- continue;
- if (val <= rng[ix].rmax)
- goto valid_return;
- }
- option_usage_fp = stderr;
- fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
- pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
- pzIndent = "\t";
- emit_ranges:
- fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
- pzIndent, rng[0].rmin, rng[0].rmax );
- if (pOptDesc == NULL)
- return;
- USAGE( EXIT_FAILURE );
- /* NOTREACHED */
- return;
- valid_return:
- pOptDesc->pzLastArg = (char*)val;
- }
- /* * * * * * *
- *
- * For the vlan_pri option.
- */
- static void
- doOptVlan_Pri(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
- static const struct {const int rmin, rmax;} rng[ 1 ] = {
- { 0, 7 } };
- long val;
- int ix;
- tCC* pzIndent = "\t\t\t\t ";
- extern FILE* option_usage_fp;
- if (pOptDesc == NULL) /* usage is requesting range list
- option_usage_fp has already been set */
- goto emit_ranges;
- val = atoi( pOptDesc->pzLastArg );
- for (ix = 0; ix < 1; ix++) {
- if (val < rng[ix].rmin)
- continue; /* ranges need not be ordered. */
- if (val == rng[ix].rmin)
- goto valid_return;
- if (rng[ix].rmax == INT_MIN)
- continue;
- if (val <= rng[ix].rmax)
- goto valid_return;
- }
- option_usage_fp = stderr;
- fprintf( stderr, _("%s error: %s option value ``%s''is out of range.\n"),
- pOptions->pzProgName, pOptDesc->pz_Name, pOptDesc->pzLastArg );
- pzIndent = "\t";
- emit_ranges:
- fprintf( option_usage_fp, _("%sit must lie in the range: %d to %d\n"),
- pzIndent, rng[0].rmin, rng[0].rmax );
- if (pOptDesc == NULL)
- return;
- USAGE( EXIT_FAILURE );
- /* NOTREACHED */
- return;
- valid_return:
- pOptDesc->pzLastArg = (char*)val;
- }
- /* * * * * * *
- *
- * For the pid option.
- */
- static void
- doOptPid(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- fprintf(stderr, "PID: %hu\n", getpid());
-
- }
- /* * * * * * *
- *
- * For the version option.
- */
- static void
- doOptVersion(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- fprintf(stderr, "tcpbridge version: %s (build %s)", VERSION, svn_version());
- #ifdef DEBUG
- fprintf(stderr, " (debug)");
- #endif
- fprintf(stderr, "\n");
- fprintf(stderr, "Copyright 2001-2005 by Aaron Turner <aturner@pobox.com>\n");
- fprintf(stderr, "Compiled against libnet: %s\n", LIBNET_VERSION);
- fprintf(stderr, "Compiled against libpcap: %s\n", pcap_version);
- #ifdef ENABLE_64BITS
- fprintf(stderr, "64 bit packet counters: enabled\n");
- #else
- fprintf(stderr, "64 bit packet counters: disabled\n");
- #endif
- #ifdef HAVE_TCPDUMP
- fprintf(stderr, "Verbose printing via tcpdump: enabled\n");
- #else
- fprintf(stderr, "Verbose printing via tcpdump: disabled\n");
- #endif
- exit(0);
-
- }
- /* * * * * * *
- *
- * For the less-help option.
- */
- static void
- doOptLess_Help(
- tOptions* pOptions,
- tOptDesc* pOptDesc )
- {
-
- USAGE(EXIT_FAILURE);
- }
- /* extracted from /usr/local/share/autogen/optcode.tpl near line 396 */
- #if ENABLE_NLS
- #include <string.h>
- #include <stdio.h>
- #include <autoopts/usage-txt.h>
- static char*
- AO_gettext( const char* pz )
- {
- char* pzRes;
- if (pz == NULL)
- return NULL;
- pzRes = _(pz);
- if (pzRes == pz)
- return pzRes;
- pzRes = strdup( pzRes );
- if (pzRes == NULL) {
- fputs( _("No memory for duping translated strings\n"), stderr );
- exit( EXIT_FAILURE );
- }
- return pzRes;
- }
- /*
- * This invokes the translation code (e.g. gettext(3)).
- */
- static void
- translate_option_strings( void )
- {
- /*
- * Guard against re-translation. It won't work. The strings will have
- * been changed by the first pass through this code. One shot only.
- */
- if (option_usage_text.field_ct == 0)
- return;
- /*
- * Do the translations. The first pointer follows the field count field.
- * The field count field is the size of a pointer.
- */
- {
- char** ppz = (char**)(void*)&(option_usage_text);
- int ix = option_usage_text.field_ct;
- do {
- ppz++;
- *ppz = AO_gettext(*ppz);
- } while (--ix > 0);
- }
- option_usage_text.field_ct = 0;
- {
- tOptDesc* pOD = tcpbridgeOptions.pOptDesc;
- int ix = tcpbridgeOptions.optCt;
- for (;;) {
- pOD->pzText = AO_gettext(pOD->pzText);
- pOD->pz_NAME = AO_gettext(pOD->pz_NAME);
- pOD->pz_Name = AO_gettext(pOD->pz_Name);
- pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName);
- pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx);
- if (--ix <= 0)
- break;
- pOD++;
- }
- }
- tcpbridgeOptions.pzCopyright = AO_gettext(tcpbridgeOptions.pzCopyright);
- tcpbridgeOptions.pzCopyNotice = AO_gettext(tcpbridgeOptions.pzCopyNotice);
- tcpbridgeOptions.pzFullVersion = AO_gettext(tcpbridgeOptions.pzFullVersion);
- tcpbridgeOptions.pzUsageTitle = AO_gettext(tcpbridgeOptions.pzUsageTitle);
- tcpbridgeOptions.pzExplain = AO_gettext(tcpbridgeOptions.pzExplain);
- tcpbridgeOptions.pzDetail = AO_gettext(tcpbridgeOptions.pzDetail);
- }
- #endif /* ENABLE_NLS */
- #ifdef __cplusplus
- }
- #endif
|