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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group. In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" 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]
.\"
.\"
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\"
.TH SENDMSG 3XNET "Nov 1, 2003"
.SH NAME
sendmsg \- send a message on a socket using a message structure
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
#include <sys/socket.h>
\fBssize_t\fR \fBsendmsg\fR(\fBint\fR \fIsocket\fR, \fBconst struct msghdr *\fR\fImessage\fR, \fBint\fR \fIflags\fR);
.fi
.SH PARAMETERS
.sp
.LP
The function takes the following arguments:
.sp
.ne 2
.na
\fB\fIsocket\fR\fR
.ad
.RS 11n
Specifies the socket file descriptor.
.RE
.sp
.ne 2
.na
\fB\fImessage\fR\fR
.ad
.RS 11n
Points to a \fBmsghdr\fR structure, containing both the destination address and
the buffers for the outgoing message. The length and format of the address
depend on the address family of the socket. The \fBmsg_flags\fR member is
ignored.
.RE
.sp
.ne 2
.na
\fB\fIflags\fR\fR
.ad
.RS 11n
Specifies the type of message transmission. The application may specify 0 or
the following flag:
.sp
.ne 2
.na
\fBMSG_EOR\fR
.ad
.RS 11n
Terminates a record (if supported by the protocol)
.RE
.sp
.ne 2
.na
\fBMSG_OOB\fR
.ad
.RS 11n
Sends out-of-band data on sockets that support out-of-bound data. The
significance and semantics of out-of-band data are protocol-specific.
.RE
.RE
.SH DESCRIPTION
.sp
.LP
The \fBsendmsg()\fR function sends a message through a connection-mode or
connectionless-mode socket. If the socket is connectionless-mode, the message
will be sent to the address specified by \fImsghdr\fR. If the socket is
connection-mode, the destination address in \fImsghdr\fR is ignored.
.sp
.LP
The \fImsg_iov\fR and \fImsg_iovlen\fR fields of message specify zero or more
buffers containing the data to be sent. \fImsg_iov\fR points to an array of
\fBiovec\fR structures; \fImsg_iovlen\fR must be set to the dimension of this
array. In each \fBiovec\fR structure, the \fIiov_base\fR field specifies a
storage area and the \fIiov_len\fR field gives its size in bytes. Some of
these sizes can be zero. The data from each storage area indicated by
\fImsg_iov\fR is sent in turn.
.sp
.LP
Successful completion of a call to \fBsendmsg()\fR does not guarantee delivery
of the message. A return value of \(mi1 indicates only locally-detected errors.
.sp
.LP
If space is not available at the sending socket to hold the message to be
transmitted and the socket file descriptor does not have \fBO_NONBLOCK\fR set,
\fBsendmsg()\fR function blocks until space is available. If space is not
available at the sending socket to hold the message to be transmitted and the
socket file descriptor does have \fBO_NONBLOCK\fR set, \fBsendmsg()\fR function
will fail.
.sp
.LP
If the socket protocol supports broadcast and the specified address is a
broadcast address for the socket protocol, \fBsendmsg()\fR will fail if the
\fBSO_BROADCAST\fR option is not set for the socket.
.sp
.LP
The socket in use may require the process to have appropriate privileges to use
the \fBsendmsg()\fR function.
.SH USAGE
.sp
.LP
The \fBselect\fR(3C) and \fBpoll\fR(2) functions can be used to determine when
it is possible to send more data.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBsendmsg()\fR function returns the number of
bytes sent. Otherwise, \(mi1 is returned and \fBerrno\fR is set to indicate
the error.
.SH ERRORS
.sp
.LP
The \fBsendmsg()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEAGAIN\fR \fR
.ad
.br
.na
\fB\fBEWOULDBLOCK\fR\fR
.ad
.RS 16n
The socket's file descriptor is marked O_NONBLOCK and the requested operation
would block.
.RE
.sp
.ne 2
.na
\fB\fBEAFNOSUPPORT\fR\fR
.ad
.RS 16n
Addresses in the specified address family cannot be used with this socket.
.RE
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 16n
The \fIsocket\fR argument is not a valid file descriptor.
.RE
.sp
.ne 2
.na
\fB\fBECONNRESET\fR\fR
.ad
.RS 16n
A connection was forcibly closed by a peer.
.RE
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 16n
The \fImessage\fR parameter, or storage pointed to by the \fImsg_name\fR,
\fImsg_control\fR or \fImsg_iov\fR fields of the \fImessage\fR parameter, or
storage pointed to by the \fBiovec\fR structures pointed to by the
\fImsg_iov\fR field can not be accessed.
.RE
.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 16n
A signal interrupted \fBsendmsg()\fR before any data was transmitted.
.RE
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 16n
The sum of the \fBiov_len\fR values overflows an \fBssize_t\fR.
.RE
.sp
.ne 2
.na
\fB\fBEMSGSIZE\fR\fR
.ad
.RS 16n
The message is to large to be sent all at once (as the socket requires), or the
\fBmsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by
\fImessage\fR is less than or equal to 0 or is greater than \fBIOV_MAX\fR.
.RE
.sp
.ne 2
.na
\fB\fBENOTCONN\fR\fR
.ad
.RS 16n
The socket is connection-mode but is not connected.
.RE
.sp
.ne 2
.na
\fB\fBENOTSOCK\fR\fR
.ad
.RS 16n
The \fIsocket\fR argument does not refer a socket.
.RE
.sp
.ne 2
.na
\fB\fBEOPNOTSUPP\fR\fR
.ad
.RS 16n
The \fIsocket\fR argument is associated with a socket that does not support one
or more of the values set in \fIflags\fR.
.RE
.sp
.ne 2
.na
\fB\fBEPIPE\fR\fR
.ad
.RS 16n
The socket is shut down for writing, or the socket is connection-mode and is no
longer connected. In the latter case, and if the socket is of type SOCK_STREAM,
the \fBSIGPIPE\fR signal is generated to the calling thread.
.RE
.sp
.LP
If the address family of the socket is \fBAF_UNIX\fR, then \fBsendmsg()\fR will
fail if:
.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 16n
An I/O error occurred while reading from or writing to the file system.
.RE
.sp
.ne 2
.na
\fB\fBELOOP\fR\fR
.ad
.RS 16n
Too many symbolic links were encountered in translating the pathname in the
socket address.
.RE
.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
pathname exceeded \fIPATH_MAX\fR characters.
.RE
.sp
.ne 2
.na
\fB\fBENOENT\fR\fR
.ad
.RS 16n
A component of the pathname does not name an existing file or the pathname is
an empty string.
.RE
.sp
.ne 2
.na
\fB\fBENOTDIR\fR\fR
.ad
.RS 16n
A component of the path prefix of the pathname in the socket address is not a
directory.
.RE
.sp
.LP
The \fBsendmsg()\fR function may fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 16n
Search permission is denied for a component of the path prefix; or write access
to the named socket is denied.
.RE
.sp
.ne 2
.na
\fB\fBEDESTADDRREQ\fR\fR
.ad
.RS 16n
The socket is not connection-mode and does not have its peer address set, and
no destination address was specified.
.RE
.sp
.ne 2
.na
\fB\fBEHOSTUNREACH\fR\fR
.ad
.RS 16n
The destination host cannot be reached (probably because the host is down or a
remote router cannot reach it).
.RE
.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 16n
An I/O error occurred while reading from or writing to the file system.
.RE
.sp
.ne 2
.na
\fB\fBEISCONN\fR\fR
.ad
.RS 16n
A destination address was specified and the socket is already connected.
.RE
.sp
.ne 2
.na
\fB\fBENETDOWN\fR\fR
.ad
.RS 16n
The local interface used to reach the destination is down.
.RE
.sp
.ne 2
.na
\fB\fBENETUNREACH\fR\fR
.ad
.RS 16n
No route to the network is present.
.RE
.sp
.ne 2
.na
\fB\fBENOBUFS\fR\fR
.ad
.RS 16n
Insufficient resources were available in the system to perform the operation.
.RE
.sp
.ne 2
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 16n
Insufficient memory was available to fulfill the request.
.RE
.sp
.ne 2
.na
\fB\fBENOSR\fR\fR
.ad
.RS 16n
There were insufficient STREAMS resources available for the operation to
complete.
.RE
.sp
.LP
If the address family of the socket is \fBAF_UNIX\fR, then \fBsendmsg()\fR may
fail if:
.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
Pathname resolution of a symbolic link produced an intermediate result whose
length exceeds \fIPATH_MAX\fR.
.RE
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
Interface Stability Standard
_
MT-Level MT-Safe
.TE
.SH SEE ALSO
.sp
.LP
\fBpoll\fR(2) \fBgetsockopt\fR(3XNET), \fBrecv\fR(3XNET),
\fBrecvfrom\fR(3XNET), \fBrecvmsg\fR(3XNET), \fBselect\fR(3C),
\fBsend\fR(3XNET), \fBsendto\fR(3XNET), \fBsetsockopt\fR(3XNET),
\fBshutdown\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),
\fBstandards\fR(5)
|