SNMP Manager Programmer's Guide

Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-24
SNMP_Bind_Null()
invocation line specifies MIB objects that are not defined in MIB-II. Manager Services
has an internal table it can use to find the data type of MIB-II objects:
#define MAXOIDS 16
OIDC_T base_component_list[MAX_OID_COUNT];
OBJ_ID_T base_oid = { MAX_OID_COUNT, base_component_list };
...
int longform = 0;
int mibtype = 0;
int oidcnt;
char *oidstr[MAXOIDS];
struct namerec *p;
SNMP_PKT_T *send_pkt;
char *typestr[MAXOIDS];
char *valstr[MAXOIDS];
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;