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

NAME

12       sendto — send a message on a socket
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

206       None.
207

APPLICATION USAGE

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

RATIONALE

213       None.
214

FUTURE DIRECTIONS

216       None.
217

SEE ALSO

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