1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
'\" te
.\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH send 3SOCKET "31 Aug 2009" "SunOS 5.11" "Sockets Library Functions"
.SH NAME
send, sendto, sendmsg \- send a message from a socket
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
#include <sys/types.h>
#include <sys/socket.h>
\fBssize_t\fR \fBsend\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR);
.fi
.LP
.nf
\fBssize_t\fR \fBsendto\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR,
\fBconst struct sockaddr *\fR\fIto\fR, \fBint\fR \fItolen\fR);
.fi
.LP
.nf
\fBssize_t\fR \fBsendmsg\fR(\fBint\fR \fIs\fR, \fBconst struct msghdr *\fR\fImsg\fR, \fBint\fR \fIflags\fR);
.fi
.SH DESCRIPTION
.sp
.LP
The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions are used to
transmit a message to another transport end-point. The \fBsend()\fR function
can be used only when the socket is in a connected state. See
\fBconnect\fR(3SOCKET). The \fBsendto()\fR and \fBsendmsg()\fR functions can be
used at any time. The \fIs\fR socket is created with \fBsocket\fR(3SOCKET).
.sp
.LP
The address of the target is supplied by \fIto\fR with a \fItolen\fR parameter
used to specify the size. The length of the message is supplied by the
\fIlen\fR parameter. For socket types such as \fBSOCK_DGRAM\fR and
\fBSOCK_RAW\fR that require atomic messages, the error \fBEMSGSIZE\fR is
returned and the message is not transmitted when it is too long to pass
atomically through the underlying protocol. The same restrictions do not apply
to \fBSOCK_STREAM\fR sockets.
.sp
.LP
A return value \fB\(mi1\fR indicates locally detected errors. It does not imply
a delivery failure.
.sp
.LP
If the socket does not have enough buffer space available to hold a message,
the \fBsend()\fR function blocks the message, unless the socket has been placed
in non-blocking I/O mode (see \fBfcntl\fR(2)). The \fBselect\fR(3C) or
\fBpoll\fR(2) call can be used to determine when it is possible to send more
data.
.sp
.LP
The \fIflags\fR parameter is formed from the bitwise OR of zero or more of the
following:
.sp
.ne 2
.mk
.na
\fB\fBMSG_OOB\fR\fR
.ad
.RS 17n
.rt
Send \fBout-of-band\fR data on sockets that support this notion. The underlying
protocol must also support \fBout-of-band\fR data. Only \fBSOCK_STREAM\fR
sockets created in the \fBAF_INET\fR or the \fBAF_INET6\fR address family
support out-of-band data.
.RE
.sp
.ne 2
.mk
.na
\fB\fBMSG_DONTROUTE\fR\fR
.ad
.RS 17n
.rt
The \fBSO_DONTROUTE\fR option is turned on for the duration of the operation.
It is used only by diagnostic or routing programs.
.RE
.sp
.LP
See \fBrecv\fR(3SOCKET) for a description of the \fBmsghdr\fR structure.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, these functions return the number of bytes sent.
Otherwise, they return \fB-1\fR and set \fBerrno\fR to indicate the error.
.SH ERRORS
.sp
.LP
The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions return errors
under the following conditions:
.sp
.ne 2
.mk
.na
\fB\fBEBADF\fR\fR
.ad
.RS 16n
.rt
\fIs\fR is not a valid file descriptor.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEINTR\fR\fR
.ad
.RS 16n
.rt
The operation was interrupted by delivery of a signal before any data could be
buffered to be sent.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEMSGSIZE\fR\fR
.ad
.RS 16n
.rt
The message is too large to be sent all at once (as the socket requires), or
the \fImsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by message
is less than or equal to 0 or is greater than {\fBIOV_MAX\fR}.
.RE
.sp
.ne 2
.mk
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 16n
.rt
Insufficient memory is available to complete the operation.
.RE
.sp
.ne 2
.mk
.na
\fB\fBENOSR\fR\fR
.ad
.RS 16n
.rt
Insufficient STREAMS resources are available for the operation to complete.
.RE
.sp
.ne 2
.mk
.na
\fB\fBENOTSOCK\fR\fR
.ad
.RS 16n
.rt
\fIs\fR is not a socket.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEWOULDBLOCK\fR\fR
.ad
.RS 16n
.rt
The socket is marked non-blocking and the requested operation would block.
\fBEWOULDBLOCK\fR is also returned when sufficient memory is not immediately
available to allocate a suitable buffer. In such a case, the operation can be
retried later.
.RE
.sp
.ne 2
.mk
.na
\fB\fBECONNREFUSED\fR\fR
.ad
.RS 16n
.rt
The requested connection was refused by the peer. For conected IPv4 and IPv6
datagram sockets, this indicates that the system received an \fBICMP
Destination Port Unreachable\fR message from the peer in response to some prior
transmission.
.RE
.sp
.LP
The \fBsend()\fR and \fBsendto()\fR functions return errors under the following
conditions:
.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt
The \fIlen\fR argument overflows a \fBssize_t\fR.
.sp
Inconsistent port attributes for system call.
.RE
.sp
.LP
The \fBsendto()\fR function returns errors under the following conditions:
.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt
The value specified for the \fItolen\fR parameter is not the size of a valid
address for the specified address family.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEISCON\fR\fR
.ad
.RS 10n
.rt
A destination address was specified and the socket is already connected.
.RE
.sp
.LP
The \fBsendmsg()\fR function returns errors under the following conditions:
.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt
The \fBmsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by
\fImsg\fR is less than or equal to \fB0\fR, or the sum of the \fIiov_len\fR
values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
.sp
One of the \fIiov_len\fR values in the \fBmsg_iov\fR array member of the
\fBmsghdr\fR structure pointed to by \fImsg\fR is negative, or the sum of the
\fIiov_len\fR values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
.sp
\fBmsg_iov\fR contents are inconsistent with port attributes.
.RE
.sp
.LP
The \fBsend()\fR function returns errors under the following conditions:
.sp
.ne 2
.mk
.na
\fB\fBEPIPE\fR\fR
.ad
.RS 9n
.rt
The socket is shut down for writing, or the socket is connection-mode and is no
longer connected. In the latter case, if the socket is of type
\fBSOCK_STREAM\fR, the \fBSIGPIPE\fR signal is generated to the calling thread.
.RE
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Interface StabilityCommitted
_
MT-LevelSafe
.TE
.SH SEE ALSO
.sp
.LP
\fBfcntl\fR(2), \fBpoll\fR(2), \fBwrite\fR(2), \fBconnect\fR(3SOCKET),
\fBgetsockopt\fR(3SOCKET), \fBrecv\fR(3SOCKET), \fBselect\fR(3C),
\fBsocket\fR(3SOCKET), \fBsocket.h\fR(3HEAD), \fBattributes\fR(5)
|