TUT:mib2c General Overview
This brief tutorial presents an overview of generating skeleton C code for a SNMP MIB using the mib2c utility.
For mib2c to work, it needs to be able to find the MIB file that defines the MIB for which it will be generating code. Running mib2c without arguments informs you of this:
You didn't give mib2c a valid OID to start with. IE, I could not find any information about the mib node "". This could be caused because you supplied an incorrectly node, or by the MIB that you're trying to generate code from isn't loaded. To make sure your mib is loaded, run mib2c using this as an example: env MIBS="+MY-PERSONAL-MIB" mib2c You might wish to start by reading the MIB loading tutorial at: http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS And making sure you can get snmptranslate to display information about
your MIB node. Once snmptranslate works, then come back and try mib2c again.
So, if you are interested in generating code for your table XYZTable, make sure that
snmptranslate -IR XYZTable
works first.
When you run mib2c, you must specify a MIB node for it to process. You can also specify which configuration file you would like it to use to generate the code. The available options are:
mib2c.array-user.conf mib2c.create-dataset.conf mib2c.int_watch.conf mib2c.iterate.conf mib2c.iterate_access.conf mib2c.mfd.conf mib2c.notify.conf mib2c.old-api.conf mib2c.scalar.conf
Running mib2c without specifying a configuration file will prompt you with some questions to help determine which one might be appropriate for your situation.
One thing many people get confuse about is what to do after running mib2c. Contrary to popular belief, simply running mib2c on a MIB does not generate a complete implementation for the module, as indicated by this warning printed after running mib2c without specifying a configuration file:
********************************************************************** * NOTE WELL: The code generated by mib2c is only a template. *YOU* * * must fill in the code before it'll work most of the time. In many * * cases, spots that MUST be edited within the files are marked with * * /* XXX */ or /* TODO */ comments. * **********************************************************************
So once you've generated the template (aka skeleton) code for your mib, you need to edit the code and implement the portions of the code specific to your module. As more elaborate configuration files are developed, it should become simpler to identify the what/when/where portions of the code (the MFD configuration file is the latest step towards this goal - see the MFD tutorial here).
The next section covers the shell script mib2c-update, which is a wrapper around mib2c to help you take advantage of updates to the configuration file you chose for your mib module.