Blame man-pages-posix-2013-a/man3p/sendto.3p

Packit 7cfc04
'\" et
Packit 7cfc04
.TH SENDTO "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
Packit 7cfc04
.SH PROLOG
Packit 7cfc04
This manual page is part of the POSIX Programmer's Manual.
Packit 7cfc04
The Linux implementation of this interface may differ (consult
Packit 7cfc04
the corresponding Linux manual page for details of Linux behavior),
Packit 7cfc04
or the interface may not be implemented on Linux.
Packit 7cfc04
Packit 7cfc04
.SH NAME
Packit 7cfc04
sendto
Packit 7cfc04
\(em send a message on a socket
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <sys/socket.h>
Packit 7cfc04
.P
Packit 7cfc04
ssize_t sendto(int \fIsocket\fP, const void *\fImessage\fP, size_t \fIlength\fP,
Packit 7cfc04
    int \fIflags\fP, const struct sockaddr *\fIdest_addr\fP,
Packit 7cfc04
    socklen_t \fIdest_len\fP);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
function shall send a message through a connection-mode or
Packit 7cfc04
connectionless-mode socket.
Packit 7cfc04
.P
Packit 7cfc04
If the socket is a connectionless-mode socket, the message shall be sent
Packit 7cfc04
to the address specified by
Packit 7cfc04
.IR dest_addr
Packit 7cfc04
if no pre-specified peer address has been set. If a peer address has
Packit 7cfc04
been pre-specified, either the message shall be sent to the address
Packit 7cfc04
specified by
Packit 7cfc04
.IR dest_addr
Packit 7cfc04
(overriding the pre-specified peer address), or the function shall
Packit 7cfc04
return \(mi1 and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to
Packit 7cfc04
.BR [EISCONN] .
Packit 7cfc04
.P
Packit 7cfc04
If the socket is connection-mode,
Packit 7cfc04
.IR dest_addr
Packit 7cfc04
shall be ignored.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
function takes the following arguments:
Packit 7cfc04
.IP "\fIsocket\fR" 12
Packit 7cfc04
Specifies the socket file descriptor.
Packit 7cfc04
.IP "\fImessage\fR" 12
Packit 7cfc04
Points to a buffer containing the message to be sent.
Packit 7cfc04
.IP "\fIlength\fR" 12
Packit 7cfc04
Specifies the size of the message in bytes.
Packit 7cfc04
.IP "\fIflags\fR" 12
Packit 7cfc04
Specifies the type of message transmission. Values of this argument
Packit 7cfc04
are formed by logically OR'ing zero or more of the following flags:
Packit 7cfc04
.RS 12 
Packit 7cfc04
.IP MSG_EOR 14
Packit 7cfc04
Terminates a record (if supported by the protocol).
Packit 7cfc04
.IP MSG_OOB 14
Packit 7cfc04
Sends out-of-band data on sockets that support out-of-band data. The
Packit 7cfc04
significance and semantics of out-of-band data are protocol-specific.
Packit 7cfc04
.IP MSG_NOSIGNAL 14
Packit 7cfc04
Requests not to send the SIGPIPE signal if an attempt to send is made
Packit 7cfc04
on a stream-oriented socket that is no longer connected. The
Packit 7cfc04
.BR [EPIPE] 
Packit 7cfc04
error shall still be returned.
Packit 7cfc04
.RE
Packit 7cfc04
.IP "\fIdest_addr\fR" 12
Packit 7cfc04
Points to a
Packit 7cfc04
.BR sockaddr
Packit 7cfc04
structure containing the destination address. The length and format of
Packit 7cfc04
the address depend on the address family of the socket.
Packit 7cfc04
.IP "\fIdest_len\fR" 12
Packit 7cfc04
Specifies the length of the
Packit 7cfc04
.BR sockaddr
Packit 7cfc04
structure pointed to by the
Packit 7cfc04
.IR dest_addr
Packit 7cfc04
argument.
Packit 7cfc04
.P
Packit 7cfc04
If the socket protocol supports broadcast and the specified address is
Packit 7cfc04
a broadcast address for the socket protocol,
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
shall fail if the SO_BROADCAST option is not set for the socket.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR dest_addr
Packit 7cfc04
argument specifies the address of the target.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR length
Packit 7cfc04
argument specifies the length of the message.
Packit 7cfc04
.P
Packit 7cfc04
Successful completion of a call to
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
does not guarantee delivery of the message. A return value of \(mi1
Packit 7cfc04
indicates only locally-detected errors.
Packit 7cfc04
.P
Packit 7cfc04
If space is not available at the sending socket to hold the message to
Packit 7cfc04
be transmitted and the socket file descriptor does not have O_NONBLOCK
Packit 7cfc04
set,
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
shall block until space is available. If space is not available at the
Packit 7cfc04
sending socket to hold the message to be transmitted and the socket
Packit 7cfc04
file descriptor does have O_NONBLOCK set,
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
shall fail.
Packit 7cfc04
.br
Packit 7cfc04
.P
Packit 7cfc04
The socket in use may require the process to have appropriate
Packit 7cfc04
privileges to use the
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
function.
Packit 7cfc04
.SH "RETURN VALUE"
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
shall return the number of bytes sent. Otherwise, \(mi1 shall be
Packit 7cfc04
returned and
Packit 7cfc04
.IR errno
Packit 7cfc04
set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
The
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
function shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EAFNOSUPPORT
Packit 7cfc04
.br
Packit 7cfc04
Addresses in the specified address family cannot be used with this
Packit 7cfc04
socket.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EAGAIN " or " EWOULDBLOCK
Packit 7cfc04
.br
Packit 7cfc04
The socket's file descriptor is marked O_NONBLOCK and the requested
Packit 7cfc04
operation would block.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EBADF
Packit 7cfc04
The
Packit 7cfc04
.IR socket
Packit 7cfc04
argument is not a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ECONNRESET
Packit 7cfc04
A connection was forcibly closed by a peer.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINTR
Packit 7cfc04
A signal interrupted
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
before any data was transmitted.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EMSGSIZE
Packit 7cfc04
The message is too large to be sent all at once, as the socket
Packit 7cfc04
requires.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOTCONN
Packit 7cfc04
The socket is connection-mode but is not connected.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOTSOCK
Packit 7cfc04
The
Packit 7cfc04
.IR socket
Packit 7cfc04
argument does not refer to a socket.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EOPNOTSUPP
Packit 7cfc04
The
Packit 7cfc04
.IR socket
Packit 7cfc04
argument is associated with a socket that does not support one or more
Packit 7cfc04
of the values set in
Packit 7cfc04
.IR flags .
Packit 7cfc04
.TP
Packit 7cfc04
.BR EPIPE
Packit 7cfc04
The socket is shut down for writing, or the socket is connection-mode
Packit 7cfc04
and is no longer connected. In the latter case, and if the socket is of
Packit 7cfc04
type SOCK_STREAM or SOCK_SEQPACKET and the MSG_NOSIGNAL flag is not set,
Packit 7cfc04
the SIGPIPE signal is generated to the calling thread.
Packit 7cfc04
.P
Packit 7cfc04
If the address family of the socket is AF_UNIX, then
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EIO
Packit 7cfc04
An I/O error occurred while reading from or writing to the file
Packit 7cfc04
system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ELOOP
Packit 7cfc04
A loop exists in symbolic links encountered during resolution of the
Packit 7cfc04
pathname in the socket address.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENAMETOOLONG
Packit 7cfc04
.br
Packit 7cfc04
The length of a component of a pathname is longer than
Packit 7cfc04
{NAME_MAX}.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOENT
Packit 7cfc04
A component of the pathname does not name an existing file or the
Packit 7cfc04
pathname is an empty string.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOTDIR
Packit 7cfc04
A component of the path prefix of the pathname in the socket address
Packit 7cfc04
names an existing file that is neither a directory nor a symbolic link
Packit 7cfc04
to a directory, or the pathname in the socket address contains at
Packit 7cfc04
least one non-\c
Packit 7cfc04
<slash>
Packit 7cfc04
character and ends with one or more trailing
Packit 7cfc04
<slash>
Packit 7cfc04
characters and the last pathname component names an existing file that
Packit 7cfc04
is neither a directory nor a symbolic link to a directory.
Packit 7cfc04
.br
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
function may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES
Packit 7cfc04
Search permission is denied for a component of the path prefix; or
Packit 7cfc04
write access to the named socket is denied.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EDESTADDRREQ
Packit 7cfc04
.br
Packit 7cfc04
The socket is not connection-mode and does not have its peer address
Packit 7cfc04
set, and no destination address was specified.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EHOSTUNREACH
Packit 7cfc04
.br
Packit 7cfc04
The destination host cannot be reached (probably because the host is
Packit 7cfc04
down or a remote router cannot reach it).
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL
Packit 7cfc04
The
Packit 7cfc04
.IR dest_len
Packit 7cfc04
argument is not a valid length for the address family.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EIO
Packit 7cfc04
An I/O error occurred while reading from or writing to the file
Packit 7cfc04
system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EISCONN
Packit 7cfc04
A destination address was specified and the socket is already
Packit 7cfc04
connected.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENETDOWN
Packit 7cfc04
The local network interface used to reach the destination is down.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENETUNREACH
Packit 7cfc04
.br
Packit 7cfc04
No route to the network is present.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOBUFS
Packit 7cfc04
Insufficient resources were available in the system to perform the
Packit 7cfc04
operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOMEM
Packit 7cfc04
Insufficient memory was available to fulfill the request.
Packit 7cfc04
.P
Packit 7cfc04
If the address family of the socket is AF_UNIX, then
Packit 7cfc04
\fIsendto\fR()
Packit 7cfc04
may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR ELOOP
Packit 7cfc04
More than
Packit 7cfc04
{SYMLOOP_MAX}
Packit 7cfc04
symbolic links were encountered during resolution of the pathname in
Packit 7cfc04
the socket address.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENAMETOOLONG
Packit 7cfc04
.br
Packit 7cfc04
The length of a pathname exceeds
Packit 7cfc04
{PATH_MAX},
Packit 7cfc04
or pathname resolution of a symbolic link produced an intermediate
Packit 7cfc04
result with a length that exceeds
Packit 7cfc04
{PATH_MAX}.
Packit 7cfc04
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH "EXAMPLES"
Packit 7cfc04
None.
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
The
Packit 7cfc04
\fIselect\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIpoll\fR()
Packit 7cfc04
functions can be used to determine when it is possible to send more
Packit 7cfc04
data.
Packit 7cfc04
.SH "RATIONALE"
Packit 7cfc04
None.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
None.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "\fIgetsockopt\fR\^(\|)",
Packit 7cfc04
.IR "\fIpoll\fR\^(\|)",
Packit 7cfc04
.IR "\fIpselect\fR\^(\|)",
Packit 7cfc04
.IR "\fIrecv\fR\^(\|)",
Packit 7cfc04
.IR "\fIrecvfrom\fR\^(\|)",
Packit 7cfc04
.IR "\fIrecvmsg\fR\^(\|)",
Packit 7cfc04
.IR "\fIsend\fR\^(\|)",
Packit 7cfc04
.IR "\fIsendmsg\fR\^(\|)",
Packit 7cfc04
.IR "\fIsetsockopt\fR\^(\|)",
Packit 7cfc04
.IR "\fIshutdown\fR\^(\|)",
Packit 7cfc04
.IR "\fIsocket\fR\^(\|)"
Packit 7cfc04
.P
Packit 7cfc04
The Base Definitions volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "\fB<sys_socket.h>\fP"
Packit 7cfc04
.SH COPYRIGHT
Packit 7cfc04
Portions of this text are reprinted and reproduced in electronic form
Packit 7cfc04
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
Packit 7cfc04
-- Portable Operating System Interface (POSIX), The Open Group Base
Packit 7cfc04
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Packit 7cfc04
Electrical and Electronics Engineers, Inc and The Open Group.
Packit 7cfc04
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
Packit 7cfc04
event of any discrepancy between this version and the original IEEE and
Packit 7cfc04
The Open Group Standard, the original IEEE and The Open Group Standard
Packit 7cfc04
is the referee document. The original Standard can be obtained online at
Packit 7cfc04
http://www.unix.org/online.html .
Packit 7cfc04
Packit 7cfc04
Any typographical or formatting errors that appear
Packit 7cfc04
in this page are most likely
Packit 7cfc04
to have been introduced during the conversion of the source files to
Packit 7cfc04
man page format. To report such errors, see
Packit 7cfc04
https://www.kernel.org/doc/man-pages/reporting_bugs.html .