SNMP Manager Programmer's Guide

Constructing and Interpreting Packets
SNMP Manager Programmer’s Guide–134249
5-12
Functions for Initializing Packets
Functions for Initializing Packets
There are two Manager Services functions for initializing a packet. You use
SNMP_Create_Request() when creating a request packet and SNMP_Create_Trap()
when creating a trap packet. This subsection describes and provides examples for these
two functions.
SNMP_Create_Request()
This function initializes a request packet for a Get, GetNext, or Set PDU. It dynamically
allocates memory for a packet structure of type SNMP_PKT_T, assigns to it all request
packet variables except variable bindings, and returns a pointer to the structure. To
associate variable bindings with the packet, use the functions defined in Functions for
Binding MIB Objects on page 5-17. To deallocate memory used by a request packet you
no longer need, use SNMP_Free(), described in Function for Releasing Packet Memory
on page 5-33.
packet
is a pointer to a structure of type SNMP_PKT_T if the function succeeds or 0 if it
fails.
pdu-type
indicates the kind of PDU to be placed in the packet. Use one of the following
defines:
For Get requests, use GET_REQUEST_PDU (0).
For GetNext requests, use GET_NEXT_REQUEST_PDU (1).
For Set requests, use SET_REQUEST_PDU (3).
version
is one of the following defines, all of which equate to 0, indicating Version 1 of
SNMP:
packet = SNMP_Create_Request(pdu-type,
version,
community-length,
community-identifier,
request-id,
num-varbinds);
SNMP_PKT_T* SNMP_Create_Request(int pdu-type,
int version,
int community-length,
char *community-
identifier,
INT_32_t request-id,
int num-varbinds);