1SENDTO(3P)                 POSIX Programmer's Manual                SENDTO(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       sendto — send a message on a socket
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       ssize_t sendto(int socket, const void *message, size_t length,
19           int flags, const struct sockaddr *dest_addr,
20           socklen_t dest_len);
21

DESCRIPTION

23       The sendto() function shall send a message through a connection-mode or
24       connectionless-mode socket.
25
26       If  the  socket  is  a connectionless-mode socket, the message shall be
27       sent to the address specified by dest_addr  if  no  pre-specified  peer
28       address  has been set. If a peer address has been pre-specified, either
29       the message shall be sent to the address specified by dest_addr  (over‐
30       riding the pre-specified peer address), or the function shall return −1
31       and set errno to [EISCONN].
32
33       If the socket is connection-mode, dest_addr shall be ignored.
34
35       The sendto() function takes the following arguments:
36
37       socket      Specifies the socket file descriptor.
38
39       message     Points to a buffer containing the message to be sent.
40
41       length      Specifies the size of the message in bytes.
42
43       flags       Specifies the type of message transmission. Values of  this
44                   argument are formed by logically OR'ing zero or more of the
45                   following flags:
46
47                   MSG_EOR       Terminates a record (if supported by the pro‐
48                                 tocol).
49
50                   MSG_OOB       Sends  out-of-band  data on sockets that sup‐
51                                 port out-of-band data. The  significance  and
52                                 semantics  of  out-of-band data are protocol-
53                                 specific.
54
55                   MSG_NOSIGNAL  Requests not to send the SIGPIPE signal if an
56                                 attempt  to send is made on a stream-oriented
57                                 socket  that  is  no  longer  connected.  The
58                                 [EPIPE] error shall still be returned.
59
60       dest_addr   Points  to  a sockaddr structure containing the destination
61                   address. The length and format of the address depend on the
62                   address family of the socket.
63
64       dest_len    Specifies  the  length of the sockaddr structure pointed to
65                   by the dest_addr argument.
66
67       If the socket protocol supports broadcast and the specified address  is
68       a broadcast address for the socket protocol, sendto() shall fail if the
69       SO_BROADCAST option is not set for the socket.
70
71       The dest_addr argument specifies the address of the target.
72
73       The length argument specifies the length of the message.
74
75       Successful completion of a call to sendto() does not guarantee delivery
76       of  the  message.  A return value of −1 indicates only locally-detected
77       errors.
78
79       If space is not available at the sending socket to hold the message  to
80       be  transmitted and the socket file descriptor does not have O_NONBLOCK
81       set, sendto() shall block until space is available.  If  space  is  not
82       available  at  the sending socket to hold the message to be transmitted
83       and the socket file descriptor does have O_NONBLOCK set, sendto() shall
84       fail.
85
86       The  socket  in  use may require the process to have appropriate privi‐
87       leges to use the sendto() function.
88

RETURN VALUE

90       Upon successful completion, sendto() shall return the number  of  bytes
91       sent.  Otherwise,  −1  shall  be returned and errno set to indicate the
92       error.
93

ERRORS

95       The sendto() function shall fail if:
96
97       EAFNOSUPPORT
98              Addresses in the specified address family cannot  be  used  with
99              this socket.
100
101       EAGAIN or EWOULDBLOCK
102              The  socket's  file  descriptor  is  marked  O_NONBLOCK  and the
103              requested operation would block.
104
105       EBADF  The socket argument is not a valid file descriptor.
106
107       ECONNRESET
108              A connection was forcibly closed by a peer.
109
110       EINTR  A signal interrupted sendto() before any data was transmitted.
111
112       EMSGSIZE
113              The message is too large to be sent all at once, as  the  socket
114              requires.
115
116       ENOTCONN
117              The socket is connection-mode but is not connected.
118
119       ENOTSOCK
120              The socket argument does not refer to a socket.
121
122       EOPNOTSUPP
123              The  socket  argument  is associated with a socket that does not
124              support one or more of the values set in flags.
125
126       EPIPE  The socket is shut down for writing, or the  socket  is  connec‐
127              tion-mode and is no longer connected. In the latter case, and if
128              the socket is of type  SOCK_STREAM  or  SOCK_SEQPACKET  and  the
129              MSG_NOSIGNAL flag is not set, the SIGPIPE signal is generated to
130              the calling thread.
131
132       If the address family of the socket is  AF_UNIX,  then  sendto()  shall
133       fail if:
134
135       EIO    An  I/O error occurred while reading from or writing to the file
136              system.
137
138       ELOOP  A loop exists in symbolic links encountered during resolution of
139              the pathname in the socket address.
140
141       ENAMETOOLONG
142              The  length  of  a  component  of  a  pathname  is  longer  than
143              {NAME_MAX}.
144
145       ENOENT A component of the pathname does not name an  existing  file  or
146              the pathname is an empty string.
147
148       ENOTDIR
149              A  component  of  the  path prefix of the pathname in the socket
150              address names an existing file that is neither a directory nor a
151              symbolic  link  to  a  directory,  or the pathname in the socket
152              address contains at least one  non-<slash>  character  and  ends
153              with  one or more trailing <slash> characters and the last path‐
154              name component names an existing file that is neither  a  direc‐
155              tory nor a symbolic link to a directory.
156
157       The sendto() function may fail if:
158
159       EACCES Search  permission is denied for a component of the path prefix;
160              or write access to the named socket is denied.
161
162       EDESTADDRREQ
163              The socket is not connection-mode and does  not  have  its  peer
164              address set, and no destination address was specified.
165
166       EHOSTUNREACH
167              The  destination  host  cannot  be reached (probably because the
168              host is down or a remote router cannot reach it).
169
170       EINVAL The dest_len argument is not a valid length for the address fam‐
171              ily.
172
173       EIO    An  I/O error occurred while reading from or writing to the file
174              system.
175
176       EISCONN
177              A destination address was specified and the  socket  is  already
178              connected.
179
180       ENETDOWN
181              The  local  network  interface  used to reach the destination is
182              down.
183
184       ENETUNREACH
185              No route to the network is present.
186
187       ENOBUFS
188              Insufficient resources were available in the system  to  perform
189              the operation.
190
191       ENOMEM Insufficient memory was available to fulfill the request.
192
193       If  the address family of the socket is AF_UNIX, then sendto() may fail
194       if:
195
196       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
197              resolution of the pathname in the socket address.
198
199       ENAMETOOLONG
200              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
201              tion of a symbolic link produced an intermediate result  with  a
202              length that exceeds {PATH_MAX}.
203
204       The following sections are informative.
205

EXAMPLES

207       None.
208

APPLICATION USAGE

210       The  select()  and poll() functions can be used to determine when it is
211       possible to send more data.
212

RATIONALE

214       None.
215

FUTURE DIRECTIONS

217       None.
218

SEE ALSO

220       getsockopt(), poll(), pselect(), recv(), recvfrom(), recvmsg(), send(),
221       sendmsg(), setsockopt(), shutdown(), socket()
222
223       The Base Definitions volume of POSIX.1‐2008, <sys_socket.h>
224
226       Portions  of  this text are reprinted and reproduced in electronic form
227       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
228       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
229       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
230       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
231       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
232       event of any discrepancy between this version and the original IEEE and
233       The Open Group Standard, the original IEEE and The Open Group  Standard
234       is  the  referee document. The original Standard can be obtained online
235       at http://www.unix.org/online.html .
236
237       Any typographical or formatting errors that appear  in  this  page  are
238       most likely to have been introduced during the conversion of the source
239       files to man page format. To report such errors,  see  https://www.ker
240       nel.org/doc/man-pages/reporting_bugs.html .
241
242
243
244IEEE/The Open Group                  2013                           SENDTO(3P)
Impressum