SNMP Manager Programmer's Guide

Encoding and Decoding Packets
SNMP Manager Programmer’s Guide134249
6-4
Encoding Packets
After the call to EBufferSetup(), the start_bp and next_bp indicators point to the start of
the buffer, and the value of remaining is the number of bytes you allocated.
Encoding Packets
After you have initialized an encoded-packet buffer, you use SNMP_Encode_Packet()
or tdm_SNMP_Encode_Packet() to encode into it the contents of a request or trap
packet.
To BER-encode a packet, you can use either function:
SNMP_Encode_Packet() always performs BER encoding:
SNMP_PKT_T *send_pkt;
EBUFFER_T ebuff;
rcode = SNMP_Encode_Packet(send_pkt, &ebuff);
tdm_SNMP_Encode_Packet() BER-encodes a packet when its final argument is 0:
myflag = 0;
rcode = tdm_SNMP_Encode_Packet(send_pkt, &ebuff, myflag);
To IPC-encode a packet, you use tdm_SNMP_Encode_Packet(), passing a value of 1
in its final argument:
myflag = 1;
rcode = tdm_SNMP_Encode_Packet(send_pkt, &ebuff, myflag);
Decoding Packets
You receive response and trap packets into an EBUFFER_T buffer. To decode either a
BER- or IPC-encoded packet, you use SNMP_Decode_Packet_WER(). This function
returns a pointer to a packet structure containing the decoded packet. The first argument
in the function points to the location in the buffer to begin decoding. The second
argument indicates how many bytes to decode:
SNMP_PKT_T *rcvd_pkt;
EBUFFER_T ebuff;
rcvd_pkt = SNMP_Decode_Packet_WER(ebuff.start_bp, amount,
(SNMPADDR_T*) 0, (SNMPADDR_T*) 0, &rcode);
604
ebuff
start_bp
next_bp
remaining