1SEND(2)                    Linux Programmer's Manual                   SEND(2)
2
3
4

NAME

6       send, sendto, sendmsg - send a message on a socket
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/socket.h>
11
12       ssize_t send(int sockfd, const void *buf, size_t len, int flags);
13
14       ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
15                      const struct sockaddr *dest_addr, socklen_t addrlen);
16
17       ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
18

DESCRIPTION

20       The system calls send(), sendto(), and sendmsg() are used to transmit a
21       message to another socket.
22
23       The send() call may be used only when the  socket  is  in  a  connected
24       state  (so  that the intended recipient is known).  The only difference
25       between send() and write(2) is the presence  of  flags.   With  a  zero
26       flags  argument, send() is equivalent to write(2).  Also, the following
27       call
28
29           send(sockfd, buf, len, flags);
30
31       is equivalent to
32
33           sendto(sockfd, buf, len, flags, NULL, 0);
34
35       The argument sockfd is the file descriptor of the sending socket.
36
37       If sendto() is used on a connection-mode (SOCK_STREAM,  SOCK_SEQPACKET)
38       socket,  the arguments dest_addr and addrlen are ignored (and the error
39       EISCONN may be returned when they are not NULL and 0),  and  the  error
40       ENOTCONN  is returned when the socket was not actually connected.  Oth‐
41       erwise, the address of the target is given by  dest_addr  with  addrlen
42       specifying its size.  For sendmsg(), the address of the target is given
43       by msg.msg_name, with msg.msg_namelen specifying its size.
44
45       For send() and sendto(), the message is found in  buf  and  has  length
46       len.   For  sendmsg(), the message is pointed to by the elements of the
47       array msg.msg_iov.  The sendmsg() call also  allows  sending  ancillary
48       data (also known as control information).
49
50       If  the  message  is too long to pass atomically through the underlying
51       protocol, the error EMSGSIZE is returned, and the message is not trans‐
52       mitted.
53
54       No  indication  of failure to deliver is implicit in a send().  Locally
55       detected errors are indicated by a return value of -1.
56
57       When the message does not fit into  the  send  buffer  of  the  socket,
58       send()  normally blocks, unless the socket has been placed in nonblock‐
59       ing I/O mode.  In nonblocking mode it would fail with the error  EAGAIN
60       or  EWOULDBLOCK in this case.  The select(2) call may be used to deter‐
61       mine when it is possible to send more data.
62
63   The flags argument
64       The flags argument is the bitwise OR of zero or more of  the  following
65       flags.
66
67       MSG_CONFIRM (since Linux 2.3.15)
68              Tell  the  link  layer that forward prog