VxWorks Reference Manual : Libraries
m2Lib - MIB-II API library for SNMP agents
m2Init( ) - initialize the SNMP MIB-2 library
m2Delete( ) - delete all the MIB-II library groups
This library provides Management Information Base (MIB-II, defined in RFC 1213) services for applications wishing to have access to MIB parameters.
There are no specific provisions for MIB-I: all services are provided at the MIB-II level. Applications that use this library for MIB-I must hide the MIB-II extensions from higher level protocols. The library accesses all the MIB-II parameters, and presents them to the application in data structures based on the MIB-II specifications.
The routines provided by the VxWorks MIB-II library are separated into groups that follow the MIB-II definition. Each supported group has its own interface library:
- m2SysLib
- systems group
- m2IfLib
- interface group
- m2IpLib
- IP group (includes AT)
- m2IcmpLib
- ICMP group
- m2TcpLib
- TCP group
- m2UdpLib
- UDP group
MIB-II retains the AT group for backward compatibility, but includes its functionality in the IP group. The EGP and SNMP groups are not supported by this interface. The variables in each group have been subdivided into two types: table entries and scalar variables. Each type has a pair of routines that get and set the variables.
There are four types of operations on each group:
- initializing the group
- getting variables and table entries
- setting variables and table entries
- deleting the groupOnly the groups that are to be used need be initialized. There is one exception: to use the IP group, the interface group must also be initialized. Applications that require MIB-II support from all groups can initialize all groups at once by calling the m2Init( ). All MIB-II group services can be disabled by calling m2Delete( ). Applications that need access only to a particular set of groups need only call the initialization routines of the desired groups.
To read the scalar variables for each group, call one of the following routines:
m2SysGroupInfoGet( )
m2IfGroupInfoGet( )
m2IpGroupInfoGet( )
m2IcmpGroupInfoGet( )
m2TcpGroupInfoGet( )
m2UdpGroupInfoGet( )The input parameter to the routine is always a pointer to a structure specific to the associated group. The scalar group structures follow the naming convention "M2_groupname". The get routines fill in the input structure with the values of all the group variables.
The scalar variables can also be set to a user supplied value. Not all groups 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 field that specifies which variables to set, and a group structure. The structure is the same structure type used in the get operation. Applications need set only the structure fields corresponding to the bits that are set in the bit field.
The MIB-II table routines read one entry at a time. Each MIB-II group that has tables has a get routine for each table. The following table-get routines are available:
m2IfTblEntryGet( )
m2IpAddrTblEntryGet( )
m2IpAtransTblEntryGet( )
m2IpRouteTblEntryGet( )
m2TcpConnEntryGet( )
m2UdpTblEntryGet( )The input parameters are a pointer to a table entry structure, and a flag value specifying one of two types of table search. Each table entry is a structure, where the struct type name follows this naming convention: "M2_GroupnameTablenameTBL". The MIB-II RFC specifies an index that identifies a table entry. Each get request must specify an index value. To retrieve the first entry in a table, set all the index fields of the table-entry structure to zero, and use the search parameter M2_NEXT_VALUE. To retrieve subsequent entries, pass the index returned from the previous invocation, incremented to the next possible lexicographical entry. The search field can only be set to the constants M2_NEXT_VALUE or M2_EXACT_VALUE:
- M2_NEXT_VALUE
- retrieves a table entry that is either identical to the index value specified as input, or is the closest entry following that value, in lexicographic order.
- M2_EXACT_VALUE
- retrieves a table entry that exactly matches the index specified in the input structure.
Some MIB-II table entries can be added, modified and deleted. Routines to manipulate such entries are described in the manual pages for individual groups.
All the IP network addresses that are exchanged with the MIB-II library must be in host-byte order; use ntohl( ) to convert addresses before calling these library routines.
The following example shows how to initialize the MIB-II library for all groups.
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 */
m2Lib.h
m2Lib, m2IfLib, m2IpLib, m2IcmpLib, m2UdpLib, m2TcpLib, m2SysLib
m2Init( ) - initialize the SNMP MIB-2 library
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 */ )
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( ).
OK if successful, otherwise ERROR.
m2Lib, m2SysInit( ), m2TcpInit( ), m2UdpInit( ), m2IcmpInit( ), m2IfInit( ), m2IpInit( )
m2Delete( ) - delete all the MIB-II library groups
STATUS m2Delete (void)
This routine cleans up the state associated with the MIB-II library.
OK (always).
m2Lib, m2SysDelete( ), m2TcpDelete( ), m2UdpDelete( ), m2IcmpDelete( ), m2IfDelete( ), m2IpDelete( )