John Smith
John Smith

Reputation: 128

NET-SNMP SET request using C

How do I setup a SNMP SET request using the NET-SNMP C API?

I tried searching for some function documentation but I couldn't find any.

Upvotes: 0

Views: 2532

Answers (2)

Marco Thome
Marco Thome

Reputation: 1

You can follow the steps of http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application, but instead of using

snmp_add_null_var(pdu, varoid, varoid_len);

just use

snmp_add_var(pdu, varoid, varoid_len, type, value);

Full example: https://github.com/winlibs/net-snmp/blob/master/apps/snmpset.c

Upvotes: 0

k1eran
k1eran

Reputation: 4970

man snmp_pdu_create

shows ...

#include <net-snmp/pdu_api.h> 
netsnmp_pdu *snmp_pdu_create( int type);

Quoting NET-SNMP website :

   /*
    * Create the PDU for the data for our request.
    *   1) We're going to GET the system.sysDescr.0 node.
    */    
   pdu = snmp_pdu_create(SNMP_MSG_GET);

So, let's fill it with our requested oid. Let's get the system.sysDescr.0 variable for this example. There are numerious ways you could create the oid in question. You could put in the numerical unsigned integer values yourself into the anOID array we created above, or you could use one of the following function calls to do it. We recommend the first one (get_node), as it is the most powerful and accepts more types of OIDs.

read_objid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len);
#if OTHER_METHODS    get_node("sysDescr.0", anOID, &anOID_len);     
read_objid("system.sysDescr.0", anOID, &anOID_len);    
#endif

So we add this oid, with a NULL value to the PDU using the following statement: (all oids should be paired with a NULL value for outgoing requests for information. For an SNMP-SET pdu, we'd put in the value we wanted to set the oid to).

   snmp_add_null_var(pdu, anOID, anOID_len);

Upvotes: 1

Related Questions