252 lines
6.2 KiB
HTML
252 lines
6.2 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of IF_NAMEINDEX</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>IF_NAMEINDEX</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
if_nameindex, if_freenameindex - get network interface names and indexes
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/net/if.h">net/if.h</A>></B>
|
|
|
|
<B>struct if_nameindex *if_nameindex(void);</B>
|
|
<B>void if_freenameindex(struct if_nameindex *</B><I>ptr</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>if_nameindex</B>()
|
|
|
|
function returns an array of
|
|
<I>if_nameindex</I>
|
|
|
|
structures, each containing information
|
|
about one of the network interfaces on the local system.
|
|
The
|
|
<I>if_nameindex</I>
|
|
|
|
structure contains at least the following entries:
|
|
<P>
|
|
|
|
|
|
|
|
unsigned int if_index; /* Index of interface (1, 2, ...) */
|
|
char *if_name; /* Null-terminated name ("eth0", etc.) */
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>if_index</I>
|
|
|
|
field contains the interface index.
|
|
The
|
|
<I>if_name</I>
|
|
|
|
field points to the null-terminated interface name.
|
|
The end of the array is indicated by entry with
|
|
<I>if_index</I>
|
|
|
|
set to zero and
|
|
<I>if_name</I>
|
|
|
|
set to NULL.
|
|
<P>
|
|
|
|
The data structure returned by
|
|
<B>if_nameindex</B>()
|
|
|
|
is dynamically allocated and should be freed using
|
|
<B>if_freenameindex</B>()
|
|
|
|
when no longer needed.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>if_nameindex</B>()
|
|
|
|
returns pointer to the array;
|
|
on error, NULL is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<B>if_nameindex</B>()
|
|
|
|
may fail and set
|
|
<I>errno</I>
|
|
|
|
if:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ENOBUFS</B>
|
|
|
|
<DD>
|
|
Insufficient resources available.
|
|
</DL>
|
|
<P>
|
|
|
|
<B>if_nameindex</B>()
|
|
|
|
may also fail for any of the errors specified for
|
|
<B><A HREF="/cgi-bin/man/man2html?2+socket">socket</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+bind">bind</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+ioctl">ioctl</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getsockname">getsockname</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+recvmsg">recvmsg</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sendto">sendto</A></B>(2),
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+malloc">malloc</A></B>(3).
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
The
|
|
<B>if_nameindex</B>()
|
|
|
|
function first appeared in glibc 2.1, but before glibc 2.3.4,
|
|
the implementation supported only interfaces with IPv4 addresses.
|
|
Support of interfaces that don't have IPv4 addresses is available only
|
|
on kernels that support netlink.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>if_nameindex</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>if_freenameindex</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, RFC 3493.
|
|
<P>
|
|
|
|
This function first appeared in BSDi.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below demonstrates the use of the functions described
|
|
on this page.
|
|
An example of the output this program might produce is the following:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>./a.out</B><I>
|
|
1: lo
|
|
2: wlan0
|
|
3: em1
|
|
|
|
|
|
</I><A NAME="lbAK"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/net/if.h">net/if.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> struct if_nameindex *if_ni, *i;
|
|
<P>
|
|
<BR> if_ni = if_nameindex();
|
|
<BR> if (if_ni == NULL) {
|
|
<BR> perror("if_nameindex");
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++)
|
|
<BR> printf("%u: %s\n", i->if_index, i->if_name);
|
|
<P>
|
|
<BR> if_freenameindex(if_ni);
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+getsockopt">getsockopt</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+setsockopt">setsockopt</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getifaddrs">getifaddrs</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+if_indextoname">if_indextoname</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+if_nametoindex">if_nametoindex</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+ifconfig">ifconfig</A></B>(8)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAK">Program source</A><DD>
|
|
</DL>
|
|
<DT id="12"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:46 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|