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 Sat Jul 24 01:15:33 1993 by Rik Faith <faith@cs.unc.edu>
33 .\" Modified Tue Oct 22 17:55:49 1996 by Eric S. Raymond <esr@thyrsus.com>
34 .\" Modified Oct 1998 by Andi Kleen
36 .TH SEND 2 2002-12-31 "Linux Man Page" "Linux Programmer's Manual"
38 send, sendto, sendmsg \- send a message from a socket
40 .B #include <sys/types.h>
42 .B #include <sys/socket.h>
44 .BI "ssize_t send(int " s ", const void *" msg ", size_t " len ,
47 .BI "ssize_t sendto(int " s ", const void *" msg ", size_t " len ,
48 .BI "int " flags ", const struct sockaddr *" to ", socklen_t " tolen );
50 .BI "ssize_t sendmsg(int " s ", const struct msghdr *" msg ,
57 are used to transmit a message to another socket.
59 may be used only when the socket is in a
65 may be used at any time.
67 The address of the target is given by
71 specifying its size. The length of the message is given by
73 If the message is too long to pass atomically through the
74 underlying protocol, the error
76 is returned, and the message is not transmitted.
78 No indication of failure to deliver is implicit in a
80 Locally detected errors are indicated by a return value of \-1.
82 When the message does not fit into the send buffer of the socket,
84 normally blocks, unless the socket has been placed in non-blocking I/O
85 mode. In non-blocking mode it would return
90 call may be used to determine when it is possible to send more data.
94 parameter is a flagword and can contain the following flags:
95 .\" XXX document MSG_PROXY
100 data on sockets that support this notion (e.g.
102 the underlying protocol must also support
107 Dont't use a gateway to send out the packet, only send to hosts on
108 directly connected networks. This is usually used only
109 by diagnostic or routing programs. This is only defined for protocol
110 families that route; packet sockets don't.
113 Enables non-blocking operation; if the operation would block,
115 is returned (this can also be enabled using the
124 on errors on stream oriented sockets when the other end breaks the
127 error is still returned.
129 .BR MSG_CONFIRM " (Linux 2.3+ only)"
130 Tell the link layer that forward process happened: you got a successful
131 reply from the other side. If the link layer doesn't get this
132 it'll regularly reprobe the neighbour (e.g. via a unicast ARP).
137 sockets and currently only implemented for IPv4 and IPv6. See
141 The definition of the
143 structure follows. See
145 and below for an exact description of its fields.
151 void * msg_name; /* optional address */
152 socklen_t msg_namelen; /* size of address */
153 struct iovec * msg_iov; /* scatter/gather array */
154 size_t msg_iovlen; /* # elements in msg_iov */
155 void * msg_control; /* ancillary data, see below */
156 socklen_t msg_controllen; /* ancillary data buffer len */
157 int msg_flags; /* flags on received message */
163 You may send control information using the
167 members. The maximum control buffer length the kernel can process is limited
169 .B net.core.optmem_max
173 The calls return the number of characters sent, or \-1
174 if an error occurred.
176 These are some standard errors generated by the socket layer. Additional errors
177 may be generated and returned from the underlying protocol modules; see their
178 respective manual pages.
181 An invalid descriptor was specified.
189 An invalid user space address was specified for a parameter.
192 The socket requires that message be sent atomically, and the size
193 of the message to be sent made this impossible.
195 .BR EAGAIN " or " EWOULDBLOCK
196 The socket is marked non-blocking and the requested operation
200 The output queue for a network interface was full.
201 This generally indicates that the interface has stopped sending,
202 but may be caused by transient congestion.
203 (Normally, this does not occur in Linux. Packets are just silently dropped
204 when a device queue overflows.)
213 Invalid argument passed.
216 The local end has been shut down on a connection oriented socket.
217 In this case the process
224 4.4BSD, SVr4, POSIX 1003.1g draft (these function calls appeared in 4.2BSD).
227 is a Linux extension.
229 The prototypes given above follow the Single Unix Specification,
230 as glibc2 also does; the
232 argument was `int' in BSD 4.*, but `unsigned int' in libc4 and libc5;
235 argument was `int' in BSD 4.* and libc4, but `size_t' in libc5;
238 argument was `int' in BSD 4.* and libc4 and libc5.