]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/send.2
Merge ACPICA 20160422.
[FreeBSD/FreeBSD.git] / lib / libc / sys / send.2
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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 .\" 4. 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.
15 .\"
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
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     From: @(#)send.2        8.2 (Berkeley) 2/21/94
29 .\" $FreeBSD$
30 .\"
31 .Dd January 29, 2016
32 .Dt SEND 2
33 .Os
34 .Sh NAME
35 .Nm send ,
36 .Nm sendto ,
37 .Nm sendmsg ,
38 .Nm sendmmsg
39 .Nd send message(s) from a socket
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In sys/types.h
44 .In sys/socket.h
45 .Ft ssize_t
46 .Fn send "int s" "const void *msg" "size_t len" "int flags"
47 .Ft ssize_t
48 .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen"
49 .Ft ssize_t
50 .Fn sendmsg "int s" "const struct msghdr *msg" "int flags"
51 .Ft ssize_t
52 .Fn sendmmsg "int s" "struct mmsghdr * restrict msgvec" "size_t vlen" "int flags"
53 .Sh DESCRIPTION
54 The
55 .Fn send
56 and
57 .Fn sendmmsg
58 functions,
59 and
60 .Fn sendto
61 and
62 .Fn sendmsg
63 system calls
64 are used to transmit one or more messages (with the
65 .Fn sendmmsg
66 call) to
67 another socket.
68 The
69 .Fn send
70 function
71 may be used only when the socket is in a
72 .Em connected
73 state, while
74 .Fn sendto ,
75 .Fn sendmsg
76 and
77 .Fn sendmmsg
78 may be used at any time.
79 .Pp
80 The address of the target is given by
81 .Fa to
82 with
83 .Fa tolen
84 specifying its size.
85 The length of the message is given by
86 .Fa len .
87 If the message is too long to pass atomically through the
88 underlying protocol, the error
89 .Er EMSGSIZE
90 is returned, and
91 the message is not transmitted.
92 .Pp
93 The
94 .Fn sendmmsg
95 function sends multiple messages at a call.
96 They are given by the
97 .Fa msgvec
98 vector along with
99 .Fa vlen
100 specifying the vector size.
101 The number of octets sent per each message is placed in the
102 .Fa msg_len
103 field of each processed element of the vector after transmission.
104 .Pp
105 No indication of failure to deliver is implicit in a
106 .Fn send .
107 Locally detected errors are indicated by a return value of -1.
108 .Pp
109 If no messages space is available at the socket to hold
110 the message to be transmitted, then
111 .Fn send
112 normally blocks, unless the socket has been placed in
113 non-blocking I/O mode.
114 The
115 .Xr select 2
116 system call may be used to determine when it is possible to
117 send more data.
118 .Pp
119 The
120 .Fa flags
121 argument may include one or more of the following:
122 .Bd -literal
123 #define MSG_OOB         0x00001 /* process out-of-band data */
124 #define MSG_DONTROUTE   0x00004 /* bypass routing, use direct interface */
125 #define MSG_EOR         0x00008 /* data completes record */
126 #define MSG_EOF         0x00100 /* data completes transaction */
127 #define MSG_NOSIGNAL    0x20000 /* do not generate SIGPIPE on EOF */
128 .Ed
129 .Pp
130 The flag
131 .Dv MSG_OOB
132 is used to send
133 .Dq out-of-band
134 data on sockets that support this notion (e.g.\&
135 .Dv SOCK_STREAM ) ;
136 the underlying protocol must also support
137 .Dq out-of-band
138 data.
139 .Dv MSG_EOR
140 is used to indicate a record mark for protocols which support the
141 concept.
142 .Dv MSG_EOF
143 requests that the sender side of a socket be shut down, and that an
144 appropriate indication be sent at the end of the specified data;
145 this flag is only implemented for
146 .Dv SOCK_STREAM
147 sockets in the
148 .Dv PF_INET
149 protocol family.
150 .Dv MSG_DONTROUTE
151 is usually used only by diagnostic or routing programs.
152 .Dv MSG_NOSIGNAL
153 is used to prevent
154 .Dv SIGPIPE
155 generation when writing a socket that
156 may be closed.
157 .Pp
158 See
159 .Xr recv 2
160 for a description of the
161 .Fa msghdr
162 structure and the
163 .Fa mmsghdr
164 structure.
165 .Sh RETURN VALUES
166 The
167 .Fn send ,
168 .Fn sendto
169 and
170 .Fn sendmsg
171 calls
172 return the number of octets sent.
173 The
174 .Fn sendmmsg
175 call returns the number of messages sent.
176 If an error occurred a value of -1 is returned.
177 .Sh ERRORS
178 The
179 .Fn send
180 and
181 .Fn sendmmsg
182 functions and
183 .Fn sendto
184 and
185 .Fn sendmsg
186 system calls
187 fail if:
188 .Bl -tag -width Er
189 .It Bq Er EBADF
190 An invalid descriptor was specified.
191 .It Bq Er EACCES
192 The destination address is a broadcast address, and
193 .Dv SO_BROADCAST
194 has not been set on the socket.
195 .It Bq Er ENOTSOCK
196 The argument
197 .Fa s
198 is not a socket.
199 .It Bq Er EFAULT
200 An invalid user space address was specified for an argument.
201 .It Bq Er EMSGSIZE
202 The socket requires that message be sent atomically,
203 and the size of the message to be sent made this impossible.
204 .It Bq Er EAGAIN
205 The socket is marked non-blocking and the requested operation
206 would block.
207 .It Bq Er ENOBUFS
208 The system was unable to allocate an internal buffer.
209 The operation may succeed when buffers become available.
210 .It Bq Er ENOBUFS
211 The output queue for a network interface was full.
212 This generally indicates that the interface has stopped sending,
213 but may be caused by transient congestion.
214 .It Bq Er EHOSTUNREACH
215 The remote host was unreachable.
216 .It Bq Er EISCONN
217 A destination address was specified and the socket is already connected.
218 .It Bq Er ECONNREFUSED
219 The socket received an ICMP destination unreachable message
220 from the last message sent.
221 This typically means that the
222 receiver is not listening on the remote port.
223 .It Bq Er EHOSTDOWN
224 The remote host was down.
225 .It Bq Er ENETDOWN
226 The remote network was down.
227 .It Bq Er EADDRNOTAVAIL
228 The process using a
229 .Dv SOCK_RAW
230 socket was jailed and the source
231 address specified in the IP header did not match the IP
232 address bound to the prison.
233 .It Bq Er EPIPE
234 The socket is unable to send anymore data
235 .Dv ( SBS_CANTSENDMORE
236 has been set on the socket).
237 This typically means that the socket
238 is not connected.
239 .El
240 .Sh SEE ALSO
241 .Xr fcntl 2 ,
242 .Xr getsockopt 2 ,
243 .Xr recv 2 ,
244 .Xr select 2 ,
245 .Xr socket 2 ,
246 .Xr write 2
247 .Sh HISTORY
248 The
249 .Fn send
250 function appeared in
251 .Bx 4.2 .
252 The
253 .Fn sendmmsg
254 function appeared in
255 .Fx 11.0 .
256 .Sh BUGS
257 Because
258 .Fn sendmsg
259 does not necessarily block until the data has been transferred, it
260 is possible to transfer an open file descriptor across an
261 .Dv AF_UNIX
262 domain socket
263 (see
264 .Xr recv 2 ) ,
265 then
266 .Fn close
267 it before it has actually been sent, the result being that the receiver
268 gets a closed file descriptor.
269 It is left to the application to
270 implement an acknowledgment mechanism to prevent this from happening.