SNMP Manager Programmer's Guide

Sending and Receiving Packets
SNMP Manager Programmer’s Guide–134249
7-6
Sending Packets
value of the target IP address. The destination port value is replaced if a port number is
specified at invocation:
host_int->dest.sin_family = AF_INET;
host_int->dest.sin_port = htons(SNMP_REQUEST_PORT);
host_int->dest.sin_addr.s_addr = host_int->host_addr;
The socket_nw() call in SNMP_Open_() creates a socket for nowaited operations. Its
arguments are the address format (AF_INET), a define requesting a UDP socket
(SOCK_DGRAM), a nowait depth of 2 (allowing pending simultaneous reads and
writes), and a sync depth of 1. It returns to file_num a socket number identifying the
new socket:
if ((host_int->file_num = socket_nw(AF_INET, SOCK_DGRAM, 0,
2, 1)) == -1)
Sending Packets
The D20 socket library requires that the sockaddr_in data appear at the front of the
transmitted buffer. So myEBuff descriptors are set up to reserve space for this
information:
myEbuff.start_bp += sizeof(struct sockaddr_in);
myEBuff.next_bp += sizeof(struct sockaddr_in);
myEbuff.remaining -= sizeof(struct sockaddr_in);
Then the packet passed in spkt is UDP-encoded into the buffer, starting at the byte
described by start_bp in myEBuff:
err = tdm_SNMP_Encode_Packet(spkt, &myEBuff,
host_int->local_flag);
Variables are set up for the call to t_sendto_nw(). The ebuffp descriptors are used to
write the socket information to the start of the encoded-packet buffer, and the number of
Figure 7-2. Calls for Sending and Receiving UDP-Encoded Packets
702
socket_nw() t_sendto_nw() AWAITIOX() FILE_GETINFO_()
t_recvfrom_nwAWAITIOX()FILE_GETINFO_()
Create a
socket
Initiate sending of
request packet
to NonStop agent
Detect
I/O
completion
Determine
outcome of
I/O operation
Detect I/O completion
Determine outcome
of I/O operation
Initiate receipt of
response packet
from NonStop agent
Determine amount
of data
written
socket_get_len