SNMP Manager Programmer's Guide
Programming Examples
SNMP Manager Programmer’s Guide–134249
2-85
SNMPWALK
Example 2-11 illustrates the contents of snmpwlkc, the source code file for the main 
block of SNMPWALK. Numbers in the example correspond to numbers in the 
observations made between here and the example:
1. The readmib.h and rtutils.h header files contain prototypes for the common utility 
functions SNMPWALK uses in conjunction with mibrt: read_mib() and 
string2oid().
2. Any value specified at invocation with the -d parameter is stored in distance.
3. The common utility function read_mib() is called to load mibrt and convert its 
contents into an in-memory structure that string2oid() can parse.  The in-memory 
structure has the same format as the MIB compiler -nametree output.
4. The common utility function string2oid() converts any name specified at invocation 
and represented in mibrt into an OID.
5. SNMP_Init_() is called.
6. SNMP_Open_() is called.
7. A request packet is constructed for a GetNext request containing one variable 
binding.
8. The first variable binding is bound to the request packet.
9. This for loop is executed the number of times specified by distance. The loop 
encodes, sends, receives, decodes and prints packets, then creates a new request 
packet from the previously received response packet. Also resets the request ID to 1 
once the request ID reaches MAX-REQID-VALUE.
10. SNMP_WriteRead() is called.
11. The response packet becomes the basis for the next request packet.  The request 
identifier is incremented and request ID is reset to 1 in case it has reached MAX-
REQID-VALUE. Then, several fields in the packet structure (SNMP_PKT_T) are 
reinitialized to values appropriate for request packets.  The pdu_type field is 
assigned the value GET_NEXT_REQUEST_PDU.  The pdu.std_pdu.request_id 
field is assigned the current request identifier value.  The pdu.std_pdu.error_status 
and error_index fields are assigned the value 0. If the value for the MIB object is of 
type string or OID, the buffer space occupied by those values must be reinitialized 
before they can be overwritten with the new value. The OID in the packet is not 
changed, because it becomes the basis for the next GetNext operation.










