Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/bind.html
2024-02-19 00:21:47 -05:00

234 lines
6.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>bind</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="bind"></a> <a name="tag_03_39"></a><!-- bind -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_39_01"></a>NAME</h4>
<blockquote>bind - bind a name to a socket</blockquote>
<h4><a name="tag_03_39_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>&gt;<br>
<br>
int bind(int</tt> <i>socket</i><tt>, const struct sockaddr *</tt><i>address</i><tt>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; socklen_t</tt> <i>address_len</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_39_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>bind</i>() function shall assign a local socket address <i>address</i> to a socket identified by descriptor <i>socket</i>
that has no local socket address assigned. Sockets created with the <a href="../functions/socket.html"><i>socket</i>()</a> function
are initially unnamed; they are identified only by their address family.</p>
<p>The <i>bind</i>() function takes the following arguments:</p>
<dl compact>
<dt><i>socket</i></dt>
<dd>Specifies the file descriptor of the socket to be bound.</dd>
<dt><i>address</i></dt>
<dd>Points to a <b>sockaddr</b> structure containing the address to be bound to the socket. The length and format of the address
depend on the address family of the socket.</dd>
<dt><i>address_len</i></dt>
<dd>Specifies the length of the <b>sockaddr</b> structure pointed to by the <i>address</i> argument.</dd>
</dl>
<p>The socket specified by <i>socket</i> may require the process to have appropriate privileges to use the <i>bind</i>()
function.</p>
</blockquote>
<h4><a name="tag_03_39_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>bind</i>() shall return 0; otherwise, -1 shall be returned and <i>errno</i> set to indicate the
error.</p>
</blockquote>
<h4><a name="tag_03_39_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>bind</i>() function shall fail if:</p>
<dl compact>
<dt>[EADDRINUSE]</dt>
<dd>The specified address is already in use.</dd>
<dt>[EADDRNOTAVAIL]</dt>
<dd>
The specified address is not available from the local machine.</dd>
<dt>[EAFNOSUPPORT]</dt>
<dd>
The specified address is not a valid address for the address family of the specified socket.</dd>
<dt>[EBADF]</dt>
<dd>The <i>socket</i> argument is not a valid file descriptor.</dd>
<dt>[EINVAL]</dt>
<dd>The socket is already bound to an address, and the protocol does not support binding to a new address; or the socket has been
shut down.</dd>
<dt>[ENOTSOCK]</dt>
<dd>The <i>socket</i> argument does not refer to a socket.</dd>
<dt>[EOPNOTSUPP]</dt>
<dd>The socket type of the specified socket does not support binding to an address.</dd>
</dl>
<p>If the address family of the socket is AF_UNIX, then <i>bind</i>() shall fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>A component of the path prefix denies search permission, or the requested name requires writing in a directory with a mode that
denies write permission.</dd>
<dt>[EDESTADDRREQ] or [EISDIR]</dt>
<dd>
The <i>address</i> argument is a null pointer.</dd>
<dt>[EIO]</dt>
<dd>An I/O error occurred.</dd>
<dt>[ELOOP]</dt>
<dd>A loop exists in symbolic links encountered during resolution of the pathname in <i>address</i>.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
A component of a pathname exceeded {NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.</dd>
<dt>[ENOENT]</dt>
<dd>A component of the pathname does not name an existing file or the pathname is an empty string.</dd>
<dt>[ENOTDIR]</dt>
<dd>A component of the path prefix of the pathname in <i>address</i> is not a directory.</dd>
<dt>[EROFS]</dt>
<dd>The name would reside on a read-only file system.</dd>
</dl>
<p>The <i>bind</i>() function may fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>The specified address is protected and the current user does not have permission to bind to it.</dd>
<dt>[EINVAL]</dt>
<dd>The <i>address_len</i> argument is not a valid length for the address family.</dd>
<dt>[EISCONN]</dt>
<dd>The socket is already connected.</dd>
<dt>[ELOOP]</dt>
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the pathname in <i>address</i>.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
<dt>[ENOBUFS]</dt>
<dd>Insufficient resources were available to complete the call.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_39_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_39_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>An application program can retrieve the assigned socket name with the <a href=
"../functions/getsockname.html"><i>getsockname</i>()</a> function.</p>
</blockquote>
<h4><a name="tag_03_39_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_39_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_39_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="connect.html"><i>connect</i>()</a> , <a href="getsockname.html"><i>getsockname</i>()</a> , <a href=
"listen.html"><i>listen</i>()</a> , <a href="socket.html"><i>socket</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/sys/socket.h.html"><i>&lt;sys/socket.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_39_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>