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

142 lines
4.4 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>if_freenameindex--Free Dynamic Memory Allocated by if_nameindex() 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_freenameindex()--Free Dynamic Memory Allocated by if_nameindex()</h2>
<div class="box" style="width: 80%;">
<br>
<br>
&nbsp;&nbsp;Syntax
<pre>
#include &lt;net/if.h&gt;
void if_freenameindex(struct if_nameindex *ptr);
</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_freenameindex()</em></strong> function
frees the dynamic memory that was allocated by <strong><em>if_nameindex()</em></strong>.
After <strong><em>if_freenameindex()</em></strong> has been called,
the application should not use the array of which <em>ptr</em> is the address.
</p>
<br>
<h3><a name="Header_2">Parameters</a></h3>
<dl>
<dt><strong><em>ptr</em></strong> &nbsp;(Input)&nbsp;</dt>
<dd>Array of <em>if_nameindex</em> structures. <em>ptr</em> MUST be a
pointer that was returned by <strong><em>if_nameindex()</em></strong>.
<br><br>
<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 name */
};
</pre>
</dd></dl>
<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>None.</p>
<br>
<h3><a name="Header_5">Error Conditions</a></h3>
<p><em>errno</em> can be set to:</p>
<dl compact>
<dt><em>[DEFAULT]</em></dt>
<dd>The memory pointed to by <em>ptr</em> can not be accessed.</dd>
</dl>
<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_indextoname.htm">if_indextoname()--</a>Map an Interface Index to its
Corresponding Name</li>
<li><a href="if_nameindex.htm">if_nameindex()</a>--Return All Interface Names and Indexes</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_freenameindex()</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;
interfaceArray = if_nameindex(void); /* retrieve the current interfaces */
if (interfaceArray != NULL)
{
...
<strong>if_freenameindex(interfaceArray); /* free the dynamic memory */</strong>
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>