5331 want sockaddr(3SOCKET)
[illumos-gate.git] / usr / src / man / man3xnet / sendto.3xnet
bloba3e6bc81f5a5ed4d6b29a24eee0ebe30c0ccf103
1 '\" te
2 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.  Portions Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" 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
4 .\" http://www.opengroup.org/bookstore/.
5 .\" 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 Sun OS 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.
6 .\"  This notice shall appear on any product containing this material.
7 .\" 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.
8 .\" 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.
9 .\" 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]
10 .TH SENDTO 3XNET "Nov 1, 2003"
11 .SH NAME
12 sendto \- send a message on a socket
13 .SH SYNOPSIS
14 .LP
15 .nf
16 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lxnet\fR [ \fIlibrary\fR ... ]
17 #include <sys/socket.h>
19 \fBssize_t\fR \fBsendto\fR(\fBint\fR \fIsocket\fR, \fBconst void *\fR\fImessage\fR, \fBsize_t\fR \fIlength\fR, \fBint\fR \fIflags\fR,
20      \fBconst struct sockaddr *\fR\fIdest_addr\fR, \fBsocklen_t\fR \fIdest_len\fR);
21 .fi
23 .SH DESCRIPTION
24 .LP
25 The \fBsendto()\fR function sends a message through a connection-mode or
26 connectionless-mode socket.  If the socket is connectionless-mode, the message
27 will be sent to the address specified by \fIdest_addr\fR.  If the socket is
28 connection-mode, \fIdest_addr\fR is ignored.
29 .sp
30 .LP
31 If the socket protocol supports broadcast and the specified address is a
32 broadcast address for the socket protocol, \fBsendto()\fR will fail if the
33 \fBSO_BROADCAST\fR option is not set for the socket.
34 .sp
35 .LP
36 The \fIdest_addr\fR argument specifies the address of the target. The
37 \fIlength\fR argument specifies the length of the message.
38 .sp
39 .LP
40 Successful completion of a call to \fBsendto()\fR does not guarantee delivery
41 of the message. A return value of \fB\(mi1\fR indicates only locally-detected
42 errors.
43 .sp
44 .LP
45 If space is not available at the sending socket to hold the message to be
46 transmitted and the socket file descriptor does not have \fBO_NONBLOCK\fR set,
47 \fBsendto()\fR blocks until space is available. If space is not available at
48 the sending socket to hold the message to be transmitted and the socket file
49 descriptor does have \fBO_NONBLOCK\fR set, \fBsendto()\fR will fail.
50 .sp
51 .LP
52 The socket in use may require the process to have appropriate privileges to use
53 the \fBsendto()\fR function.
54 .SH PARAMETERS
55 .LP
56 The function takes the following arguments:
57 .sp
58 .ne 2
59 .na
60 \fB\fIsocket\fR\fR
61 .ad
62 .RS 13n
63 Specifies the socket file descriptor.
64 .RE
66 .sp
67 .ne 2
68 .na
69 \fB\fImessage\fR\fR
70 .ad
71 .RS 13n
72 Points to a buffer containing the message to be sent.
73 .RE
75 .sp
76 .ne 2
77 .na
78 \fB\fIlength\fR\fR
79 .ad
80 .RS 13n
81 Specifies the size of the message in bytes.
82 .RE
84 .sp
85 .ne 2
86 .na
87 \fB\fIflags\fR\fR
88 .ad
89 .RS 13n
90 Specifies the type of message transmission. Values of this argument are formed
91 by logically OR'ing zero or more of the following flags:
92 .sp
93 .ne 2
94 .na
95 \fBMSG_EOR\fR
96 .ad
97 .RS 11n
98 Terminates a record (if supported by the protocol)
99 .RE
102 .ne 2
104 \fBMSG_OOB\fR
106 .RS 11n
107 Sends out-of-band data on sockets that support out-of-band data. The
108 significance and semantics of out-of-band data are protocol-specific.
114 .ne 2
116 \fB\fIdest_addr\fR\fR
118 .RS 13n
119 Points to a \fBsockaddr\fR structure containing the destination address.  The
120 length and format of the address depend on the address family of the socket.
124 .ne 2
126 \fB\fIdest_len\fR\fR
128 .RS 13n
129 Specifies the length of the \fBsockaddr\fR structure pointed to by the
130 \fIdest_addr\fR argument.
133 .SH USAGE
135 The \fBselect\fR(3C) and \fBpoll\fR(2) functions can be used to determine when
136 it is possible to send more data.
137 .SH RETURN VALUES
139 Upon successful completion, \fBsendto()\fR returns the number of bytes sent.
140 Otherwise, \fB-1\fR is returned and \fBerrno\fR is set to indicate the error.
141 .SH ERRORS
143 The \fBsendto()\fR function will fail if:
145 .ne 2
147 \fB\fBEAFNOSUPPORT\fR\fR
149 .RS 16n
150 Addresses in the specified address family cannot be used with this socket.
154 .ne 2
156 \fB\fBEAGAIN\fR\fR
160 \fB\fBEWOULDBLOCK\fR\fR
162 .RS 16n
163 The socket's file descriptor is marked \fBO_NONBLOCK\fR and the requested
164 operation would block.
168 .ne 2
170 \fB\fBEBADF\fR\fR
172 .RS 16n
173 The \fIsocket\fR argument is not a valid file descriptor.
177 .ne 2
179 \fB\fBECONNRESET\fR\fR
181 .RS 16n
182 A connection was forcibly closed by a peer.
186 .ne 2
188 \fB\fBEFAULT\fR\fR
190 .RS 16n
191 The  \fImessage\fR or  \fIdestaddr\fR parameter cannot be accessed.
195 .ne 2
197 \fB\fBEINTR\fR\fR
199 .RS 16n
200 A signal interrupted \fBsendto()\fR before any data was transmitted.
204 .ne 2
206 \fB\fBEMSGSIZE\fR\fR
208 .RS 16n
209 The message is too large to be sent all at once, as the socket requires.
213 .ne 2
215 \fB\fBENOTCONN\fR\fR
217 .RS 16n
218 The socket is connection-mode but is not connected.
222 .ne 2
224 \fB\fBENOTSOCK\fR\fR
226 .RS 16n
227 The \fIsocket\fR argument does not refer to a socket.
231 .ne 2
233 \fB\fBEOPNOTSUPP\fR\fR
235 .RS 16n
236 The \fIsocket\fR argument is associated with a socket that does not support one
237 or more of the values set in \fIflags\fR.
241 .ne 2
243 \fB\fBEPIPE\fR\fR
245 .RS 16n
246 The socket is shut down for writing, or the socket is connection-mode and is no
247 longer connected. In the latter case, and if the socket is of type
248 \fBSOCK_STREAM\fR, the \fBSIGPIPE\fR signal is generated to the calling thread.
253 If the address family of the socket is \fBAF_UNIX\fR, then \fBsendto()\fR will
254 fail if:
256 .ne 2
258 \fB\fBEIO\fR\fR
260 .RS 16n
261 An I/O error occurred while reading from or writing to the file system.
265 .ne 2
267 \fB\fBELOOP\fR\fR
269 .RS 16n
270 Too many symbolic links were encountered in translating the pathname in the
271 socket address.
275 .ne 2
277 \fB\fBENAMETOOLONG\fR\fR
279 .RS 16n
280 A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
281 pathname exceeded \fIPATH_MAX\fR characters.
285 .ne 2
287 \fB\fBENOENT\fR\fR
289 .RS 16n
290 A component of the pathname does not name an existing file or the pathname is
291 an empty string.
295 .ne 2
297 \fB\fBENOTDIR\fR\fR
299 .RS 16n
300 A component of the path prefix of the pathname in the socket address is not a
301 directory.
306 The \fBsendto()\fR function may fail if:
308 .ne 2
310 \fB\fBEACCES\fR\fR
312 .RS 16n
313 Search permission is denied for a component of the path prefix; or write access
314 to the named socket is denied.
318 .ne 2
320 \fB\fBEDESTADDRREQ\fR\fR
322 .RS 16n
323 The socket is not connection-mode and does not have its peer address set, and
324 no destination address was specified.
328 .ne 2
330 \fB\fBEHOSTUNREACH\fR\fR
332 .RS 16n
333 The destination host cannot be reached (probably because the host is down or a
334 remote router cannot reach it).
338 .ne 2
340 \fB\fBEINVAL\fR\fR
342 .RS 16n
343 The \fIdest_len\fR argument is not a valid length for the address family.
347 .ne 2
349 \fB\fBEIO\fR\fR
351 .RS 16n
352 An I/O error occurred while reading from or writing to the file system.
356 .ne 2
358 \fB\fBEISCONN\fR\fR
360 .RS 16n
361 A destination address was specified and the socket is already connected.
365 .ne 2
367 \fB\fBENETDOWN\fR\fR
369 .RS 16n
370 The local interface used to reach the destination is down.
374 .ne 2
376 \fB\fBENETUNREACH\fR\fR
378 .RS 16n
379 No route to the network is present.
383 .ne 2
385 \fB\fBENOBUFS\fR\fR
387 .RS 16n
388 Insufficient resources were available in the system to perform the operation.
392 .ne 2
394 \fB\fBENOMEM\fR\fR
396 .RS 16n
397 Insufficient memory was available to fulfill the request.
401 .ne 2
403 \fB\fBENOSR\fR\fR
405 .RS 16n
406 There were insufficient STREAMS resources available for the operation to
407 complete.
412 If the address family of the socket is \fBAF_UNIX\fR, then \fBsendto()\fR may
413 fail if:
415 .ne 2
417 \fB\fBENAMETOOLONG\fR\fR
419 .RS 16n
420 Pathname resolution of a symbolic link produced an intermediate result whose
421 length exceeds \fIPATH_MAX\fR.
424 .SH ATTRIBUTES
426 See \fBattributes\fR(5) for descriptions of the following attributes:
431 box;
432 c | c
433 l | l .
434 ATTRIBUTE TYPE  ATTRIBUTE VALUE
436 Interface Stability     Standard
438 MT-Level        MT-Safe
441 .SH SEE ALSO
443 \fBpoll\fR(2), \fBsockaddr\fR(3SOCKET),
444 \fBgetsockopt\fR(3XNET), \fBrecv\fR(3XNET),
445 \fBrecvfrom\fR(3XNET), \fBrecvmsg\fR(3XNET), \fBselect\fR(3C),
446 \fBsend\fR(3XNET), \fBsendmsg\fR(3XNET), \fBsetsockopt\fR(3XNET),
447 \fBshutdown\fR(3XNET), \fBsocket\fR(3XNET), \fBattributes\fR(5),
448 \fBstandards\fR(5)