SNMP Manager Programmer's Guide
Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-16
SNMP_Create_Trap()
number of elements in the OID component array and the component count variable to
32:
OIDC_T snmp_product_id[] = {
/* ISO */ 1,
/* ORG */ 3,
/* DOD */ 6,
/* INTERNET */ 1,
/* PRIVATE */ 4,
/* ENTERPRISES */ 1,
/* Tandem */ 169,
/* nonstopsystems */ 3
};
int
snmp_product_id_count=sizeof(snmp_product_id)/sizeof(OIDC_T);
...
OIDC_T base_component_list[MAX_OID_COUNT];
OBJ_ID_T base_oid = { MAX_OID_COUNT, base_component_list);
Variables for other arguments in the SNMP_Create_Trap() call are declared and
initialized in the main block; variables related to the call are highlighted in bold type:
SNMP_PKT_T *send_pkt;
int szfrom,i, oidcnt, longform = 0;
u_long host_addr, ipaddr;
char opt, *whoami, *hostname, *community="public"
char *entstr = 0, *agentstr, *genstr="0", localhost[80],
int generic = 0, specific = 0;
unsigned int timestamp = 0;
When the command-line arguments are parsed, values overriding default values are
obtained. Any value specified for enterprise is stored in entstr and used later to assign a
value to the OBJ_ID_T structure used to hold OIDs for the SNMP_Create_Trap() call.
The value stored in entstr is validated; if entstr does not contain a valid enterprise
identifier, the default enterprise identifier is assigned to the OID structure:
if (entstr)
{
if (oidstr_to_oid(entstr, &base_oid) < 0)
{
fprintf(stderr, "Bad enterprise object identifier:
%s\n", entstr);
exit(0);
}
}else
{
base_oid.num_components = snmp_product_id_count;
for (i = 0; i < snmp_product_id_count; i++)
base_oid.component_list[i] = snmp_product_id[i];
}