1 .\" $NetBSD: send.2,v 1.6 1996/01/15 01:17:18 thorpej Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)send.2 8.2 (Berkeley) 2/21/94
43 .Nd send a message from a socket
45 .Fd #include <sys/socket.h>
49 .Fa "const void *buffer"
56 .Fa "const struct msghdr *buffer"
62 .Fa "const void *buffer"
65 .Fa "const struct sockaddr *dest_addr"
66 .Fa "socklen_t dest_len"
73 are used to transmit a message to another socket.
75 may be used only when the socket is in a
81 may be used at any time.
83 The address of the target is given by
88 The length of the message is given by
90 If the message is too long to pass atomically through the
91 underlying protocol, the error
94 the message is not transmitted.
96 No indication of failure to deliver is implicit in a
98 Locally detected errors are indicated by a return value of -1.
100 If no messages space is available at the socket to hold
101 the message to be transmitted, then
103 normally blocks, unless the socket has been placed in
104 non-blocking I/O mode.
107 call may be used to determine when it is possible to
112 parameter may include one or more of the following:
114 #define MSG_OOB 0x1 /* process out-of-band data */
115 #define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */
122 data on sockets that support this notion (e.g.
124 the underlying protocol must also support
128 is usually used only by diagnostic or routing programs.
132 for a description of the
136 Upon successful completion,
137 the number of bytes which were sent is returned.
138 Otherwise, -1 is returned and the global variable
140 is set to indicate the error.
147 system calls will fail if:
151 The SO_BROADCAST option is not set on the socket
152 and a broadcast address is given as the destination.
155 The socket is marked non-blocking
156 and the requested operation would block.
159 An invalid descriptor is specified.
162 A connection is forcibly closed by a peer.
165 An invalid user space address is specified for a parameter.
167 .It Bq Er EHOSTUNREACH
168 The destination address specifies an unreachable host.
171 A signal interrupts the system call
172 before any data is transmitted.
175 The socket requires that message be sent atomically,
176 and the size of the message to be sent makes this impossible.
179 The local network interface used to reach the destination is down.
181 .It Bq Er ENETUNREACH
182 No route to the network is present.
185 The system is unable to allocate an internal buffer.
186 The operation may succeed when buffers become available.
189 The output queue for a network interface is full.
190 This generally indicates that the interface has stopped sending,
191 but may be caused by transient congestion.
200 does not support (some of) the option(s) specified in
204 The socket is shut down for writing
205 or the socket is connection-mode and is no longer connected.
206 In the latter case, and if the socket is of type SOCK_STREAM,
207 the SIGPIPE signal is generated to the calling thread.
214 system calls will fail if:
217 .It Bq Er EAFNOSUPPORT
218 Addresses in the specified address family cannot be used
221 .It Bq Er EDESTADDRREQ
222 The socket is not connection-mode and does not have its peer address set,
223 and no destination address is specified.
226 A destination address was specified and the socket is already connected.
229 A component of the pathname does not name an existing file
230 or the path name is an empty string.
233 Insufficient memory is available to fulfill the request.
236 The socket is connection-mode, but is not connected.
239 A component of the path prefix of the pathname in the socket address
245 system call will fail if:
248 .It Bq Er EDESTADDRREQ
249 The socket is not connection-mode and no peer address is set.
252 The socket is not connected or otherwise has not had the peer pre-specified.
257 system call will fail if:
261 The sum of the iov_len values overflows an ssize_t.
264 .Fd #include <sys/types.h>
265 .Fd #include <sys/socket.h>
268 .In sys/types.h is necessary.
280 function call appeared in