SNMP Manager Programmer's Guide
Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-21
SNMP_Bind_IP_Address()
instance-count
is the number of components in the instance identifier whose value you supply in
instance-components. For example, an instance identifier of 1.2.3.4 has a
component count of 4.
instance-components
is a pointer to a structure of type OIDC_T that contains the instance identifier of the
variable binding.
value
is a pointer to a 4-byte area containing the value of the variable binding.
The following example, taken from SNMPSET, binds an IP address to a request packet.
Related declarations include a global define and OID structure declaration and several
variables in the main block; the Manager Services define MAX_OID_COUNT is used to
set the number of elements in the OID component array and the component count
variable to 32. The variable named longform indicates that the 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 };
...
struct hostent *host3;
u_long ipaddr;
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