{"id":5318,"date":"2022-12-20T18:37:18","date_gmt":"2022-12-20T21:37:18","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/sendto-man3p\/"},"modified":"2022-12-20T18:37:18","modified_gmt":"2022-12-20T21:37:18","slug":"sendto-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/sendto-man3p\/","title":{"rendered":"SENDTO (man3p)"},"content":{"rendered":"<h1 align=\"center\">SENDTO<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">sendto \u2014 send a message on a socket<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <sys\/socket.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">ssize_t sendto(int <i>socket<\/i>, const void *<i>message<\/i>, size_t <i>length<\/i>, <br \/> int <i>flags<\/i>, const struct sockaddr *<i>dest_addr<\/i>, <br \/> socklen_t <i>dest_len<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>sendto<\/i>() function shall send a message through a connection-mode or connectionless-mode socket.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the socket is a connectionless-mode socket, the message shall be sent to the address specified by <i>dest_addr<\/i> if no pre-specified peer address has been set. If a peer address has been pre-specified, either the message shall be sent to the address specified by <i>dest_addr<\/i> (overriding the pre-specified peer address), or the function shall return \u22121 and set <i>errno<\/i> to <b>[EISCONN]<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the socket is connection-mode, <i>dest_addr<\/i> shall be ignored.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>sendto<\/i>() function takes the following arguments:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>socket<\/i><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"71%\">\n<p>Specifies the socket file descriptor.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>message<\/i><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"71%\">\n<p>Points to a buffer containing the message to be sent.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>length<\/i><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"71%\">\n<p>Specifies the size of the message in bytes.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"11%\">\n<p><i>flags<\/i><\/p>\n<\/td>\n<td width=\"7%\"><\/td>\n<td width=\"71%\">\n<p>Specifies the type of message transmission. Values of this argument are formed by logically OR\u2019ing zero or more of the following flags:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:29%;\">MSG_EOR<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"37%\"><\/td>\n<td width=\"3%\"><\/td>\n<td width=\"49%\">\n<p style=\"margin-top: 1em\">Terminates a record (if supported by the protocol).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"37%\">\n<p>MSG_OOB<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"49%\">\n<p>Sends out-of-band data on sockets that support out-of-band data. The significance and semantics of out-of-band data are protocol-specific.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"37%\">\n<p>MSG_NOSIGNAL<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"49%\">\n<p>Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected. The <b>[EPIPE]<\/b> error shall still be returned.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"37%\">\n<p><i>dest_addr<\/i><\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"49%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:29%; margin-top: 1em\">Points to a <b>sockaddr<\/b> structure containing the destination address. The length and format of the address depend on the address family of the socket.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"12%\">\n<p style=\"margin-top: 1em\"><i>dest_len<\/i><\/p>\n<\/td>\n<td width=\"6%\"><\/td>\n<td width=\"71%\">\n<p style=\"margin-top: 1em\">Specifies the length of the <b>sockaddr<\/b> structure pointed to by the <i>dest_addr<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If the socket protocol supports broadcast and the specified address is a broadcast address for the socket protocol, <i>sendto<\/i>() shall fail if the SO_BROADCAST option is not set for the socket.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>dest_addr<\/i> argument specifies the address of the target.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>length<\/i> argument specifies the length of the message.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Successful completion of a call to <i>sendto<\/i>() does not guarantee delivery of the message. A return value of \u22121 indicates only locally-detected errors.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If space is not available at the sending socket to hold the message to be transmitted and the socket file descriptor does not have O_NONBLOCK set, <i>sendto<\/i>() shall block 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 O_NONBLOCK set, <i>sendto<\/i>() shall fail.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The socket in use may require the process to have appropriate privileges to use the <i>sendto<\/i>() function.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>sendto<\/i>() shall return the number of bytes sent. Otherwise, \u22121 shall be returned and <i>errno<\/i> set to indicate the error.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>sendto<\/i>() function shall fail if: <b><br \/> EAFNOSUPPORT<\/b><\/p>\n<p style=\"margin-left:22%;\">Addresses in the specified address family cannot be used with this socket.<\/p>\n<p style=\"margin-left:11%;\"><b>EAGAIN<\/b> or <b>EWOULDBLOCK<\/b><\/p>\n<p style=\"margin-left:22%;\">The socket\u2019s file descriptor is marked O_NONBLOCK and the requested operation would block.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>EBADF<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>The <i>socket<\/i> argument is not a valid file descriptor.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ECONNRESET<\/b><\/p>\n<p style=\"margin-left:22%;\">A connection was forcibly closed by a peer.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>EINTR<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>A signal interrupted <i>sendto<\/i>() before any data was transmitted.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>EMSGSIZE<\/b><\/p>\n<p style=\"margin-left:22%;\">The message is too large to be sent all at once, as the socket requires.<\/p>\n<p style=\"margin-left:11%;\"><b>ENOTCONN<\/b><\/p>\n<p style=\"margin-left:22%;\">The socket is connection-mode but is not connected.<\/p>\n<p style=\"margin-left:11%;\"><b>ENOTSOCK<\/b><\/p>\n<p style=\"margin-left:22%;\">The <i>socket<\/i> argument does not refer to a socket.<\/p>\n<p style=\"margin-left:11%;\"><b>EOPNOTSUPP<\/b><\/p>\n<p style=\"margin-left:22%;\">The <i>socket<\/i> argument is associated with a socket that does not support one or more of the values set in <i>flags<\/i>.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>EPIPE<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM or SOCK_SEQPACKET and the MSG_NOSIGNAL flag is not set, the SIGPIPE signal is generated to the calling thread.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If the address family of the socket is AF_UNIX, then <i>sendto<\/i>() shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p style=\"margin-top: 1em\"><b>EIO<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">An I\/O error occurred while reading from or writing to the file system.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>A loop exists in symbolic links encountered during resolution of the pathname in the socket address.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a component of a pathname is longer than {NAME_MAX}.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOENT<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A component of the pathname does not name an existing file or the pathname is an empty string.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">A component of the path prefix of the pathname in the socket address names an existing file that is neither a directory nor a symbolic link to a directory, or the pathname in the socket address contains at least one non-<slash> character and ends with one or more trailing <slash> characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>sendto<\/i>() function may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Search permission is denied for a component of the path prefix; or write access to the named socket is denied.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>EDESTADDRREQ<\/b><\/p>\n<p style=\"margin-left:22%;\">The socket is not connection-mode and does not have its peer address set, and no destination address was specified.<\/p>\n<p style=\"margin-left:11%;\"><b>EHOSTUNREACH<\/b><\/p>\n<p style=\"margin-left:22%;\">The destination host cannot be reached (probably because the host is down or a remote router cannot reach it).<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>dest_len<\/i> argument is not a valid length for the address family.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EIO<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>An I\/O error occurred while reading from or writing to the file system.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>EISCONN<\/b><\/p>\n<p style=\"margin-left:22%;\">A destination address was specified and the socket is already connected.<\/p>\n<p style=\"margin-left:11%;\"><b>ENETDOWN<\/b><\/p>\n<p style=\"margin-left:22%;\">The local network interface used to reach the destination is down.<\/p>\n<p style=\"margin-left:11%;\"><b>ENETUNREACH<\/b><\/p>\n<p style=\"margin-left:22%;\">No route to the network is present.<\/p>\n<p style=\"margin-left:11%;\"><b>ENOBUFS<\/b><\/p>\n<p style=\"margin-left:22%;\">Insufficient resources were available in the system to perform the operation.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOMEM<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Insufficient memory was available to fulfill the request.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If the address family of the socket is AF_UNIX, then <i>sendto<\/i>() may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p style=\"margin-top: 1em\"><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the pathname in the socket address.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>select<\/i>() and <i>poll<\/i>() functions can be used to determine when it is possible to send more data.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>getsockopt<\/i>(), <i>poll<\/i>(), <i>pselect<\/i>(), <i>recv<\/i>(), <i>recvfrom<\/i>(), <i>recvmsg<\/i>(), <i>send<\/i>(), <i>sendmsg<\/i>(), <i>setsockopt<\/i>(), <i>shutdown<\/i>(), <i>socket<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><sys_socket.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  sendto \u2014 send a message on a socket <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1594,2206],"class_list":["post-5318","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-man3p","tag-sendto"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5318"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5318\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}