SNMP Manager Programmer's Guide
Encoding and Decoding Packets
SNMP Manager Programmer’s Guide–134249
6-15
Functions for Encoding Packets
Functions for Encoding Packets
After you have initialized an encoded-packet buffer, you use one of these functions to 
encode into it the contents of a request or trap packet:
•
SNMP_Encode_Packet() BER-encodes the packet. BER encoding can be 
interpreted by any SNMP agent or manager.
•
tdm_SNMP_Encode_Packet() can either BER- or IPC-encode a packet.  IPC 
encoding can be interpreted by a NonStop agent process.
SNMP_Encode_Packet()
This function BER-encodes a request or trap packet into an initialized encoded-packet 
buffer. If you previously allocated memory for the buffer, SNMP_Encode_Packet() 
determines whether the memory allocated is sufficient, then proceeds only if it is. If you 
have not allocated memory for the buffer, this function dynamically allocates enough 
memory to hold the encoded packet. 
rcode
is an integer describing the outcome of the call. If the call is successful, 0 is 
returned; if not, -1 is returned.
packet
is a pointer to an unencoded request or trap packet.
buffer
is a pointer to the descriptor structure for an encoded-packet buffer previously 
initialized with EBufferInitialize() or EBufferSetup().
The sample managers that transmit and receive packets using only the UDP protocol call 
SNMP_Encode_Packet() after a request or trap packet has been constructed and before 
transmitting it to the target entity. Here is what the call looks like in SNMPGT:
SNMP_PKT_T *send_pkt;
EBUFFER_T ebuff.
rcode = SNMP_Encode_Packet(send_pkt, &ebuff);
tdm_SNMP_Encode_Packet()
This function either BER- or IPC-encodes a request or trap packet into an initialized 
encoded-packet buffer, depending on the value of its final argument. If you previously 
allocated memory for the buffer, tdm_SNMP_Encode_Packet() determines whether the 
rcode = SNMP_Encode_Packet(packet, buffer);
int SNMP_Encode_Packet(SNMP_PKT_T* packet, EBUFFER_T* 
buffer);










