1 .\" Copyright (c) 1983, 1991, 1993
2 .\" The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" From: @(#)send.2 8.2 (Berkeley) 2/21/94
39 .Nd send message(s) from a socket
45 .Fn send "int s" "const void *msg" "size_t len" "int flags"
47 .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen"
49 .Fn sendmsg "int s" "const struct msghdr *msg" "int flags"
51 .Fn sendmmsg "int s" "struct mmsghdr * restrict msgvec" "size_t vlen" "int flags"
63 are used to transmit one or more messages (with the
70 may be used only when the socket is in a
78 may be used at any time if the socket is connectionless-mode.
79 If the socket is connection-mode, the protocol
80 must support implied connect (currently
82 is the only protocol with support) or the socket must be in a
83 connected state before use.
85 The address of the target is given by
89 specifying its size, or the equivalent
95 If the socket is in a connected state, the target address passed to
101 The length of the message is given by
103 If the message is too long to pass atomically through the
104 underlying protocol, the error
107 the message is not transmitted.
111 function sends multiple messages at a call.
112 They are given by the
116 specifying the vector size.
117 The number of octets sent per each message is placed in the
119 field of each processed element of the vector after transmission.
121 No indication of failure to deliver is implicit in a
123 Locally detected errors are indicated by a return value of -1.
125 If no messages space is available at the socket to hold
126 the message to be transmitted, then
128 normally blocks, unless the socket has been placed in
129 non-blocking I/O mode.
132 system call may be used to determine when it is possible to
137 argument may include one or more of the following:
139 #define MSG_OOB 0x00001 /* process out-of-band data */
140 #define MSG_DONTROUTE 0x00004 /* bypass routing, use direct interface */
141 #define MSG_EOR 0x00008 /* data completes record */
142 #define MSG_DONTWAIT 0x00080 /* do not block */
143 #define MSG_EOF 0x00100 /* data completes transaction */
144 #define MSG_NOSIGNAL 0x20000 /* do not generate SIGPIPE on EOF */
151 data on sockets that support this notion (e.g.\&
153 the underlying protocol must also support
157 is used to indicate a record mark for protocols which support the
161 flag request the call to return when it would block otherwise.
163 requests that the sender side of a socket be shut down, and that an
164 appropriate indication be sent at the end of the specified data;
165 this flag is only implemented for
171 is usually used only by diagnostic or routing programs.
175 generation when writing a socket that
180 for a description of the
192 return the number of octets sent.
195 call returns the number of messages sent.
196 If an error occurred a value of -1 is returned.
210 An invalid descriptor was specified.
212 The destination address is a broadcast address, and
214 has not been set on the socket.
216 The socket is connection-mode but is not connected.
222 An invalid user space address was specified for an argument.
224 The socket requires that message be sent atomically,
225 and the size of the message to be sent made this impossible.
227 The socket is marked non-blocking, or
229 is specified, and the requested operation would block.
231 The system was unable to allocate an internal buffer.
232 The operation may succeed when buffers become available.
234 The output queue for a network interface was full.
235 This generally indicates that the interface has stopped sending,
236 but may be caused by transient congestion.
237 .It Bq Er EHOSTUNREACH
238 The remote host was unreachable.
240 A destination address was specified and the socket is already connected.
241 .It Bq Er ECONNREFUSED
242 The socket received an ICMP destination unreachable message
243 from the last message sent.
244 This typically means that the
245 receiver is not listening on the remote port.
247 The remote host was down.
249 The remote network was down.
250 .It Bq Er EADDRNOTAVAIL
253 socket was jailed and the source
254 address specified in the IP header did not match the IP
255 address bound to the prison.
257 The socket is unable to send anymore data
258 .Dv ( SBS_CANTSENDMORE
259 has been set on the socket).
260 This typically means that the socket
284 does not necessarily block until the data has been transferred, it
285 is possible to transfer an open file descriptor across an
292 it before it has actually been sent, the result being that the receiver
293 gets a closed file descriptor.
294 It is left to the application to
295 implement an acknowledgment mechanism to prevent this from happening.