1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
33 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
34 .\" Modified Oct 1998 by Andi Kleen
35 .\" Modified Oct 2003 by aeb
36 .\" Modified 2004-07-01 by mtk
38 .TH SEND 2 2004-07-01 "Linux" "Linux Programmer's Manual"
40 send, sendto, sendmsg \- send a message on a socket
43 .B #include <sys/types.h>
44 .B #include <sys/socket.h>
46 .BI "ssize_t send(int " s ", const void *" buf ", size_t " len \
49 .BI "ssize_t sendto(int " s ", const void *" buf ", size_t " len \
51 .BI " const struct sockaddr *" to ", socklen_t " tolen );
53 .BI "ssize_t sendmsg(int " s ", const struct msghdr *" msg \
62 are used to transmit a message to another socket.
66 call may be used only when the socket is in a
68 state (so that the intended recipient is known).
69 The only difference between
82 .RI send( s , buf , len , flags )
84 .RI sendto( s , buf , len , flags ,NULL,0).
88 is the file descriptor of the sending socket.
92 is used on a connection-mode
95 socket, the parameters
99 are ignored (and the error
101 may be returned when they are
102 not NULL and 0), and the error
104 is returned when the socket was not actually connected.
105 Otherwise, the address of the target is given by
112 the address of the target is given by
122 the message is found in
128 the message is pointed to by the elements of the array
132 call also allows sending ancillary data (also known as control information).
134 If the message is too long to pass atomically through the
135 underlying protocol, the error
137 is returned, and the message is not transmitted.
139 No indication of failure to deliver is implicit in a
141 Locally detected errors are indicated by a return value of \-1.
143 When the message does not fit into the send buffer of the socket,
145 normally blocks, unless the socket has been placed in non-blocking I/O
147 In non-blocking mode it would return
152 call may be used to determine when it is possible to send more data.
156 parameter is the bitwise OR
157 of zero or more of the following flags.
158 .\" FIXME ? document MSG_PROXY (which went away in 2.3.15)
160 .BR MSG_CONFIRM " (Linux 2.3+ only)"
161 Tell the link layer that forward progress happened: you got a successful
162 reply from the other side.
163 If the link layer doesn't get this
164 it will regularly reprobe the neighbor (e.g., via a unicast ARP).
169 sockets and currently only implemented for IPv4 and IPv6.
175 Don't use a gateway to send out the packet, only send to hosts on
176 directly connected networks.
177 This is usually used only
178 by diagnostic or routing programs.
179 This is only defined for protocol
180 families that route; packet sockets don't.
183 Enables non-blocking operation; if the operation would block,
185 is returned (this can also be enabled using the
192 Terminates a record (when this notion is supported, as for sockets of type
193 .BR SOCK_SEQPACKET ).
195 .BR MSG_MORE " (Since Linux 2.4.4)"
196 The caller has more data to send.
197 This flag is used with TCP sockets to obtain the same effect
202 with the difference that this flag can be set on a per-call basis.
204 Since Linux 2.6, this flag is also supported for UDP sockets, and informs
205 the kernel to package all of the data sent in calls with this flag set
206 into a single datagram which is only transmitted when a call is performed
207 that does not specify this flag.
210 socket option described in
216 on errors on stream oriented sockets when the other end breaks the
220 error is still returned.
225 data on sockets that support this notion (e.g., of type
227 the underlying protocol must also support
231 The definition of the
236 and below for an exact description of its fields.
241 void *msg_name; /* optional address */
242 socklen_t msg_namelen; /* size of address */
243 struct iovec *msg_iov; /* scatter/gather array */
244 size_t msg_iovlen; /* # elements in msg_iov */
245 void *msg_control; /* ancillary data, see below */
246 socklen_t msg_controllen; /* ancillary data buffer len */
247 int msg_flags; /* flags on received message */
252 You may send control information using the
257 The maximum control buffer length the kernel can process is limited
259 .B net.core.optmem_max
262 .\" Still to be documented:
263 .\" Send file descriptors and user credentials using the
264 .\" msg_control* fields.
265 .\" The flags returned in msg_flags.
267 On success, these calls return the number of characters sent.
268 On error, \-1 is returned, and
270 is set appropriately.
272 These are some standard errors generated by the socket layer.
274 may be generated and returned from the underlying protocol modules;
275 see their respective manual pages.
278 (For Unix domain sockets, which are identified by pathname)
279 Write permission is denied on the destination socket file,
280 or search permission is denied for one of the directories
283 .BR path_resolution (7).)
285 .BR EAGAIN " or " EWOULDBLOCK
286 The socket is marked non-blocking and the requested operation
290 An invalid descriptor was specified.
293 Connection reset by peer.
296 The socket is not connection-mode, and no peer address is set.
299 An invalid user space address was specified for a parameter.
302 A signal occurred before any data was transmitted.
305 Invalid argument passed.
308 The connection-mode socket was connected already but a
309 recipient was specified.
310 (Now either this error is returned, or the recipient specification
315 .\" (e.g., SOCK_DGRAM )
316 requires that message be sent atomically, and the size
317 of the message to be sent made this impossible.
320 The output queue for a network interface was full.
321 This generally indicates that the interface has stopped sending,
322 but may be caused by transient congestion.
323 (Normally, this does not occur in Linux.
324 Packets are just silently dropped
325 when a device queue overflows.)
331 The socket is not connected, and no target has been given.
341 argument is inappropriate for the socket type.
344 The local end has been shut down on a connection oriented socket.
345 In this case the process
352 4.4BSD, SVr4, POSIX.1-2001.
353 These function calls appeared in 4.2BSD.
355 POSIX.1-2001 only describes the
362 flag is a Linux extension.
364 The prototypes given above follow the Single Unix Specification,
365 as glibc2 also does; the
367 argument was \fIint\fP in 4.x BSD, but \fIunsigned int\fP in libc4 and libc5;
370 argument was \fIint\fP in 4.x BSD and libc4, but \fIsize_t\fP in libc5;
373 argument was \fIint\fP in 4.x BSD and libc4 and libc5.
377 According to POSIX.1-2001, the
381 structure should be typed as
383 but glibc currently (2.4) types it as
385 .\" glibc bug raised 12 Mar 2006
386 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=2448
387 .\" The problem is an underlying kernel issue: the size of the
388 .\" __kernel_size_t type used to type this field varies
389 .\" across architectures, but socklen_t is always 32 bits.
396 An example of the use of