'\"macro stdmacro
.if n .pH g3n.send @(#)send	40.8 of 1/29/90
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} send 3N "" "\&"
.if \nX=1 .ds x} send 3N ""
.if \nX=2 .ds x} send 3N "" "\&"
.if \nX=3 .ds x} send "" "" "\&"
.TH \*(x}
.SH NAME
\f4send, sendto, sendmsg\fP \- send a message from a socket
.SH SYNOPSIS
.nf
.ft CW
#include <sys/types.h>
#include <sys/socket.h>
.LP
.ft CW
int send(s, msg, len, flags)
int s;
char \(**msg;
int len, flags;
.LP
.ft CW
int sendto(s, msg, len, flags, to, tolen)
int s;
char \(**msg;
int len, flags;
struct sockaddr \(**to;
int tolen;
.LP
.ft CW
int sendmsg(s, msg, flags)
int s;
struct msghdr \(**msg;
int flags;
.fi
.SH DESCRIPTION
.LP
.I s
is a socket created with \f4socket\f1(3N).
\f4send()\f1, \f4sendto()\f1, and \f4sendmsg()\f1
are used to transmit a message to another socket.
\f4send()\f1 may be used only when the socket is in a
.I connected
state, while \f4sendto()\f1 and \f4sendmsg()\f1
may be used at any time.
.LP
The address of the target is given by
.I to
with
.I tolen
specifying its size.
The length of the message is given by
.IR len .
If the message is too long to pass atomically through the
underlying protocol, then the error
\f4EMSGSIZE\f1
is returned, and
the message is not transmitted.
.LP
No indication of failure to deliver is implicit in a \f4send()\f1.
Return values of \-1 indicate some locally detected errors.
.LP
If no buffer space is available at the socket to hold
the message to be transmitted, then \f4send()\f1
normally blocks, unless the socket has been placed in
non-blocking I/O mode (see \f4fcntl\f1(2)).
The \f4select()\f1 call may be used to determine when it is
possible to send more data.
.LP
The
.I flags
parameter is formed by
.SM OR\s0ing
one or more of the following:
.TP 1i
\f4MSG_OOB\f1
Send \(lqout-of-band\(rq
data on sockets that support this notion. 
The underlying protocol must also
support \(lqout-of-band\(rq data.
Currently, only
\f4SOCK_STREAM\f1
sockets created in the
\f4AF_INET\f1
address family support out-of-band data.
.TP
\f4MSG_DONTROUTE\f1
The
\f4SO_DONTROUTE\f1
option is turned on for the duration of the operation.
It is used only by diagnostic or routing programs.
.LP
See
\f4recv\fP(3N)
for a description of the
\f4msghdr\fP
structure.
.SH RETURN VALUE
.LP
These calls return the number of bytes sent,
or \f4-1\fP if an error occurred.
.SH ERRORS
.LP
The calls fail if:
.TP 20
\f4EBADF\f1
.I s
is an invalid descriptor.
.TP
\f4ENOTSOCK\f1
.I s
is a descriptor for a file, not a socket.
.TP
\f4EINVAL\f1
\f2tolen\fP
is not the size of a valid address for the specified address family.
.TP
\f4EINTR\f1
The operation was interrupted by delivery of a signal before
any data could be buffered to be sent.
.\".TP
.\".SM EFAULT
.\"The data was specified to be sent to a non-existent
.\"or protected part of the process address space.
.TP
\f4EMSGSIZE\f1
The socket requires that message be sent atomically,
and the message was too long.
.TP
\f4EWOULDBLOCK\f1
The socket is marked non-blocking and the requested operation
would block.
.TP
\f4ENOMEM\f1
There was insufficient user memory available for the operation to
complete.
.TP
\f4ENOSR\f1
There were insufficient
.SM STREAMS
resources available for the operation to
complete.
.SH SEE ALSO
\f4connect\f1(3N),
\f4fcntl\f1(2),
\f4getsockopt\f1(3N),
\f4recv\f1(3N),
.\" \f4select\f1(3),
\f4socket\f1(3N),
\f4write\f1(2).
