SNMP Manager Programmer's Guide
Encoding and Decoding Packets
SNMP Manager Programmer’s Guide–134249
6-14
SNMP_memory_alloc()
buffer
is a pointer to the descriptor structure of the buffer for which you want to know the
number of used bytes.
The sample manager SNMPGT calls EBufferUsed() to determine how many bytes to
write to the buffer used to transmit a request. The variable sndbuff is the encoded-
packet buffer used for requests. Because the UDP transport protocol requires that the
first information in the buffer transmitted be the socket structure, the response packet in
the buffer described by ebuff is written into sndbuff following this structure:
#define TBSIZE 2048;
unsigned char sndbuff[TBSIZE];
struct sockaddr_in dest;
EBUFFER_T ebuff;
memcpy (sndbuff, (void*) &dest, sizeof(dest));
memcpy (sndbuff + sizeof(struct sockaddr_in), ebuff.start_bp,
EBufferUsed(&ebuff));
SNMP_memory_alloc()
This function allocates buffer memory dynamically. It is a define for the C function
malloc.
need
is the number of bytes to dynamically allocate.
The sample manager SNMPGET dynamically allocates a 2000-byte buffer for the
encoded-packet buffer, then calls EBufferSetup() to prepare the buffer for receiving the
encoded packet:
EBUFFER_T ebuff;
int need;
char *buffp;
need = 2000;
if ((buffp = (char *)SNMP_memory_alloc(need)) ==0
return (-1);
EBufferSetup(BFL_IS_DYNAMIC, &ebuff, buffp, need);
SNMP_memory_alloc(need);
#define SNMP_memory_alloc(need) malloc(need)