Sends bytes through a socket to any other socket.
#include <socket.h> int sendto (int s, char *msg, int len, int flags, struct sockaddr *to, int tolen);Routine Variants This socket routine has a variant named __bsd44_sendto. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.
If there is no space available to buffer the data being sent on the receiving end of the connection, sendto will normally block until buffer space becomes available. If the socket is defined as nonblocking, however, sendto will fail with an errno indication of EWOULDBLOCK. If the message is too large to be sent in one piece and the socket type requires that messages be sent atomically (using SOCK_DGRAM), sendto will fail with an errno indication of EMSGSIZE.
No indication of failure to deliver is implicit in a sendto. All errors (except EWOULDBLOCK) are detected locally. You may use the select routine to determine when it is possible to send more data.
If the address specified is a INADDR_BROADCAST address, then the SO_BROADCAST option must be set and the process must have SYSPRV or BYPASS privilege for the I/O operation to succeed.
See also read, recv, recvfrom, recvmsg, and socket in this section, and getsockopt in this appendix.
n | The number of bytes sent. This value will normally equal len. |
- 1 | Indicates an error; errno is set to one of the
following:
|