sendto(3N-xs) (X/OPEN SOCKETS) sendto(3N-xs)
NAME
sendto - send a message on a socket
SYNOPSIS
cc [flag ...] file ... -lxnet [library ...]
#include <sys/socket.h>
ssizet sendto(int socket, const void *message, sizet length,
int flags, const struct sockaddr *destaddr, sizet destlen);
DESCRIPTION
The sendto function sends a message through a connection-oriented or
connectionless socket. If the socket is connectionless, the message
will be sent to the address specified by destaddr. If the socket is
connection-oriented, destaddr is ignored.
The function takes the following arguments:
socket Specifies the socket file descriptor.
message Points to a buffer containing the message to be sent.
length Specifies the size of the message in bytes.
flags Specifies the type of message transmission. Values of
this argument are formed by logically ORing zero or more
of the following flags:
MSGEOR Terminates a record (if supported by the pro-
tocol).
MSGOOB Sends out-of-band data on sockets that support
out-of-band data. The significance and seman-
tics of out-of-band data are protocol-speci-
fic.
destaddr Points to a sockaddr structure containing the destination
address. The length and format of the address depend on
the address family of the socket.
destlen Specifies the length of the sockaddr structure pointed to
by the destaddr argument.
If the socket protocol supports broadcast and the specified address is
a broadcast address for the socket protocol, sendto will fail if the
SOBROADCAST option is not set for the socket.
The destaddr argument specifies the address of the target. The length
argument specifies the length of the message.
Page 1 Reliant UNIX 5.44 Printed 11/98
sendto(3N-xs) (X/OPEN SOCKETS) sendto(3N-xs)
Successful completion of a call to sendto does not guarantee delivery
of the message. A return value of -1 indicates only locally-detected
errors.
If space is not available at the sending socket to hold the message to
be transmitted and the socket file descriptor does not have ONONBLOCK
set, sendto blocks until space is available. If space is not available
at the sending socket to hold the message to be transmitted and the
socket file descriptor does have ONONBLOCK set, sendto will fail.
RETURN VALUE
Upon successful completion, sendto returns the number of bytes sent.
Otherwise, -1 is returned and errno is set to indicate the error.
ERRORS
The sendto function will fail if:
EAFNOSUPPORT Addresses in the specified address family cannot be
used with this socket.
EBADF The socket argument is not a valid file descriptor.
ECONNRESET A connection was forcibly closed by a peer.
EINTR A signal interrupted sendto before any data was trans-
mitted.
EMSGSIZE The message is too large to be sent all at once, as
the socket requires.
ENOTCONN The socket is connection-oriented but is not con-
nected.
ENOTSOCK The socket argument does not refer to a socket.
EOPNOTSUPP The socket argument is associated with a socket that
does not support one or more of the values set in
flags.
EPIPE The socket is shut down for writing, or the socket is
connection-oriented and the peer is closed or shut
down for reading. In the latter case, and if the
socket is of type SOCKSTREAM, the SIGPIPE signal is
generated to the calling process.
EWOULDBLOCK or EAGAIN
The socket's file descriptor is marked ONONBLOCK and
the requested operation would block.
Page 2 Reliant UNIX 5.44 Printed 11/98
sendto(3N-xs) (X/OPEN SOCKETS) sendto(3N-xs)
If the address family of the socket is AFUNIX, then sendto will fail
if:
EACCES Search permission is denied for a component of the
path prefix; or write access to the named socket is
denied.
EIO An I/O error occurred while reading from or writing to
the file system.
ELOOP Too many symbolic links were encountered in translat-
ing the pathname in the socket address.
ENAMETOOLONG A component of a pathname exceeded {NAMEMAX} charac-
ters, or an entire pathname exceeded {PATHMAX} char-
acters.
ENOENT A component of the pathname does not name an existing
file or the pathname is an empty string.
ENOTDIR A component of the path prefix of the pathname in the
socket address is not a directory.
The sendto function may fail if:
EDESTADDRREQ The socket is not connection-oriented and does not
have its peer address set, and no destination address
was specified.
EHOSTUNREACH The destination host cannot be reached (probably
because the host is down or a remote router cannot
reach it).
EINVAL The destlen argument is not a valid length for the
address family.
EIO An I/O error occurred while reading from or writing to
the file system.
EISCONN A destination address was specified and the socket is
connection-oriented and is already connected.
ENETDOWN The local interface used to reach the destination is
down.
ENETUNREACH No route to the network is present.
ENOBUFS The resources available in the system were not suffi-
cient to perform the operation.
ENOMEM The memory available was not sufficient to fulfill the
request.
Page 3 Reliant UNIX 5.44 Printed 11/98
sendto(3N-xs) (X/OPEN SOCKETS) sendto(3N-xs)
ENOSR The STREAMS resources available were not sufficient to
complete the operation.
If the address family of the socket is AFUNIX, then sendto may fail
if:
ENAMETOOLONG Pathname resolution of a symbolic link produced an
intermediate result whose length exceeds {PATHMAX}.
APPLICATION USAGE
The select and poll functions can be used to determine when it is pos-
sible to send more data.
SEE ALSO
poll(2), select(3C), getsockopt(3N), recv(3N-xs), recvfrom(3N-xs),
recvmsg(3N-xs), send(3N-xs), sendmsg(3N-xs), setsockopt(3N-xs),
shutdown(3N-xs), socket(3N-xs).
Page 4 Reliant UNIX 5.44 Printed 11/98