SNMP Manager Programmer's Guide
Encoding and Decoding Packets
SNMP Manager Programmer’s Guide–134249
6-16
tdm_SNMP_Encode_Packet()
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().
mode
is an integer indicating whether to BER- or IPC-encode the packet:
0 indicates BER encoding.
1 indicates IPC encoding.
The sample managers that support both UDP and IPC protocols use this function, setting
the value of the final argument, which is stored in the local_flag field of the host_int
structure, to 0 or 1. This function encodes the contents of the request packet (in spkt)
into the buffer described by myEBuff. If the packet needs to be BER-encoded, buffer
descriptors are set up to leave room for the socket address at the beginning of the buffer:
SNMP_PKT_T *spkt;
EBUFFER_T myEBuff;
short err = 0;
if(host_int->local_flag == REMOTE_HOSTNAME)
{
myEbuff.start_bp += sizeof(struct sockaddr_in);
myEBuff.next_bp += sizeof(struct sockaddr_in);
myEbuff.remaining -= sizeof(struct sockaddr_in);
}
err = tdm_SNMP_Encode_Packet(spkt, &myEBuff,
host_int->local_flag);
rcode = tdm_SNMP_Encode_Packet(packet, buffer, mode);
int SNMP_Encode_Packet(SNMP_PKT_T* packet,
EBUFFER_T* buffer
short mode);