SNMP Manager Programmer's Guide

Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-27
SNMP_Bind_Object_ID()
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_Object_ID() is called when the value of peertype is
VT_OBJECT. Before the value is bound to the packet, the common utility function
oidstr_to_oid() is used to convert the value in valstr into the type required by the
SNMP_Bind_Null() call:
switch (peertype)
{
case VT_OBJECT:
if (oidstr_to_oid(valstr[i], &val_oid) < 0)
{
fprintf(stdout , "Bad object identifier: %s\n",
valstr[i]);
fprintf(stdout, "while binding the VT_OBJECT\n";
exit(2);
}
rcode = SNMP_Bind_Object_ID(send_pkt, i,
base_oid.num_components,
base_oid.component_list,
val_oid.num_components,
val_oid.component_list);
break;