1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified Oct 1998 by Andi Kleen
37 .\" Modified Oct 2003 by aeb
38 .\" Modified 2004-07-01 by mtk
40 .TH SEND 2 2014-08-19 "Linux" "Linux Programmer's Manual"
42 send, sendto, sendmsg \- send a message on a socket
45 .B #include <sys/types.h>
46 .B #include <sys/socket.h>
48 .BI "ssize_t send(int " sockfd ", const void *" buf ", size_t " len \
51 .BI "ssize_t sendto(int " sockfd ", const void *" buf ", size_t " len \
53 .BI " const struct sockaddr *" dest_addr ", socklen_t " addrlen );
55 .BI "ssize_t sendmsg(int " sockfd ", const struct msghdr *" msg \
64 are used to transmit a message to another socket.
68 call may be used only when the socket is in a
70 state (so that the intended recipient is known).
71 The only difference between
83 Also, the following call
85 send(sockfd, buf, len, flags);
89 sendto(sockfd, buf, len, flags, NULL, 0);
93 is the file descriptor of the sending socket.
97 is used on a connection-mode
100 socket, the arguments
104 are ignored (and the error
106 may be returned when they are
107 not NULL and 0), and the error
109 is returned when the socket was not actually connected.
110 Otherwise, the address of the target is given by
117 the address of the target is given by
127 the message is found in
133 the message is pointed to by the elements of the array
137 call also allows sending ancillary data (also known as control information).
139 If the message is too long to pass atomically through the
140 underlying protocol, the error
142 is returned, and the message is not transmitted.
144 No indication of failure to deliver is implicit in a
146 Locally detected errors are indicated by a return value of \-1.
148 When the message does not fit into the send buffer of the socket,
150 normally blocks, unless the socket has been placed in nonblocking I/O
152 In nonblocking mode it would fail with the error
159 call may be used to determine when it is possible to send more data.
160 .SS The flags argument
163 argument is the bitwise OR
164 of zero or more of the following flags.
165 .\" FIXME . ? document MSG_PROXY (which went away in 2.3.15)
167 .BR MSG_CONFIRM " (since Linux 2.3.15)"
168 Tell the link layer that forward progress happened: you got a successful
169 reply from the other side.
170 If the link layer doesn't get this
171 it will regularly reprobe the neighbor (e.g., via a unicast ARP).
176 sockets and currently implemented only for IPv4 and IPv6.
182 Don't use a gateway to send out the packet, send to hosts only on
183 directly connected networks.
184 This is usually used only
185 by diagnostic or routing programs.
186 This is defined only for protocol
187 families that route; packet sockets don't.
189 .BR MSG_DONTWAIT " (since Linux 2.2)"
190 Enables nonblocking operation; if the operation would block,
194 is returned (this can also be enabled using the
200 .BR MSG_EOR " (since Linux 2.2)"
201 Terminates a record (when this notion is supported, as for sockets of type
202 .BR SOCK_SEQPACKET ).
204 .BR MSG_MORE " (since Linux 2.4.4)"
205 The caller has more data to send.
206 This flag is used with TCP sockets to obtain the same effect
211 with the difference that this flag can be set on a per-call basis.
213 Since Linux 2.6, this flag is also supported for UDP sockets, and informs
214 the kernel to package all of the data sent in calls with this flag set
215 into a single datagram which is transmitted only when a call is performed
216 that does not specify this flag.
219 socket option described in
222 .BR MSG_NOSIGNAL " (since Linux 2.2)"
225 on errors on stream oriented sockets when the other end breaks the
229 error is still returned.
234 data on sockets that support this notion (e.g., of type
236 the underlying protocol must also support
240 The definition of the
242 structure employed by
249 void *msg_name; /* optional address */
250 socklen_t msg_namelen; /* size of address */
251 struct iovec *msg_iov; /* scatter/gather array */
252 size_t msg_iovlen; /* # elements in msg_iov */
253 void *msg_control; /* ancillary data, see below */
254 size_t msg_controllen; /* ancillary data buffer len */
255 int msg_flags; /* flags (unused) */
262 field is used on an unconnected socket to specify the target
263 address for a datagram.
264 It points to a buffer containing the address; the
266 field should be set to the size of the address.
267 For a connected socket, these fields should be specified as NULL and 0,
274 fields specify scatter-gather locations, as for
277 You may send control information using the
282 The maximum control buffer length the kernel can process is limited
283 per socket by the value in
284 .IR /proc/sys/net/core/optmem_max ;
291 .\" Still to be documented:
292 .\" Send file descriptors and user credentials using the
293 .\" msg_control* fields.
295 On success, these calls return the number of bytes sent.
296 On error, \-1 is returned, and
298 is set appropriately.
300 These are some standard errors generated by the socket layer.
302 may be generated and returned from the underlying protocol modules;
303 see their respective manual pages.
306 (For UNIX domain sockets, which are identified by pathname)
307 Write permission is denied on the destination socket file,
308 or search permission is denied for one of the directories
311 .BR path_resolution (7).)
313 (For UDP sockets) An attempt was made to send to a
314 network/broadcast address as though it was a unicast address.
316 .BR EAGAIN " or " EWOULDBLOCK
317 .\" Actually EAGAIN on Linux
318 The socket is marked nonblocking and the requested operation
320 POSIX.1-2001 allows either error to be returned for this case,
321 and does not require these constants to have the same value,
322 so a portable application should check for both possibilities.
325 (Internet domain datagram sockets)
326 The socket referred to by
328 had not previously been bound to an address and,
329 upon attempting to bind it to an ephemeral port,
330 it was determined that all port numbers in the ephemeral port range
331 are currently in use.
332 See the discussion of
333 .I /proc/sys/net/ipv4/ip_local_port_range
338 An invalid descriptor was specified.
341 Connection reset by peer.
344 The socket is not connection-mode, and no peer address is set.
347 An invalid user space address was specified for an argument.
350 A signal occurred before any data was transmitted; see
354 Invalid argument passed.
357 The connection-mode socket was connected already but a
358 recipient was specified.
359 (Now either this error is returned, or the recipient specification
364 .\" (e.g., SOCK_DGRAM )
365 requires that message be sent atomically, and the size
366 of the message to be sent made this impossible.
369 The output queue for a network interface was full.
370 This generally indicates that the interface has stopped sending,
371 but may be caused by transient congestion.
372 (Normally, this does not occur in Linux.
373 Packets are just silently dropped
374 when a device queue overflows.)
380 The socket is not connected, and no target has been given.
390 argument is inappropriate for the socket type.
393 The local end has been shut down on a connection oriented socket.
394 In this case, the process
401 4.4BSD, SVr4, POSIX.1-2001.
402 These function calls appeared in 4.2BSD.
404 POSIX.1-2001 describes only the
409 POSIX.1-2008 adds a specification of
413 flag is a Linux extension.
415 According to POSIX.1-2001, the
419 structure should be typed as
421 but glibc currently types it as
423 .\" glibc bug raised 12 Mar 2006
424 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=2448
425 .\" The problem is an underlying kernel issue: the size of the
426 .\" __kernel_size_t type used to type this field varies
427 .\" across architectures, but socklen_t is always 32 bits.
431 for information about a Linux-specific system call
432 that can be used to transmit multiple datagrams in a single call.
439 An example of the use of
459 This page is part of release 3.79 of the Linux
462 A description of the project,
463 information about reporting bugs,
464 and the latest version of this page,
466 \%http://www.kernel.org/doc/man\-pages/.