1sendto(3XNET)    X/Open Networking Services Library Functions    sendto(3XNET)
2
3
4

NAME

6       sendto - send a message on a socket
7

SYNOPSIS

9       cc [ flag... ] file... -lxnet [ library ... ]
10       #include <sys/socket.h>
11
12       ssize_t sendto(int socket, const void *message, size_t length, int flags,
13            const struct sockaddr *dest_addr, socklen_t dest_len);
14
15

DESCRIPTION

17       The sendto() function sends a message through a connection-mode or con‐
18       nectionless-mode socket.  If the  socket  is  connectionless-mode,  the
19       message  will  be  sent  to the address specified by dest_addr.  If the
20       socket is connection-mode, dest_addr is ignored.
21
22
23       If the socket protocol supports broadcast and the specified address  is
24       a  broadcast address for the socket protocol, sendto() will fail if the
25       SO_BROADCAST option is not set for the socket.
26
27
28       The dest_addr argument specifies the address of the target. The  length
29       argument specifies the length of the message.
30
31
32       Successful completion of a call to sendto() does not guarantee delivery
33       of the message. A return value of −1  indicates  only  locally-detected
34       errors.
35
36
37       If  space is not available at the sending socket to hold the message to
38       be transmitted and the socket file descriptor does not have  O_NONBLOCK
39       set,  sendto()  blocks until space is available. If space is not avail‐
40       able at the sending socket to hold the message to  be  transmitted  and
41       the  socket  file  descriptor  does  have O_NONBLOCK set, sendto() will
42       fail.
43
44
45       The socket in use may require the process to  have  appropriate  privi‐
46       leges to use the sendto() function.
47

PARAMETERS

49       The function takes the following arguments:
50
51       socket       Specifies the socket file descriptor.
52
53
54       message      Points to a buffer containing the message to be sent.
55
56
57       length       Specifies the size of the message in bytes.
58
59
60       flags        Specifies the type of message transmission. Values of this
61                    argument are formed by logically OR'ing zero  or  more  of
62                    the following flags:
63
64                    MSG_EOR    Terminates a record (if supported by the proto‐
65                               col)
66
67
68                    MSG_OOB    Sends out-of-band data on sockets that  support
69                               out-of-band  data.  The significance and seman‐
70                               tics of out-of-band data are protocol-specific.
71
72
73
74       dest_addr    Points to a sockaddr structure containing the  destination
75                    address.   The  length and format of the address depend on
76                    the address family of the socket.
77
78
79       dest_len     Specifies the length of the sockaddr structure pointed  to
80                    by the dest_addr argument.
81
82

USAGE

84       The  select(3C)  and poll(2) functions can be used to determine when it
85       is possible to send more data.
86

RETURN VALUES

88       Upon successful completion, sendto() returns the number of bytes  sent.
89       Otherwise, -1 is returned and errno is set to indicate the error.
90

ERRORS

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

ATTRIBUTES

217       See attributes(5) for descriptions of the following attributes:
218
219
220
221
222       ┌─────────────────────────────┬─────────────────────────────┐
223       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
224       ├─────────────────────────────┼─────────────────────────────┤
225       │Interface Stability          │Standard                     │
226       ├─────────────────────────────┼─────────────────────────────┤
227       │MT-Level                     │MT-Safe                      │
228       └─────────────────────────────┴─────────────────────────────┘
229

SEE ALSO

231       poll(2),     getsockopt(3XNET),      recv(3XNET),      recvfrom(3XNET),
232       recvmsg(3XNET),   select(3C),   send(3XNET),  sendmsg(3XNET),  setsock‐
233       opt(3XNET), shutdown(3XNET), socket(3XNET), attributes(5), standards(5)
234
235
236
237SunOS 5.11                        1 Nov 2003                     sendto(3XNET)
Impressum