SNMP Manager Programmer's Guide
Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-30
SNMP_Bind_String()
A for loop extracts instance identifiers from the invocation line arguments, stores any
data type entered in typestr, and stores the value entered in valstr:
for (i = 0; argc > 0; i++)
{
...
oidstr[i] = *argv++; argc--;
if (longform)
{
typestr[i] = *argv++; argc--;
}
valstr[i] = *argv++; argc--;
}
oidcnt = i;
After the request packet is initialized into send_pkt, a for loop is used to assign
variable bindings to it. For objects that are not members of MIB-II, the common utility
function str_to_type() is used to validate whether the type specified at invocation is a
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_String() is called when the value of peertype is
VT_STRING or VT_OPAQUE. The common utility function hexcheck() is used in the
function call to compute the number of bytes in the value string:
switch (peertype)
{
case VT_STRING:
case VT_OPAQUE:
rcode = SNMP_Bind_String(send_pkt, i,
base_oid.num_components,
base_oid.component_list,
(OCTET_T) peertype, hexcheck(valstr[i]),
(unsigned char*)valstr[i],
/* buffer is static */ 1);
break;