⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2lib.c

📁 vxworks的完整的源代码
💻 C
字号:
/* m2Lib.c - MIB-II API library for SNMP agents *//* Copyright 1984 - 2000 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01f,25oct00,ham  doc: cleanup for vxWorks AE 1.0.01e,25jan95,jdi  doc cleanup.01d,11nov94,rhp  minor correction to library man page.01c,10nov94,rhp  edited man pages.01b,15feb94,jag  added MIB-II library documentation.01a,05jan94,elh  written*//*DESCRIPTIONThis library provides Management Information Base (MIB-II, defined inRFC 1213) services for applications wishing to have access to MIBparameters.To use this feature, include the following component:INCLUDE_MIB2_ALLThere are no specific provisions for MIB-I: all servicesare provided at the MIB-II level.  Applications that use this libraryfor MIB-I must hide the MIB-II extensions from higher level protocols.The library accesses all the MIB-II parameters, and presents them tothe application in data structures based on the MIB-II specifications.The routines provided by the VxWorks MIB-II library are separatedinto groups that follow the MIB-II definition.  Each supported grouphas its own interface library:.iP m2SysLib 15 3systems group.iP m2IfLibinterface group.iP m2IpLibIP group (includes AT).iP m2IcmpLibICMP group .iP m2TcpLibTCP group .iP m2UdpLibUDP group .LPMIB-II retains the AT group for backward compatibility, butincludes its functionality in the IP group.  The EGP and SNMP groupsare not supported by this interface.  The variables in each group havebeen subdivided into two types: table entries and scalar variables.Each type has a pair of routines that get and set the variables.USING THIS LIBRARYThere are four types of operations on each group:  - initializing the group  - getting variables and table entries  - setting variables and table entries  - deleting the group  Only the groups that are to be used need be initialized.  There is oneexception: to use the IP group, the interface group must also beinitialized.  Applications that require MIB-II support from all groups caninitialize all groups at once by calling the m2Init().  All MIB-II groupservices can be disabled by calling m2Delete().  Applications that needaccess only to a particular set of groups need only call theinitialization routines of the desired groups.To read the scalar variables for each group, call one of the followingroutines:    m2SysGroupInfoGet()    m2IfGroupInfoGet()    m2IpGroupInfoGet()    m2IcmpGroupInfoGet()    m2TcpGroupInfoGet()    m2UdpGroupInfoGet()The input parameter to the routine is always a pointer to a structurespecific to the associated group.  The scalar group structures followthe naming convention "M2_<groupname>".  The get routines fill in theinput structure with the values of all the group variables.The scalar variables can also be set to a user supplied value. Not allgroups permit setting variables, as specified by the MIB-II definition.  The following group routines allow setting variables:    m2SysGroupInfoSet()    m2IpGroupInfoSet()The input parameters to the variable-set routines are a bit fieldthat specifies which variables to set, and a group structure.  Thestructure is the same structure type used in the get operation.Applications need set only the structure fields corresponding to thebits that are set in the bit field.The MIB-II table routines read one entry at a time.  Each MIB-II groupthat has tables has a get routine for each table.  The followingtable-get routines are available:    m2IfTblEntryGet()    m2IpAddrTblEntryGet()    m2IpAtransTblEntryGet()    m2IpRouteTblEntryGet()    m2TcpConnEntryGet()    m2UdpTblEntryGet()The input parameters are a pointer to a table entry structure, and aflag value specifying one of two types of table search.  Each tableentry is a structure, where the struct type name follows this namingconvention: "M2_<Groupname><Tablename>TBL".  The MIB-II RFC specifies anindex that identifies a table entry.  Each get request must specify anindex value.  To retrieve the first entry in a table, set all theindex fields of the table-entry structure to zero, and use the searchparameter M2_NEXT_VALUE.  To retrieve subsequent entries, pass theindex returned from the previous invocation, incremented to the nextpossible lexicographical entry.  The search field can only be set tothe constants M2_NEXT_VALUE or M2_EXACT_VALUE:.iP M2_NEXT_VALUEretrieves a table entry that is either identical tothe index value specified as input, or is the closest entry followingthat value, in lexicographic order..iP M2_EXACT_VALUEretrieves a table entry that exactly matches the indexspecified in the input structure..LPSome MIB-II table entries can be added, modified and deleted.Routines to manipulate such entries are described in the manual pagesfor individual groups.All the IP network addresses that are exchanged with the MIB-IIlibrary must be in host-byte order; use ntohl() to convert addressesbefore calling these library routines.The following example shows how to initialize the MIB-II library forall groups..CS    extern FUNCPTR myTrapGenerator;    extern void *  myTrapGeneratorArg;    M2_OBJECTID mySysObjectId = { 8, {1,3,6,1,4,1,731,1} };    if (m2Init ("VxWorks 5.1.1 MIB-II library (sysDescr)",	        "support@wrs.com (sysContact)",	        "1010 Atlantic Avenue Alameda, California 94501 (sysLocation)",		 &mySysObjectId,		 myTrapGenerator,		 myTrapGeneratorArg,		 0) == OK)	/@ MIB-II groups initialized successfully @/.CEINCLUDE FILES: m2Lib.h SEE ALSO: m2IfLib, m2IpLib, m2IcmpLib, m2UdpLib, m2TcpLib, m2SysLib *//* includes */#include <vxWorks.h>#include "m2Lib.h"/******************************************************************************** m2Init - initialize the SNMP MIB-2 library ** This routine initializes the MIB-2 library by calling the initialization* routines for each MIB-2 group.  The parameters <pMib2SysDescr>* <pMib2SysContact>, <pMib2SysLocation>, and <pMib2SysObjectId> are passed* directly to m2SysInit();  <pTrapRtn> and <pTrapArg> are passed directly to* m2IfInit(); and <maxRouteTableSize> is passed to m2IpInit().** RETURNS: OK if successful, otherwise ERROR.** SEE ALSO:* m2SysInit(), m2TcpInit(), m2UdpInit(), m2IcmpInit(), m2IfInit(), m2IpInit()*/STATUS m2Init     (    char *		pMib2SysDescr,		/* sysDescr */    char *		pMib2SysContact,	/* sysContact */    char *		pMib2SysLocation,	/* sysLocation */    M2_OBJECTID	*	pMib2SysObjectId, 	/* sysObjectID */    FUNCPTR 		pTrapRtn, 		/* link up/down -trap routine */    void * 		pTrapArg,		/* trap routine arg */    int			maxRouteTableSize 	/* max size of routing table */     )    {    /* Call the initialization routine for each group in MIB-2 */    if ((m2SysInit (pMib2SysDescr, pMib2SysContact, pMib2SysLocation,		    pMib2SysObjectId) == ERROR) ||    	(m2IfInit (pTrapRtn, pTrapArg) == ERROR) ||        (m2IpInit (maxRouteTableSize) == ERROR) ||     	(m2TcpInit () == ERROR) ||    	(m2IcmpInit () == ERROR) ||	(m2UdpInit () == ERROR))	{	m2Delete ();				return (ERROR);			/* initialization failed */	}    return (OK);    }/******************************************************************************** m2Delete - delete all the MIB-II library groups** This routine cleans up the state associated with the MIB-II library.** RETURNS: OK (always).** SEE ALSO: m2SysDelete(), m2TcpDelete(), m2UdpDelete(), m2IcmpDelete(),* m2IfDelete(), m2IpDelete()*/STATUS m2Delete (void)    {    m2SysDelete ();	    m2IfDelete ();	    m2IpDelete ();    m2TcpDelete ();    m2IcmpDelete ();    m2UdpDelete ();    return (OK);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -