MIB2C(1) | Net-SNMP | MIB2C(1) |
mib2c -- generate template code for extending the agent
mib2c [-h] -c CONFIGFILE [-I PATH] [-f OUTNAME] [-i][-s][-q][-S VAR=VAL] MIBNODE
The mib2c tool is designed to take a portion of the MIB tree (as defined by a MIB file) and generate the template C code necessary to implement the relevant management objects within it.
In order to implement a new MIB module, three files are necessary:
- MIB definition file
- C header file
- C implementation file.
The mib2c tool uses the MIB definition file to produce the two C code files. Thus, mib2c generates a template that you can edit to add logic necessary to obtain information from the operating system or application to complete the module.
MIBNODE is the top level mib node you want to generate code for. You must give mib2c a mib node (e.g. ifTable) on the command line, not a mib file. This is the single most common mistake.
The mib2c tool accepts both SMIv1 and SMIv2 MIBs.
mib2c needs to be able to find and load a MIB file in order to generate C code for the MIB. To enable mib2c to find the MIB file, set the MIBS environment variable to include the MIB file you are using. An example of setting this environment variable is:
MIBS=+NET-SNMP-TUTORIAL-MIB
or
MIBS=ALL
The first example ensures that mib2c finds the NET-SNMP-TUTORIAL-MIB mib, in addition to the default MIB modules. The default list of MIB modules is set when the suite is first configured and built and basically corresponds to the list of modules that the agent supports. The second example ensures that mib2c finds all MIBs in the search location for MIB files. The default search location for MIB files is /usr/share/snmp/mibs. This search location can be modified by the MIBDIRS environment variable.
Both the MIB files to be loaded and the MIB file search location can also be configured in the snmp.conf file. Please see snmp.conf(5) for more information.
The generated *.c and *.h files will be created in the current working directory.
mib2c -c mib2c.scalar.conf MIBNODE
mib2c -c mib2c.int_watch.conf MIBNODE
The recommended configuration file for tables is the MIBs for Dummies, or MFD, configuration file. It hides as much of the SNMP details as possible, generating small, easy to understand functions. It is also the most flexible and well documented configuration file. See the agent/mibgroup/if-mib/ifTable/ifTable*.c files for an example:
mib2c -c mib2c.mfd.conf MIBNODE
If your table data is kept somewhere else (e.g. it's in the kernel and not in the memory of the agent itself) and you need to "iterate" over it to find the right data for the SNMP row being accessed. See the agent/mibgroup/mibII/vacm_context.c file for an example:
mib2c -c mib2c.iterate.conf MIBNODE
If your table data is kept in the agent (i.e. it's not located in an external source) and is purely data driven (i.e. you do not need to perform any work when a set occurs). See the agent/mibgroup/examples/data_set.c file for an example of such a table:
mib2c -c mib2c.create-dataset.conf MIBNODE
If your table data is kept in the agent (i.e. it's not located in an external source), and you can keep your data sorted by the table index but you do need to perform work when a set occurs:
mib2c -c mib2c.array-user.conf MIBNODE
GENERATING HEADER FILE DEFINITIONS
To generate just a header with a define for each column number in your table:
mib2c -c mib2c.column_defines.conf MIBNODE
To generate just a header with a define for each enum for any column containing enums:
mib2c -c mib2c.column_enums.conf MIBNODE
GENERATING CODE FOR THE 4.X LINE OF CODE (THE OLDER API)
mib2c -c mib2c.old-api.conf MIBNODE
The following generates C template code for the header and implementation files to implement UCD-DEMO-MIB::ucdDemoPublic.
The resulting ucdDemoPublic.c and ucdDemoPublic.h files are generated the current working directory.
The following generates C template code for the header and implementation files for the module to implement TCP-MIB::tcpConnTable.
The resulting tcpConnTable.c and tcpConnTable.h files are generated in the current working directory.
05 Apr 2010 | V5.9.3 |