1 .\" $NetBSD: send.2,v 1.31 2013/07/14 14:29:09 njoly 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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)send.2 8.2 (Berkeley) 2/21/94
40 .Nd send a message from a socket
46 .Fn send "int s" "const void *msg" "size_t len" "int flags"
48 .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen"
50 .Fn sendmsg "int s" "const struct msghdr *msg" "int flags"
52 .Fn sendmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "unsigned int flags"
59 are used to transmit a message to another socket.
61 may be used only when the socket is in a
68 may be used at any time.
72 call be used to send multiple messages in the same call using an array of
74 elements with the following form, as defined in
75 .Ao Pa sys/socket.h Ac :
79 struct msghdr msg_hdr; /* the message to be sent */
80 unsigned int msg_len; /* number of bytes transmitted */
86 member contains the number of bytes sent for each
91 elements, which is limited to
93 If there is an error, a number fewer than
95 may be returned, and the error may be retrieved using
100 The address of the target is given by
105 The length of the message is given by
107 If the message is too long to pass atomically through the
108 underlying protocol, the error
111 the message is not transmitted.
113 No indication of failure to deliver is implicit in a
115 Locally detected errors are indicated by a return value of \-1.
117 If no messages space is available at the socket to hold
118 the message to be transmitted, then
120 normally blocks, unless the socket has been placed in
121 non-blocking I/O mode.
126 call may be used to determine when it is possible to
128 Unfortunately this does not work when the interface queue which is used to
129 send the message is full, and the call returns
134 parameter may include one or more of the following:
136 #define MSG_OOB 0x0001 /* process out-of-band data */
137 #define MSG_PEEK 0x0002 /* peek at incoming message */
138 #define MSG_DONTROUTE 0x0004 /* bypass routing, use direct interface */
139 #define MSG_EOR 0x0008 /* data completes record */
140 #define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
147 data on sockets that support this notion (e.g.
149 the underlying protocol must also support
153 is used to indicate a record mark for protocols which support the
156 .\" requests that the sender side of a socket be shut down, and that an
157 .\" appropriate indication be sent at the end of the specified data;
158 .\" this flag is only implemented for
162 .\" protocol family, and is used to implement Transaction
167 is usually used only by diagnostic or routing programs.
171 for a description of the
177 generation when writing a socket that
185 calls return the number of characters sent, or \-1
186 if an error occurred.
189 call returns the number of messages sent, or \-1
200 The SO_BROADCAST option is not set on the socket, and a broadcast address
201 was given as the destination.
202 .It Bq Er EAFNOSUPPORT
203 Addresses in the specified address family cannot be used with this socket.
204 .It Bq Er EAGAIN|EWOULDBLOCK
205 The socket is marked non-blocking and the requested operation
208 An invalid descriptor was specified.
209 .It Bq Er EDSTADDRREQ
210 In a non-connected socket a destination address has not been specified.
212 An invalid user space address was specified for a parameter.
214 The destination is a host on the local subnet and does not respond to
216 .It Bq Er EHOSTUNREACH
217 The destination for the message is unreachable.
219 The total length of the I/O is more than can be expressed by the ssize_t
222 The socket requires that message be sent atomically,
223 and the size of the message to be sent made this impossible.
225 The system was unable to allocate an internal buffer.
226 The operation may succeed when buffers become available.
228 An alternative reason: the output queue for a network interface was full.
229 This generally indicates that the interface has stopped sending,
230 but may be caused by transient congestion.
236 In a connected socket the connection has been broken.
243 A destination address was specified and the socket is already connected.
256 structure is less than or equal to 0
270 function call appeared in
274 function call appeared in