1SENDTO(P) POSIX Programmer's Manual SENDTO(P)
2
3
4
6 sendto - send a message on a socket
7
9 #include <sys/socket.h>
10
11 ssize_t sendto(int socket, const void *message, size_t length,
12 int flags, const struct sockaddr *dest_addr,
13 socklen_t dest_len);
14
15
17 The sendto() function shall send a message through a connection-mode or
18 connectionless-mode socket. If the socket is connectionless-mode, the
19 message shall be sent to the address specified by dest_addr. If the
20 socket is connection-mode, dest_addr shall be ignored.
21
22 The sendto() function takes the following arguments:
23
24 socket Specifies the socket file descriptor.
25
26 message
27 Points to a buffer containing the message to be sent.
28
29 length Specifies the size of the message in bytes.
30
31 flags Specifies the type of message transmission. Values of this argu‐
32 ment are formed by logically OR'ing zero or more of the follow‐
33 ing flags:
34
35 MSG_EOR
36 Terminates a record (if supported by the protocol).
37
38 MSG_OOB
39 Sends out-of-band data on sockets that support out-of-band data.
40 The significance and semantics of out-of-band data are protocol-
41 specific.
42
43
44 dest_addr
45 Points to a sockaddr structure containing the destination
46 address. The length and format of the address depend on the
47 address family of the socket.
48
49 dest_len
50 Specifies the length of the sockaddr structure pointed to by the
51 dest_addr argument.
52
53
54 If the socket protocol supports broadcast and the specified address is
55 a broadcast address for the socket protocol, sendto() shall fail if the
56 SO_BROADCAST option is not set for the socket.
57
58 The dest_addr argument specifies the address of the target. The length
59 argument specifies the length of the message.
60
61 Successful completion of a call to sendto() does not guarantee delivery
62 of the message. A return value of -1 indicates only locally-detected
63 errors.
64
65 If space is not available at the sending socket to hold the message to
66 be transmitted and the socket file descriptor does not have O_NONBLOCK
67 set, sendto() shall block until space is available. If space is not
68 available at the sending socket to hold the message to be transmitted
69 and the socket file descriptor does have O_NONBLOCK set, sendto() shall
70 fail.
71
72 The socket in use may require the process to have appropriate privi‐
73 leges to use the sendto() function.
74
76 Upon successful completion, sendto() shall return the number of bytes
77 sent. Otherwise, -1 shall be returned and errno set to indicate the
78 error.
79
81 The sendto() function shall fail if:
82
83 EAFNOSUPPORT
84 Addresses in the specified address family cannot be used with
85 this socket.
86
87 EAGAIN or EWOULDBLOCK
88 The socket's file descriptor is marked O_NONBLOCK and the
89 requested operation would block.
90
91 EBADF The socket argument is not a valid file descriptor.
92
93 ECONNRESET
94 A connection was forcibly closed by a peer.
95
96 EINTR A signal interrupted sendto() before any data was transmitted.
97
98 EMSGSIZE
99 The message is too large to be sent all at once, as the socket
100 requires.
101
102 ENOTCONN
103 The socket is connection-mode but is not connected.
104
105 ENOTSOCK
106 The socket argument does not refer to a socket.
107
108 EOPNOTSUPP
109 The socket argument is associated with a socket that does not
110 support one or more of the values set in flags.
111
112 EPIPE The socket is shut down for writing, or the socket is connec‐
113 tion-mode and is no longer connected. In the latter case, and if
114 the socket is of type SOCK_STREAM, the SIGPIPE signal is gener‐
115 ated to the calling thread.
116
117
118 If the address family of the socket is AF_UNIX, then sendto() shall
119 fail if:
120
121 EIO An I/O error occurred while reading from or writing to the file
122 system.
123
124 ELOOP A loop exists in symbolic links encountered during resolution of
125 the pathname in the socket address.
126
127 ENAMETOOLONG
128 A component of a pathname exceeded {NAME_MAX} characters, or an
129 entire pathname exceeded {PATH_MAX} characters.
130
131 ENOENT A component of the pathname does not name an existing file or
132 the pathname is an empty string.
133
134 ENOTDIR
135 A component of the path prefix of the pathname in the socket
136 address is not a directory.
137
138
139 The sendto() function may fail if:
140
141 EACCES Search permission is denied for a component of the path prefix;
142 or write access to the named socket is denied.
143
144 EDESTADDRREQ
145 The socket is not connection-mode and does not have its peer
146 address set, and no destination address was specified.
147
148 EHOSTUNREACH
149 The destination host cannot be reached (probably because the
150 host is down or a remote router cannot reach it).
151
152 EINVAL The dest_len argument is not a valid length for the address fam‐
153 ily.
154
155 EIO An I/O error occurred while reading from or writing to the file
156 system.
157
158 EISCONN
159 A destination address was specified and the socket is already
160 connected. This error may or may not be returned for connection
161 mode sockets.
162
163 ENETDOWN
164 The local network interface used to reach the destination is
165 down.
166
167 ENETUNREACH
168 No route to the network is present.
169
170 ENOBUFS
171 Insufficient resources were available in the system to perform
172 the operation.
173
174 ENOMEM Insufficient memory was available to fulfill the request.
175
176
177 If the address family of the socket is AF_UNIX, then sendto() may fail
178 if:
179
180 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
181 resolution of the pathname in the socket address.
182
183 ENAMETOOLONG
184 Pathname resolution of a symbolic link produced an intermediate
185 result whose length exceeds {PATH_MAX}.
186
187
188 The following sections are informative.
189
191 None.
192
194 The select() and poll() functions can be used to determine when it is
195 possible to send more data.
196
198 None.
199
201 None.
202
204 getsockopt() , poll() , recv() , recvfrom() , recvmsg() , select() ,
205 send() , sendmsg() , setsockopt() , shutdown() , socket() , the Base
206 Definitions volume of IEEE Std 1003.1-2001, <sys/socket.h>
207
209 Portions of this text are reprinted and reproduced in electronic form
210 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
211 -- Portable Operating System Interface (POSIX), The Open Group Base
212 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
213 Electrical and Electronics Engineers, Inc and The Open Group. In the
214 event of any discrepancy between this version and the original IEEE and
215 The Open Group Standard, the original IEEE and The Open Group Standard
216 is the referee document. The original Standard can be obtained online
217 at http://www.opengroup.org/unix/online.html .
218
219
220
221IEEE/The Open Group 2003 SENDTO(P)