SNMP Manager Programmer's Guide

Programming Examples
SNMP Manager Programmer’s Guide–134249
2-122
SNMPHOST Source Code
Example 2-18 shows the contents of snmphosc. Numbers in the example correspond to
numbers in the observations made between here and the figure:
1. Header files for packet-transmission and request/response-handling structures and
functions are included.
2. Strings corresponding to hrDeviceStatus integers are defined.
3. Two encoded-packet buffers are declared, one for hrDeviceTable packets and one for
auxiliary-table packets.
4. The dev_status_to_str() function converts the integer value of hrDeviceStatus to a
string. It is used by DisplayHostDevices() when formatting device information for
display. It accepts an integer and returns one of the strings defined earlier for
dev_status[].
5. Strings corresponding to hrPrinterStatus integers are defined.
6. The prn_status_to_str() function converts the integer value of hrPrinterStatus to a
string. It is used by DisplayHostDevices() when formatting printer information for
display. It accepts an integer and returns one of the strings defined earlier for
prn_status[].
7. The oidstring2oid() function is used by GetHostDevices() and GetAuxDeviceTbl()
to fill in base_oid.num_components and the array to which base_oid.component_list
points before binding instance identifiers to request packets. The oidstring2oid()
function accepts an OID formatted like a string ("1.2.3"), a pointer to an array of
type OIDC_T, and the maximum number of integers in the array.
8. The oidcmp2() function compares two OIDs, returning -1 if the first OID is less
than the second OID, +1 if the first OID is greater than the second OID, and 0 if the
OIDs are equal. This function is used by GetHostDevices() to determine whether
the OID of a response packet variable binding is within the range of the OIDs for
hrDeviceTable objects. This function accepts the number of components of each
OID and pointers to the arrays containing them.
9. The InitDevTable() function allocates memory for an array of pointers to memory
for DEV_ENTRY_T structures, which are defined in snmphosh and hold device
information retrieved. Accepting the number of devices for which to retrieve
information, this function returns a pointer to the pointer array, which acts as an
index to memory allocated by calling AllocateDevEntry().
10. The function AllocateDevEntry() allocates memory for as many structures of type
DEV_ENTRY_T as devices for which information will be received. The
relationship between the pointer array and DEV_ENTRY_T memory looks like this:
210
pptable
*pEntry1
*pEntry2
*pEntry3
pEntry1
pEntry2
pEntry3