MIB2C(1) | Net-SNMP | MIB2C(1) |
NAME¶
mib2c -- generate template code for extending the agentSYNOPSIS¶
mib2c [-h] -c CONFIGFILE [-I PATH] [-f OUTNAME] [-i][-s][-q][-S VAR=VAL] MIBNODEDESCRIPTION¶
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 fileMIBS=+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.
OPTIONS¶
- -h
- Display a help message.
- -c CONFIGFILE
- Use CONFIGFILE when generating code. These files will be searched for first in the current directory and then in the /usr/share directory (which is where the default mib2c configuration files can be found). Running mib2c without the -c CONFIGFILE option will display a description of the valid values for CONFIGFILE, that is, the available config files, including new ones that you might author.
- For example,
- % mib2c ifTable
- will display a description of the currently available values for CONFIGFILE.
- The following values are supported for CONFIGFILE:
- mib2c.mfd.conf
- GENERATING CODE FOR SCALAR OBJECTS:
- If you're writing code for some scalars, run: mib2c -c mib2c.scalar.conf MIBNODE
- If you want to magically "tie" integer variables to integer scalars, use: mib2c -c mib2c.int_watch.conf MIBNODE
- GENERATING CODE FOR TABLES:
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
- -IPATH
- Search for configuration files in PATH. Multiple paths can be specified using multiple -I switches or by using one with a comma separated list of paths in it.
- -f OUTNAME
- Places the output code into OUTNAME.c and OUTNAME.h. Normally, mib2c will place the output code into files which correspond to the table names it is generating code for, which is probably what you want anyway.
- -i
- Do not run indent on the resulting code.
- -s
- Do not look for MIBNODE.sed and run sed on the resulting code. This is useful to shorten long mib variable names in the code.
- -q
- Run in "quiet" mode, which minimizes the status messages mib2c generates.
- -SVAR=VAL
- Preset a variable VAR, in the mib2c.*.conf file, to the value VAL. None of the existing mib2c configuration files (mib2c.*.conf) currently makes use of this feature, however, so this option should be considered available only for future use.
EXAMPLES¶
The following generates C template code for the header and implementation files to implement UCD-DEMO-MIB::ucdDemoPublic.- % mib2c -c mib2c.scalar.conf ucdDemoPublic
- % mib2c -c mib2c.iterate.conf tcpConnTable
SEE ALSO¶
snmpcmd(1), snmp.conf(5)05 Apr 2010 | V5.7.2.1 |