.TH sendto() "" "" "Sockets Function (libsocket)"
.PC "Send a message to a socket"
.B "#include <sys/socket.h>"
.B "#include <sys/types.h>"
\fBint send(\fIsocket\^\fB, \fImessage\^\fB, \fIlength\^\fB, \fIflags\^\fB, \fIaddr\^\fB, \fIalen\^\fB)\fR
\fBint \fIsocket\^\fB;\fR char *\fImessage\^\fB; int \fIlength\^\fB, \fIflags\^\fB;\fR
\fBsockaddr_t *\fIaddr\^\fB; int \fIalen\^\fB;\fR
.PP
The function
.B sendto()
sends a message to a socket.
Unlike the related function
.BR sendto() ,
it works regardless of whether the socket is connected.
.PP
.I socket
is the socket to which the messages are sent.
It must have been created by the function
.BR socket() .
.I buffer
points to the chunk of memory into which the message is to be written;
.I length
gives the amount of allocated memory to which
.I buffer
points.
If
.I from
is not NULL,
.B sendto()
initializes it to the the source address of the message.
It initializes
.I alen
to the size of the buffer associated with
.IR address ,
and modifies it upon return to the size of the address stored there.
.PP
.I flags
ORs together either or both of the following flags:
.IP \fBMSG_OOB\fR
Send ``out-of-band'' data on sockets that support this notion.
The underlying protocol must also support out-of-band data.
.\"Currently, only SOCK_STREAM sockets created in the AF_INET address
.\" family support out-of-band data.
.IP \fBMSG_DONTROUTE\fR
The socket turned on for the duration of the operation.
It is used only by diagnostic or routing programs.
.PP
If all goes well,
.B sendto()
returns the number of bytes it sent.
If something goes wrong, it returns \-1 and sets
.B errno
to one of the following values:
.IP \fBEAGAIN\fR
If
.I socket
has no buffer space available,
.B sendto()
normally waits until space becomes available (which is a blocking operation).
.IR socket ,
however, is marked as non-blocking.
.IP \fBEBADF\fR
.I socket
does not identify a valid socket.
.IP \fBEINTR\fR
A signal interrupted
.B sendto()
before it could send any data.
.IP \fBEMSGSIZE\fR
.I socket
requires that message be sent atomically, and the message was too long.
.IP \fBENOMEM\fR
Insufficient user memory was available to complete the operation.
.\" .IP \fBENOSR\fR
.\" Insufficient \*(ST resouces were available to complete the operation.
.IP ENOTSOCK\fR
.I socket
describes a file, not a socket.
.IP \fBEPROTO\fR
A protocol error has occurred.
.SH "See Also"
.Xr "connect()," connect
.Xr "libsocket," libsocket
.Xr "recv()," recv
.Xr "send()," send
.Xr "socket()" socket
.SH Notes
At present, the \*(CO implementation of
.B sendto()
always behaves as if
.I address
were initialized to NULL.
