The mib2c script is badly named. It really should have been named mib2anything, as it's actually can provide output tailored to anything you might want to change MIB data into.
mib2c was designed to:
- Alleviate the task of producing identically similar code for each mib object
- Be a generic MIB processing engine, capable of converting MIBs and MIB structures to any other format.
- Provide an easy-as-possible getting started interface for new coders trying to write new code to support MIBs
One second goal besides just generating code once and leaving it to the programmer to fill in the blanks, is to provide a framework for splitting code into two pieces:
- code that needs to be maintained by a human implementing the MIB objects
- code that needs only to be written by mib2c itself, and can be regenerated in the future to take advantage of new features produced by mib2c
Some of the mib2c output will contain both of these types of code, and code that can be regenerated/updated in the future is marked as such.
Development Process Using mib2c
The typical process for using mib2c follows this pattern:
- Write a MIB and objects for it (eg, tables and scalars)
- run mib2c on the MIB objects to generate code, producing:
- code that should be edited to complete the implementation
- code that should not be edited ("regeneratable").
- Edit the code to return value MIB data (or accept it when processing SETs)
Example mib2c input file
If you put this in file.conf:
@open -@ @foreach $t table@ @foreach $c column@ $c is a column of type $c.type at $c.objectID @end@ @end@
And then run it on a table, such as the ifTable:
# mib2c -c file.conf ifTable
You'll get this output to your screen (the '-' in '@open -'):
writing to - ifIndex is a column of type ASN_INTEGER at .22.214.171.124.126.96.36.199.1.1 ifDescr is a column of type ASN_OCTET_STR at .188.8.131.52.184.108.40.206.1.2 ifType is a column of type ASN_INTEGER at .220.127.116.11.18.104.22.168.1.3 ifMtu is a column of type ASN_INTEGER at .22.214.171.124.126.96.36.199.1.4 ifSpeed is a column of type ASN_GAUGE at .188.8.131.52.184.108.40.206.1.5 ifPhysAddress is a column of type ASN_OCTET_STR at .220.127.116.11.18.104.22.168.1.6 ifAdminStatus is a column of type ASN_INTEGER at .22.214.171.124.126.96.36.199.1.7 ifOperStatus is a column of type ASN_INTEGER at .188.8.131.52.184.108.40.206.1.8