Skip to content
Advertisement

C NET-SNMP Get and Set specifically via MIB Name, Not OID

I have written and am testing software for a generic SNMP client module in C as well as an implementation using this generic module. I am having trouble getting a get request to work by passing in a MIB name(e.g. sysDescr) instead of an OID(e.g. 1.3.6.1.2.1.1.1).

I am successful when I pass in a character array containing the OID to _snmp_parse_oid()_ but not the name.

I have checked the MIB file to make sure I am using the correct name. When I run the command line SNMP translate on the name it gives me the OID listed above:

JavaScript

(In the above command I replaced my actual mib file with <MIB File>, mib name with <MIB Name>, and OID numbers returned from the command with # characters)

The following is my code for my generic SNMP get function, assume returned values are #define numbers and I have removed some error handling for brevity:

JavaScript

The error I am getting:

JavaScript

Which comes from the following call:

JavaScript

I have made sure that the MIB files are on the machine in the configured place (snmptranslate wouldn’t work if this weren’t the case).

I have spent a good amount of time on Google results as well as directly searching here on Stack Overflow. The following is a good tutorial but does not address my issue (they directly reference the OID they want to get the value of): http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application

Any help or insight would be much appreciated.

Some other info I can think of is that this is being compiled to run on an armv5tejl target running Linux communicating with an external device via ethernet.

Thanks,

Advertisement

Answer

When I call MIB variables by their string name I use the following net-snmp functions.

JavaScript

Where:

JavaScript

In my program I pack this all into a single function call.

JavaScript

I pass in the MIB OID string and the pointer to session pdu. Remember the OID string is MIB_Name::variable.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement