How to use the mib2c command?

Gaurav picture Gaurav · Jun 21, 2012 · Viewed 10.2k times · Source

Actually I'm trying to generate .h & .c files by given sysSwYear as MIBNODE and I'm using following command:

mib2c -c mib2c.scalar.conf sysSwYear

but it produces the following error:

You didn't give mib2c a valid OID to start with. IE, I could not find any information about the mib node "sysSwYear.0". 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 -c mib2c.scalar.conf sysSwYear.0

You might wish to start by reading the MIB loading tutorial at:

http://www.net-snmp.org/tutorial-5/commands/mib-options.html

And making sure you can get snmptranslate to display information about your MIB node. Once snmptranslate works, then come back and try mib2c again.

I have already done everything needed like setting environment variable for MIB and defining a private MIB file in /usr/share/snmp/mibs ...but still no success. What to do?

Answer

Wes Hardaker picture Wes Hardaker · Jun 21, 2012

You need to do exactly what it says: get the MIB to load first into the parser. Start with using snmptranslate to make sure you can load and parse the MIB:

# export MIBS="+NAME-OF-YOUR-MIB"
# snmptranslate -IR sysSwYear

If that doesn't work, then your MIB isn't being found or loaded because it has errors (or both). If so, run snmptranslate with the -Dparse option and it'll give you way too much information about what it's doing, but it'll let you know where the problems are if you read it all.

Once snmptranslate works as above, then mib2c should work fine (assuming you leave the MIBS environment variable set).

[note: I used export assuming you're using a sh-based shell; use setenv instead and no = sign if you are using a csh-based shell]