ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/rbind.htm

410 lines
11 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>Rbind()--Set Remote Address for Socket</title>
<!-- Begin Header Records ========================================== -->
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- Edited by Kersten Feb 02 -->
<!--End Header Records -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<a name="Top_Of_Page"></a>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<h2>Rbind()--Set Remote Address for Socket</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;BSD 4.3 Syntax<br>
<pre>
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
int Rbind(int <em>socket_descriptor</em>,
struct sockaddr *<em>local_address</em>,
int <em>address_length</em>)
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QSOSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<br>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
<pre>
#define _XOPEN_SOURCE 520
#include &lt;sys/socket.h&gt;
int Rbind(int <em>socket_descriptor</em>,
const struct sockaddr *<em>local_address</em>,
socklen_t <em>address_length</em>)
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QSOSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<br>
<p>A program uses the <em>Rbind()</em> call to request that a SOCKS server
allow an inbound connection request across a firewall. This call should only be
used by applications that require inbound connections across a firewall, and
should only be used for sockets with an address family of <samp>af_inet</samp>.
Note that for an <em>Rbind()</em> call to succeed, a previous
<em>connect()</em> call must have been issued for this thread, and must have
resulted in an outbound connection over the same SOCKS server. The
<em>Rbind()</em> inbound connection will be from the same IP address addressed
by the original outbound connection. Caution must be exercised so that outbound
and inbound connections over the SOCKS server are paired. In other words, all
<em>Rbind()</em> inbound connections should immediately follow the outbound
connection over the SOCKS server, and no intervening non-SOCKS connections
relating to this thread can be attempted before the <em>Rbind()</em> runs. For
an overview of using sockets and how to interact with a SOCKS server, see the
topic about i5/OS client SOCKS support in the <a href=
"../rzab6/rzab6soxoverview.htm">Sockets Programming</a> in the iSeries
Information Center.</p>
<p> There are two versions of
the API, as shown above. The base i5/OS API uses BSD 4.3 structures and
syntax. The other uses syntax and structures compatible with the UNIX 98
programming interface specifications. You can select the UNIX 98 compatible
interface with the <a href="_xopen_source.htm">_XOPEN_SOURCE</a> macro.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>socket_descriptor</strong></dt>
<dd>(Input) The descriptor of the socket that is to be bound.<br>
<br>
</dd>
<dt><strong>local_address</strong></dt>
<dd>(Input) A pointer to a buffer of type <strong>struct sockaddr</strong> that
contains the local address to which the socket is to be bound. The structure
<strong>sockaddr</strong> is defined in <strong>&lt;sys/socket.h&gt;</strong>.
<p> The BSD 4.3 structure
is:</p>
<pre>
struct sockaddr {
u_short sa_family;
char sa_data[14];
};
</pre>
<p>The BSD 4.4/UNIX 98 compatible structure is:</p>
<pre>
typedef uchar sa_family_t;
struct sockaddr {
uint8_t sa_len;
sa_family_t sa_family;
char sa_data[14];
};
</pre>
<p>The BSD 4.4 <em>sa_len</em> field is the length of the address. The <em>sa_family</em> field identifies
the address family to which the address belongs, and <em>sa_data</em> is the
address whose format is dependent on the address family.</p>
</dd>
<dt><strong>address_length</strong></dt>
<dd>(Input) The length of the <em>local_address</em>.</dd>
</dl>
<br>
<h3>Authorities</h3>
<ul>
<li>When the address type of the socket identified by the
<strong><em>socket_descriptor</em></strong> is AF_INET, the thread must have
retrieve, insert, delete, and update authority to the port specified by the
<strong><em>local_address</em></strong> field. When the thread does not have
this level of authority, an <em>errno</em> of EACCES is returned.<br>
<br>
</li>
<li>When the address type of the socket identified by the
<strong><em>socket_descriptor</em></strong> is AF_INET and is running IP over
SNA, the thread must have retrieve, insert, delete, and update authority to the
APPC device. When the thread does not have this level of authority, an
<em>errno</em> of EACCES is returned.</li>
</ul>
<br>
<h3>Return Value</h3>
<p><em>Rbind()</em> returns an integer. Possible values are:</p>
<ul>
<li>-1 (unsuccessful)<br>
<br>
</li>
<li>0 (successful)</li>
</ul>
<br>
<h3>Error Conditions</h3>
<p>When an <em>Rbind()</em> fails, <em>errno</em> can be set to one of the
following:</p>
<table cellpadding="5">
<!-- cols="20 80" -->
<tr>
<td align="left" valign="top"><em>[EADDRNOTAVAIL]</em></td>
<td align="left" valign="top">Address not available. This error code indicates
one of the following:
<ul>
<li>The SOCKS server specified is not reachable.<br>
<br>
</li>
<li>The SOCKS server has denied the requested inbound connection.<br>
<br>
</li>
<li>The Socket can no longer be used for an inbound connection.<br>
</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EAFNOSUPPORT]</em></td>
<td align="left" valign="top">The type of socket is not supported in this
protocol family.
<p>The address family specified in the address structure pointed to by the
<em>local_address</em> parameter cannot be used with the socket pointed to by
the <em>socket_descriptor</em> parameter.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EBADF]</em></td>
<td align="left" valign="top">Descriptor not valid.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EFAULT]</em></td>
<td align="left" valign="top">Bad address.
<p>The system detected an address that was not valid while attempting to access
the <em>local_address</em> parameter.</p>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EINVAL]</em></td>
<td align="left" valign="top">Parameter not valid. This error code indicates
one of the following:
<ul>
<li>The <em>address_length</em> parameter specifies a length that is negative
or is not valid for the address family.<br>
<br>
</li>
<li>The socket referenced by <em>socket_descriptor</em> is not a socket of type
SOCK_RAW and is already bound to an address.<br>
<br>
</li>
<li>The local address pointed to by the <em>local_address</em> parameter
specified an address that was not valid.<br>
</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EIO]</em></td>
<td align="left" valign="top">Input/output error.<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOBUFS]</em></td>
<td align="left" valign="top">There is not enough buffer space for the
requested operation.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ENOTSOCK]</em></td>
<td align="left" valign="top">The specified descriptor does not reference a
socket.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EUNATCH]</em></td>
<td align="left" valign="top">The protocol required to support the specified
address family is not available at this time.<br>
<br>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>[EUNKNOWN]</em></td>
<td align="left" valign="top">Unknown system state.</td>
</tr>
</table>
<br>
<br>
<h3>Error Messages</h3>
<table width="100%" cellpadding="5">
<!-- cols="15 85" -->
<tr>
<th align="left" valign="top">Message ID</th>
<th align="left" valign="top">Error Message Text</th>
</tr>
<tr>
<td align="left" valign="top">CPE3418 E</td>
<td align="left" valign="top">Possible APAR condition or hardware failure.</td>
</tr>
<tr>
<td align="left" valign="top">CPF9872 E</td>
<td align="left" valign="top">Program or service program &amp;1 in library
&amp;2 ended. Reason code &amp;3.</td>
</tr>
<tr>
<td align="left" valign="top">CPFA081 E</td>
<td align="left" valign="top">Unable to set return value or error code.</td>
</tr>
</table>
<br>
<br>
<h3>Usage Notes</h3>
<ol>
<li>If this call is issued for sockets with an address family other than
<samp>af_inet</samp>, or if the thread has not performed an outbound connection
through a SOCKS server, then a <em>bind()</em> call will be run instead. In
this case the documented <em>errno</em> and usage notes for <em>bind()</em>
apply.<br>
<br>
</li>
<li>The local IP address and port number specified for sockets with an address
family of <samp>af_inet</samp> are ignored if <em>Rbind()</em> results in an
inbound connection over a SOCKS server. In this scenario the socket is
logically bound to the SOCKS server IP address coupled with a port selected via
SOCKS server. If a <em>bind()</em> is performed, then the socket is bound to
the local IP address and port number specified.<br>
<br>
</li>
<li>The <em>Rbind()</em> function may be explicitly used, or optionally you can
compile your application with the __Rbind macro defined when you call the
compiler. For example, if you are compiling with a Create C Module (CRTCMOD) CL
command, specify __Rbind for the DEFINE keyword to cause the __Rbind macro to
be defined before the compilation starts. Now all <em>bind()</em> calls in the
program will become <em>Rbind()</em>. See <strong>&lt;sys/socket.h&gt;</strong>
for a definition of the __Rbind macro.<br>
<br>
</li>
<li>When you develop in C-based
languages and an application is compiled with the _XOPEN_SOURCE macro defined
to the value 520 or greater, the <em>Rbind()</em> API is mapped to
<em>qso_Rbind98()</em>.</li>
</ol>
<br>
<h3>Related Information</h3>
<ul>
<li><a href=
"_xopen_source.htm">_XOPEN_SOURCE</a>--Using _XOPEN_SOURCE for the UNIX 98
compatible interface<br>
<br>
</li>
<li><a href="accept.htm">accept()</a>--Wait for Connection Request and Make
Connection<br>
<br>
</li>
<li><a href="bind.htm">bind()</a>--Set Local Address for Socket<br>
<br>
</li>
<li><a href="connec.htm">connect()</a>--Establish Connection or Destination
Address<br>
<br>
</li>
<li><a href="gsockn.htm">getsockname()</a>--Retrieve Local Address of
Socket</li>
</ul>
<br>
<hr>
API introduced: V4R2
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> |
<a href="unix.htm">UNIX-Type APIs</a> |
<a href="aplist.htm">APIs by category</a> </td>
</tr>
</table>
</center>
</body>
</html>