nrelease - fix/improve livecd
[dragonfly.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 .\" 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.
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: src/lib/libc/sys/send.2,v 1.10.2.6 2001/12/14 18:34:01 ru Exp $
30 .\"
31 .Dd October 6, 2010
32 .Dt SEND 2
33 .Os
34 .Sh NAME
35 .Nm send ,
36 .Nm sendto ,
37 .Nm sendmsg
38 .Nd send a message from a socket
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In sys/types.h
43 .In sys/socket.h
44 .Ft ssize_t
45 .Fn send "int s" "const void *msgbuf" "size_t len" "int flags"
46 .Ft ssize_t
47 .Fn sendto "int s" "const void *msgbuf" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen"
48 .Ft ssize_t
49 .Fn sendmsg "int s" "const struct msghdr *msg" "int flags"
50 .Sh DESCRIPTION
51 .Fn Send ,
52 .Fn sendto ,
53 and
54 .Fn sendmsg
55 are used to transmit a message to another socket.
56 .Fn Send
57 may be used only when the socket is in a
58 .Em connected
59 state, while
60 .Fn sendto
61 and
62 .Fn sendmsg
63 may be used at any time.
64 .Pp
65 The socket file descriptor is given by
66 .Fa s .
67 .Fa msgbuf
68 points to a buffer containing the message.
69 .Fa msg
70 points to a
71 .Fa msghdr
72 structure.
73 The address of the target is given by
74 .Fa to
75 with
76 .Fa tolen
77 specifying its size.
78 The length of the message is given by
79 .Fa len .
80 If the message is too long to pass atomically through the
81 underlying protocol, the error
82 .Er EMSGSIZE
83 is returned, and
84 the message is not transmitted.
85 .Pp
86 No indication of failure to deliver is implicit in a
87 .Fn send .
88 Locally detected errors are indicated by a return value of -1.
89 .Pp
90 If no messages space is available at the socket to hold
91 the message to be transmitted, then
92 .Fn send
93 normally blocks, unless the socket has been placed in
94 non-blocking I/O mode.
95 The
96 .Xr select 2
97 call may be used to determine when it is possible to
98 send more data.
99 .Pp
100 The
101 .Fa flags
102 parameter may include one or more of the following:
103 .Bd -literal
104 #define MSG_OOB         0x1   /* process out-of-band data */
105 #define MSG_PEEK        0x2   /* peek at incoming message */
106 #define MSG_DONTROUTE   0x4   /* bypass routing, use direct interface */
107 #define MSG_EOR         0x8   /* data completes record */
108 #define MSG_EOF         0x100 /* data completes transaction */
109 #define MSG_NOSIGNAL    0x400 /* No SIGPIPE to unconnected socket stream */
110 .Ed
111 .Pp
112 The flag
113 .Dv MSG_OOB
114 is used to send
115 .Dq out-of-band
116 data on sockets that support this notion (e.g.\&
117 .Dv SOCK_STREAM ) ;
118 the underlying protocol must also support
119 .Dq out-of-band
120 data.
121 .Dv MSG_EOR
122 is used to indicate a record mark for protocols which support the
123 concept.
124 .Dv MSG_EOF
125 requests that the sender side of a socket be shut down, and that an
126 appropriate indication be sent at the end of the specified data;
127 this flag is only implemented for
128 .Dv SOCK_STREAM
129 sockets in the
130 .Dv PF_INET
131 protocol family.
132 .Dv MSG_DONTROUTE
133 is usually used only by diagnostic or routing programs.
134 .Dv MSG_NOSIGNAL
135 requests not to send the
136 .Dv SIGPIPE
137 signal if an attempt to
138 .Nm
139 is made on a stream-oriented socket that is no longer connected.
140 .Pp
141 See
142 .Xr recv 2
143 for a description of the
144 .Fa msghdr
145 structure.
146 .Sh RETURN VALUES
147 Upon successful completion the number of characters which were sent is
148 returned.  Otherwise -1 is returned and the global variable
149 .Va errno
150 is set to indicate the error.
151 .Sh ERRORS
152 .Fn Send ,
153 .Fn sendto ,
154 and
155 .Fn sendmsg
156 fail if:
157 .Bl -tag -width Er
158 .It Bq Er EBADF
159 An invalid descriptor was specified.
160 .It Bq Er EACCES
161 The destination address is a broadcast address, and
162 .Dv SO_BROADCAST
163 has not been set on the socket.
164 .It Bq Er ENOTSOCK
165 The argument
166 .Fa s
167 is not a socket.
168 .It Bq Er EFAULT
169 An invalid user space address was specified for a parameter.
170 .It Bq Er EMSGSIZE
171 The socket requires that message be sent atomically,
172 and the size of the message to be sent made this impossible.
173 .It Bq Er EAGAIN
174 The socket is marked non-blocking and the requested operation
175 would block.
176 .It Bq Er ENOBUFS
177 The system was unable to allocate an internal buffer.
178 The operation may succeed when buffers become available.
179 .It Bq Er ENOBUFS
180 The output queue for a network interface was full.
181 This generally indicates that the interface has stopped sending,
182 but may be caused by transient congestion.
183 .It Bq Er EHOSTUNREACH
184 The remote host was unreachable.
185 .It Bq Er ECONNREFUSED
186 The socket received an ICMP destination unreachable message
187 from the last message sent.  This typically means that the
188 receiver is not listening on the remote port.
189 .It Bq Er EHOSTDOWN
190 The remote host was down.
191 .It Bq Er EPIPE
192 The socket is unable to send any more data
193 .Dv ( SS_CANTSENDMORE
194 has been set on the socket). This typically means that the socket
195 is not connected.
196 .El
197 .Sh SEE ALSO
198 .Xr fcntl 2 ,
199 .Xr getsockopt 2 ,
200 .Xr recv 2 ,
201 .Xr select 2 ,
202 .Xr socket 2 ,
203 .Xr write 2
204 .Sh HISTORY
205 The
206 .Fn send
207 function call appeared in
208 .Bx 4.2 .
209 .Sh BUGS
210 Because
211 .Fn sendmsg
212 doesn't necessarily block until the data has been transferred, it
213 is possible to transfer an open file descriptor across an
214 .Dv AF_UNIX
215 domain socket
216 (see
217 .Xr recv 2 ) ,
218 then
219 .Fn close
220 it before it has actually been sent, the result being that the receiver
221 gets a closed file descriptor.  It is left to the application to
222 implement an acknowledgment mechanism to prevent this from happening.