SNMP Manager Programmer's Guide

Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-33
Function for Releasing Packet Memory
valid SNMP data type and converts it to the Manager Services representation for it. For
MIB-II objects, the common utility function oid_to_namerec() is used to obtain the
Manager Services representation of the data type:
for (i = 0; i < oidcnt; i++)
{
peertype = longform ? str_to_type(typestr[i]) : 0;
if ((p = oid_to_namerec(&base_oid)) != 0)
mibtype = p->type;
else
mibtype = 0;
peertype = peertype ? peertype : mibtype;
The value of peertype, which holds the Manager Services representation for the SNMP
data type for the target MIB object, is used to determine which SNMP_Bind_ function
to call. The function SNMP_Bind_Unsigned_Integer() is called when the value of
peertype is VT_TIMETICKS, VT_GAUGE, or VT_COUNTER:
switch (peertype)
{
case VT_TIMETICKS:
case VT_GAUGE:
case VT_COUNTER:
rcode = SNMP_Bind_Unsigned_integer(send_pkt, i,
base_oid.num_components,
base_oid.component_list,
(OCTET_T) peertype,
strtol(valstr[i], (char **)NULL, 0));
break;
Function for Releasing Packet Memory
There is one Manager Services function for releasing memory previously allocated for a
packet structure: SNMP_Free().
packet
is a pointer to the packet you no longer want to retain in memory.
The sample manager SNMPSET uses two packet structures, one for the request packet
(send_pkt) and one for the response packet (rcvd_pkt). After the response packet has
been decoded and processed, SNMPSET calls SNMP_Free to deallocate all memory
allocated for packet handling before stopping:
SNMP_Free(send_pkt);
SNMP_Free(rcvd_pkt);
SNMP_Free(packet);
int SNMP_Free(SNMP_PKT_T *packet)