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
21

DESCRIPTION

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

RETURN VALUE

82       Upon  successful  completion, sendto() shall return the number of bytes
83       sent. Otherwise, -1 shall be returned and errno  set  to  indicate  the
84       error.
85

ERRORS

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

EXAMPLES

197       None.
198

APPLICATION USAGE

200       The select() and poll() functions can be used to determine when  it  is
201       possible to send more data.
202

RATIONALE

204       None.
205

FUTURE DIRECTIONS

207       None.
208

SEE ALSO

210       getsockopt(),  poll(), recv(), recvfrom(), recvmsg(), select(), send(),
211       sendmsg(), setsockopt(), shutdown(),  socket(),  the  Base  Definitions
212       volume of IEEE Std 1003.1-2001, <sys/socket.h>
213
215       Portions  of  this text are reprinted and reproduced in electronic form
216       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
217       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
218       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
219       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
220       event of any discrepancy between this version and the original IEEE and
221       The  Open Group Standard, the original IEEE and The Open Group Standard
222       is the referee document. The original Standard can be  obtained  online
223       at http://www.opengroup.org/unix/online.html .
224
225
226
227IEEE/The Open Group                  2003                           SENDTO(3P)
Impressum