Next: Watching SNMP on the
Up: The Net-SNMP C API
Previous: The Net-SNMP C API
Contents
Within the SNMP C library API there are a large variety of different structures
which are used to store information needed by different phases of a SNMP dialog.
The basics steps are:
- Initialize an SNMP session
- Define attributes for the session
- Add MIBs to the current MIB tree [Optional]
- Create a PDU (Primary Data Unit)
- Pack OIDs into the PDU
- Send the request and wait for response
- Do something with the returned values
- Free the PDU
- Close the session
When you initialize a new SNMP session a snmp_session structure
will be initialized with default values. You can then modify elements of
that structure to match your needs such as defining the SNMP version, community
name, and target hostname. Once the session values are in order you can open
the session which returns another snmp_session struct as a handle.
When a session is created the default system MIBs are loaded into the MIB tree
used by the library, however you can also add (or remove) MIBs from the tree to use
a MIB that isn't installed.
Once the session is in order and open, a Primary Data Unit (PDU) can be created.
Richard Stevens' wrote in his book "TCP/IP Illustrated: Vol 1" that a PDU is just a fancy
term for a packet. Each SNMP request packet includes a PDU. Each PDU can contain one or more
OIDs. The type of request that is made is specified by the type of PDU. Therefore if you
needed to read and write OIDs, you'd need 2 PDUS, however if you simply needed to read 2 or more
OIDs you could just pack them into a single PDU. Adding an OID to a PDU is a two step process,
first by reading the OID from the MIB and then by adding the OID to the PDU.
Once a PDU is populated and prepared it can be sent using the session handle returned earlier.
The response is put into a new PDU structure with both the OIDs and the values.
Next: Watching SNMP on the
Up: The Net-SNMP C API
Previous: The Net-SNMP C API
Contents
2004-11-23