Seth Woolley's Man Viewer

Manual for send - man 2 send

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

SEND(2)                    Linux Programmer's Manual                   SEND(2)

       send(2,n), sendto, sendmsg - send(2,n) a message from a socket(2,7,n)

       #include <sys/types.h>
       #include <sys/socket.h>

       ssize_t send(2,n)(int s, const void *buf, size_t len, int flags);
       ssize_t  sendto(int  s,  const  void *buf, size_t len, int flags, const
       struct sockaddr *to, socklen_t tolen);
       ssize_t sendmsg(int s, const struct msghdr *msg, int flags);

       The system calls send(2,n), sendto, and sendmsg are used to transmit a  mes-
       sage to another socket.

       The  send(2,n) call may be used only when the socket(2,7,n) is in(1,8) a connected state
       (so that the intended recipient is known).  The only difference between
       send(2,n)  and  write(1,2)  is the presence of flags.  With zero flags parameter,
       send(2,n) is equivalent to write(1,2).  Also, send(2,n)(s,buf,len)  is  equivalent  to

       The parameter s is the file(1,n) descriptor of the sending socket.

       If  sendto  is  used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET)
       socket(2,7,n), the parameters to and tolen are ignored (and the error(8,n)  EISCONN
       may  be  returned when they are not NULL and 0), and the error(8,n) ENOTCONN
       is returned when the socket(2,7,n) was not actually connected. Otherwise,  the
       address  of  the  target is given by to with tolen specifying its size.
       For sendmsg, the address of the target is given by  msg.msg_name,  with
       msg.msg_namelen specifying its size.

       For  send(2,n)  and  sendto, the message is found in(1,8) buf and has length len.
       For sendmsg, the message is pointed to by the  elements  of  the  array
       msg.msg_iov.  The sendmsg call also allows sending ancillary data (also
       known as control information).

       If the message is too long to pass atomically  through  the  underlying
       protocol, the error(8,n) EMSGSIZE is returned, and the message is not trans-

       No indication of failure to deliver is implicit  in(1,8)  a  send(2,n).   Locally
       detected errors are indicated by a return value of -1.

       When  the message does not fit into the send(2,n) buffer of the socket(2,7,n), send(2,n)
       normally blocks, unless the socket(2,7,n) has been placed in(1,8) non-blocking  I/O
       mode.   In  non-blocking mode it would return EAGAIN in(1,8) this case.  The
       select(2,7,2 select_tut)(2) call may be used to determine when it  is  possible  to  send(2,n)
       more data.

       The  flags parameter is the bitwise OR of zero or more of the following

              Sends out-of-band data on sockets that support this notion (e.g.
              of  type SOCK_STREAM); the underlying protocol must also support
              out-of-band data.

              Terminates a record (when this notion is supported, as for sock-
              ets of type SOCK_SEQPACKET).

              Don't  use  a gateway to send(2,n) out the packet, only send(2,n) to hosts
              on directly connected networks. This is  usually  used  only  by
              diagnostic  or routing programs. This is only defined for proto-
              col families that route; packet sockets don't.

              Enables non-blocking operation; if(3,n) the  operation  would  block,
              EAGAIN  is  returned  (this can also be enabled using the O_NON-
              BLOCK with the F_SETFL fcntl(2)).

              Requests not to send(2,n) SIGPIPE on errors on stream oriented  sock-
              ets when the other end breaks the connection. The EPIPE error(8,n) is
              still returned.

       MSG_CONFIRM (Linux 2.3+ only)
              Tell the link(1,2) layer that forward progress happened:  you  got  a
              successful  reply from the other side. If the link(1,2) layer doesn't
              get this it'll regularly reprobe the neighbour (e.g. via a  uni-
              cast  ARP).   Only  valid on SOCK_DGRAM and SOCK_RAW sockets and
              currently only implemented for IPv4 and  IPv6.  See  arp(7,8)(7)  for

       MSG_MORE (Since Linux 2.4.4)
              The  caller  has  more data to send.  This flag is used with TCP
              sockets to obtain the same effect as the TCP_CORK socket(2,7,n)  option
              (see tcp(7)), with the difference that this flag can be set(7,n,1 builtins) on a
              per-call basis.  Since Linux 2.6, this flag  is  also  supported
              for  UDP  sockets,  and informs the kernel to package all of the
              data sent in(1,8) calls with this flag set(7,n,1 builtins)  into  a  single  datagram
              which is only transmitted when a call is performed that does not
              specify this flag.

       The definition of the msghdr structure follows. See recv(2)  and  below
       for an exact description of its fields.

              struct msghdr {
                  void         * msg_name;     /* optional address */
                  socklen_t    msg_namelen;    /* size of address */
                  struct iovec * msg_iov;      /* scatter/gather array */
                  size_t       msg_iovlen;     /* # elements in(1,8) msg_iov */
                  void         * msg_control;  /* ancillary data, see below */
                  socklen_t    msg_controllen; /* ancillary data buffer len */
                  int          msg_flags;      /* flags on received message */

       You  may  send(2,n)  control  information using the msg_control and msg_con-
       trollen members. The maximum  control  buffer  length  the  kernel  can
       process  is  limited  per socket(2,7,n) by the net.core.optmem_max sysctl(2,5,8); see

       The calls return the number of characters  sent,  or  -1  if(3,n)  an  error(8,n)

       These  are  some  standard  errors generated by the socket(2,7,n) layer. Addi-
       tional errors may be generated and returned from the underlying  proto-
       col modules; see their respective manual pages.

       EACCES (For  Unix  domain  sockets,  which  are identified by pathname)
              Write permission is denied on the destination  socket(2,7,n)  file(1,n),  or
              search  permission is denied for one of the directories the path
              prefix. (See path_resolution(2).)

              The socket(2,7,n) is marked non-blocking and  the  requested  operation
              would block.

       EBADF  An invalid descriptor was specified.

              Connection reset(1,7,1 tput) by peer.

              The socket(2,7,n) is not connection-mode, and no peer address is set.

       EFAULT An invalid user space address was specified for a parameter.

       EINTR  A signal(2,7) occurred before any data was transmitted.

       EINVAL Invalid argument passed.

              The connection-mode socket(2,7,n) was connected already but a recipient
              was specified.  (Now either  this  error(8,n)  is  returned,  or  the
              recipient specification is ignored.)

              The  socket(2,7,n)  type  requires that message be sent atomically, and
              the size of the message to be sent made this impossible.

              The output queue(1,3) for a network interface was full.  This  gener-
              ally  indicates  that the interface has stopped sending, but may
              be caused by transient congestion.   (Normally,  this  does  not
              occur  in(1,8) Linux. Packets are just silently dropped when a device
              queue(1,3) overflows.)

       ENOMEM No memory available.

              The socket(2,7,n) is not connected, and no target has been given.

              The argument s is not a socket.

              Some bit in(1,8) the flags argument is inappropriate for  the  socket(2,7,n)

       EPIPE  The  local  end  has  been  shut  down  on a connection oriented
              socket.  In this case the process will also  receive  a  SIGPIPE
              unless MSG_NOSIGNAL is set.

       4.4BSD,  SVr4,  POSIX  1003.1-2001.   These  function calls appeared in(1,8)

       POSIX only describes the MSG_OOB and MSG_EOR  flags.   The  MSG_CONFIRM
       flag is a Linux extension.

       The  prototypes  given  above  follow the Single Unix Specification, as
       glibc2 also does;  the  flags  argument  was  `int'  in(1,8)  BSD  4.*,  but
       `unsigned  int'  in(1,8)  libc4 and libc5; the len argument was `int' in(1,8) BSD
       4.* and libc4, but `size_t' in(1,8) libc5; the tolen argument was  `int'  in(1,8)
       BSD 4.* and libc4 and libc5.  See also accept(2,8)(2).

       Linux may return EPIPE instead of ENOTCONN.

       fcntl(2),  getsockopt(2),  recv(2),  select(2,7,2 select_tut)(2), sendfile(1,2)(2), socket(2,7,n)(2),
       write(1,2)(2), ip(7,8)(7), socket(2,7,n)(7), tcp(7), udp(7)

Linux 2.6.7                       2004-07-01                           SEND(2)

References for this manual (incoming links)