|
|
Datagram sockets are created and name bound in the same ways as stream
sockets; see
``Creating a socket (Internet domain)''
and
``Binding socket names (Internet domain)''
for these procedures. However,
to send data from a datagram socket, the process uses
the sendto primitive:
sendto(s, buf, buflen, flags, &to, tolen);
The parameters are the same as those described for send, except the to and tolen values are used to indicate the intended recipient of the message.
When using an unreliable datagram interface, it is unlikely any errors will be reported to the sender. If information at the sending node indicates that the message cannot be delivered (for example, when a network is unreachable), the call returns -1, and the global variable errno contains an error number.
For an example, see `` Sending an Internet domain datagram''.