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

159 lines
5.2 KiB
HTML

<!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>if_nameindex--Return All Interface Names and Indexes API</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. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- Created for V5R4 by Tim Mullenbach -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!-- End Header Records -->
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2><img src="delta.gif" ALT="Start of change">if_nameindex()--Return All Interface Names and Indexes</h2>
<div class="box" style="width: 80%;">
<br>
<br>
&nbsp;&nbsp;Syntax
<pre>
#include &lt;net/if.h&gt;
struct if_nameindex *if_nameindex(void);
</pre>
&nbsp;&nbsp;Service Program Name: QSOSRV2
<br>
&nbsp;&nbsp;Default Public Authority: *USE
<br>
&nbsp;&nbsp;Threadsafe: Yes<br><br>
</div>
<p>The <strong><em>if_nameindex()</em></strong> function returns an array
of <em>if_nameindex</em> structures, one structure per interface.
The end of the array of structures is indicated by a structure with an
<em>if_index</em> of 0 and an <em>if_name</em> of NULL.
</p>
<br>
<h3><a name="Header_2">Parameters</a></h3>
<p>None.</p>
<br>
<h3><a name="Header_3">Authorities</a></h3>
<p>
No authorization is required.</p>
<br>
<h3><a name="Header_4">Return Value</a></h3>
<p><strong>if_nameindex()</strong> returns a pointer to an array of <em>if_nameindex</em> structures.
Possible values are:</p>
<ul>
<li>Pointer to dynamically allocated memory for the array of <em>if_nameindex</em> structures.
(successful). Note: the <strong><em>if_freenameindex()</em></strong> API should be used to
free the array once it is no longer needed.</li>
<li>NULL (unsuccessful)</li>
</ul>
<p>The structure <strong>struct if_nameindex</strong> is defined in
<strong>&lt;net/if.h&gt;</strong>.</p>
<pre>
struct if_nameindex {
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated line name */
};
</pre>
<br>
<h3><a name="Header_5">Error Conditions</a></h3>
<p>When <em>if_nameindex()</em> fails, <em>errno</em> can be set to one of the following:</p>
<dl compact>
<dt><em>[ENXIO]</em></dt>
<dd>No interfaces names and indexes exist.</dd>
<dt><em>[ENOMEM]</em></dt>
<dd>No memory available for the <em>if_nameindex</em> array.</dd>
</dl>
<br>
<h3>Usage Notes</h3>
<ol>
<li>The interface (line description) names stored at <em>if_name</em> will be
returned in the default coded character set identifier (CCSID) currently in
effect for the job.</li>
<li>It is important to note that the term "Interface" refers to the name on a line
description (i.e. a physical interface) for this API. Other parts of the
operating system, when refering to "Interface," mean an IP address.</li>
<li>The array returned will contain only interfaces (line descriptions) that are
IPv6 capable. The array may also contain a *LOOPBACK entry.</li>
</ol>
<br>
<h3><a name="Header_8">Related Information</a></h3>
<ul>
<li><a href="gsocko.htm">"getsockopt()</a>--Retrieve Information about Socket Options</li>
<li><a href="if_freenameindex.htm">if_freenameindex()</a>--Free Memory Allocated by
if_nameindex()</li>
<li><a href="if_indextoname.htm">if_indextoname()</a>--Map an Interface Index to its
Corresponding Name</li>
<li><a href="if_nametoindex.htm">if_nametoindex()</a>--Map an Interface Name to its
Corresponding Index</li>
<li><a href="ssocko.htm">setsockopt()</a>--Set Socket Options</li>
</ul>
<br>
<h3><a name="Header_9">Example</a></h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example shows how <strong>if_nameindex()</strong> is used:</p>
<pre>
#include &lt;net/if.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;errno.h&gt;
void main()
{
struct if_nameindex *interfaceArray = NULL;
<strong>interfaceArray = if_nameindex(void); /* retrieve the current interfaces */</strong>
if (interfaceArray != NULL)
{
...
if_freenameindex(interfaceArray); /* free the dynamic memory */
interfaceArray = NULL; /* prevent use after free */
}
else
{
printf(&quot;if_nameindex() failed with errno = %d %s \n&quot;,
errno,strerror(errno));
return;
}
...
}</pre>
<img src="deltaend.gif" ALT="End of change">
<br>
<hr>
API introduced: V5R4
<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>