Format
#include <snmp_dpi.h>
int DPIawait_packet_from_agent( /* await a DPI packet */
int handle, /* on this connection */
int timeout, /* timeout in seconds */
unsigned char **message_p, /* receives ptr to data */
unsigned long *length); /* receives length of data */
Parameters
- handle
- A handle as obtained with a DPIconnect_to_agent_xxxx() call.
- timeout
- A timeout value in seconds. There are two special values:
- -1
- Causes the function to wait forever until a packet arrives.
- 0
- Means that the function will check only if a packet is waiting.
If not, an immediate return is made. If there is a packet, it will
be returned.
- message_p
- The address of a pointer that will receive the address of a static DPI packet buffer
or, if there is no packet, a NULL pointer.
- length
- The address of an unsigned long integer that will receive the
length of the received DPI packet or, if there is no packet, a 0 value.
Return codes
- If successful, a 0 (DPI_RC_OK) is returned. The buffer pointer
and length of the caller will be set to point to the received DPI packet and
to the length of that packet.
- If not successful, a negative integer is returned, which indicates
the kind of error that occurred. See Return codes from DPI transport-related functions for a list of possible error codes.
- DPI_RC_NOK
- This is a return code indicating the DPI code is out of sync or has a
bug.
- DPI_RC_EOF
- End of file on the connection. The connection has been closed.
- DPI_RC_IO_ERROR
- An error occurred with an underlying select() or recvfrom() call,
or a DPI packet
was read that was less than 2 bytes. DPI uses the first 2 bytes to get the packet
length.
- DPI_RC_INVALID_HANDLE
- A bad handle was passed as input. Either the handle is not valid,
or it describes a connection that has been disconnected.
- DPI_RC_TIMEOUT
- No packet was received during the specified timeout period.
- DPI_RC_PACKET_TOO_LARGE
- The packet received was too large.
Usage
The DPIawait_packet_from_agent()
function is used at the subagent side to await a DPI packet from the DPI-capable
SNMP agent. The programmer can specify how long to wait.
Examples
#include <snmp_dpi.h>
int handle;
unsigned char *pack_p;
unsigned long length;
handle = DPIconnect_to_agent_TCP("127.0.0.1", "public");
if (handle < 0) {
printf("Error %d from connect\n",handle);
exit(1);
} /* endif */
/* do useful stuff */
rc = DPIawait_packet_from_agent(handle, -1,
&pack_p, &length);
if (rc) {
printf("Error %d from await packet\n");
exit(1);
} /* endif */
/* handle the packet */