* [RFC] if_nameindex.3: New page documenting if_nameindex(3) and if_freenameindex(3)
@ 2012-11-16 17:28 YOSHIFUJI Hideaki
[not found] ` <201211161728.qAGHSMj0015535-3Be77hNiKzq6hyM1GC9nJ01gUKqpuoTTXqFh9Ls21Oc@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: YOSHIFUJI Hideaki @ 2012-11-16 17:28 UTC (permalink / raw)
To: linux-man-u79uwXL29TY76Z2rM5mHXA,
mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
Cc: yoshfuji-VfPWfsRibaP+Ru+s062T9g
Please review.
TODO: Check VERSIONS and HISTORY sections.
References:
RFC 3542
POSIX Man Page Set
http://www.unix.com/man-page/POSIX/3posix/if_indexname
http://www.unix.com/man-page/POSIX/3posix/if_freeindexname
OS X Deverloper Tools Manual Page
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man3/if_nameindex.3.html
Source: sysdeps/unix/sysv/linux/{if_index.c,ifaddrs.c}
YOSHIFUJI Hideaki <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org>
---
man3/if_nameindex.3 | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 man3/if_nameindex.3
diff --git a/man3/if_nameindex.3 b/man3/if_nameindex.3
new file mode 100644
index 0000000..60bfd39
--- /dev/null
+++ b/man3/if_nameindex.3
@@ -0,0 +1,110 @@
+.\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org>
+.\"
+.\" Permission is granted to make and distribute verbatim copies of this
+.\" manual provided the copyright notice and this permission notice are
+.\" preserved on all copies.
+.\"
+.\" Permission is granted to copy and distribute modified versions of
+.\" this manual under the conditions for verbatim copying, provided that
+.\" the entire resulting derived work is distributed under the terms of
+.\" a permission notice identical to this one.
+.\"
+.\" Since the Linux kernel and libraries are constantly changing, this
+.\" manual page may be incorrect or out-of-date. The author(s) assume.
+.\" no responsibility for errors or omissions, or for damages resulting.
+.\" from the use of the information contained herein. The author(s) may.
+.\" not have taken the same level of care in the production of this.
+.\" manual, which is licensed free of charge, as they might when working.
+.\" professionally.
+.\"
+.\" Formatted or processed versions of this manual, if unaccompanied by
+.\" the source, must acknowledge the copyright and authors of this work.
+.\"
+.TH IF_NAMEINDEX 3 2012-11-16 "GNU" "Linux Programmer's Manual"
+.SH NAME
+if_nameindex, if_freenameindex \- get network interface names and indexes
+.SH SYNOPSIS
+.nf
+.B #include <net/if.h>
+.sp
+.BI "struct if_nameindex *if_nameindex(void);
+.BI "void if_freenameindex(struct if_nameindex *" "ptr" );
+.fi
+.SH DESCRIPTION
+The
+.BR if_nameindex ()
+function creates an array of structures, one structure per
+interface, each describing network interface name and
+corresponding network index of the local system.
+
+The
+.I if_nameindex
+structure contains at least the following entries:
+.sp
+.in +4n
+.nf
+ unsigned int if_index; /* 1, 2, ... */
+ char *if_name; /* null terminated name: "eth0", ... */
+.fi
+.in
+.PP
+The
+.I if_index
+field contains the interface index,
+or zero if this is the last item of the array.
+.PP
+The
+.I ifa_name
+field points to the null-terminated interface name,
+or NULL pointer if this is the last item of the array.
+.PP
+The data returned by
+.BR if_nameindex ()
+is dynamically allocated and should be freed using
+.BR if_freenameindex ()
+when no longer needed.
+.SH RETURN VALUE
+On success,
+.BR if_nameindex ()
+returns pointer to the array;
+on error, A NULL pointer is returned, and
+.I errno
+is set appropriately.
+.SH ERRORS
+.BR if_nameindex ()
+may fail and set
+.I errno
+if:
+.TP
+.B ENOBUFS
+Sufficient resources unavailable.
+.PP
+.BR if_nameindex ()
+may also fail for any of the errors specified for
+.BR socket (2),
+.BR bind (2),
+.BR ioctl (2),
+.BR getsockname (2),
+.BR recvmsg (2),
+.BR sendto (2),
+or
+.BR malloc (3).
+.SH VERSIONS
+The
+.BR if_nameindex ()
+function first appeared in glibc 2.3, but before glibc 2.3.3,
+the implementation only supported interfaces with IPv4 addresses.
+Support of interfaces without IPv4 addresses is only available
+on kernels that support netlink.
+.SH CONFORMING TO
+RFC\ 3493, POSIX.1-2001.
+.SH HISTORY
+This function first appeared in BSDi.
+.SH SEE ALSO
+.BR getsockopt (2),
+.BR setsockopt (2),
+.BR getifaddrs (3),
+.BR if_indextoname (3),
+.BR if_nameindex (3),
+.BR if_nametoindex (3),
+.BR ifconfig (8)
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread[parent not found: <201211161728.qAGHSMj0015535-3Be77hNiKzq6hyM1GC9nJ01gUKqpuoTTXqFh9Ls21Oc@public.gmane.org>]
* Re: [RFC] if_nameindex.3: New page documenting if_nameindex(3) and if_freenameindex(3) [not found] ` <201211161728.qAGHSMj0015535-3Be77hNiKzq6hyM1GC9nJ01gUKqpuoTTXqFh9Ls21Oc@public.gmane.org> @ 2012-11-22 4:40 ` Michael Kerrisk (man-pages) [not found] ` <CAKgNAkgJ28rsi4fLb_afX=mdfhsYvAm3H_k0qHpihoTfNFF0og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Michael Kerrisk (man-pages) @ 2012-11-22 4:40 UTC (permalink / raw) To: YOSHIFUJI Hideaki; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 4363 bytes --] On Fri, Nov 16, 2012 at 6:28 PM, YOSHIFUJI Hideaki <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> wrote: > Please review. Thanks Hideaki. I've merged this into a branch, made a number of fixes, and added an example program. Could you check my changes in the diff below. (The complete page is attached.) Cheers, Michael diff --git a/man3/if_nameindex.3 b/man3/if_nameindex.3 index 60bfd39..23eaa5a 100644 --- a/man3/if_nameindex.3 +++ b/man3/if_nameindex.3 @@ -1,4 +1,5 @@ .\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> +.\" and Copyright (c) 2012 Michael Kerrisk <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are @@ -20,7 +21,7 @@ .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" -.TH IF_NAMEINDEX 3 2012-11-16 "GNU" "Linux Programmer's Manual" +.TH IF_NAMEINDEX 3 2012-11-21 "GNU" "Linux Programmer's Manual" .SH NAME if_nameindex, if_freenameindex \- get network interface names and indexes .SH SYNOPSIS @@ -33,32 +34,34 @@ if_nameindex, if_freenameindex \- get network interface names and indexes .SH DESCRIPTION The .BR if_nameindex () -function creates an array of structures, one structure per -interface, each describing network interface name and -corresponding network index of the local system. - +function returns an array of +.I if_nameindex +structures, each containing information +about one of the network interfaces on the local system. The .I if_nameindex structure contains at least the following entries: .sp .in +4n .nf - unsigned int if_index; /* 1, 2, ... */ - char *if_name; /* null terminated name: "eth0", ... */ + unsigned int if_index; /* Index of interface (1, 2, ...) */ + char *if_name; /* Null-terminated name ("eth0", etc.) */ .fi .in .PP The .I if_index -field contains the interface index, -or zero if this is the last item of the array. -.PP +field contains the interface index. The .I ifa_name -field points to the null-terminated interface name, -or NULL pointer if this is the last item of the array. +field points to the null-terminated interface name. +The end of the array is indicated by entry with +.I if_index +set to zero and +.I ifa_name +set to NULL. .PP -The data returned by +The data structure returned by .BR if_nameindex () is dynamically allocated and should be freed using .BR if_freenameindex () @@ -67,7 +70,7 @@ when no longer needed. On success, .BR if_nameindex () returns pointer to the array; -on error, A NULL pointer is returned, and +on error, a NULL pointer is returned, and .I errno is set appropriately. .SH ERRORS @@ -77,7 +80,7 @@ may fail and set if: .TP .B ENOBUFS -Sufficient resources unavailable. +Insufficient resources unavailable. .PP .BR if_nameindex () may also fail for any of the errors specified for @@ -92,13 +95,51 @@ or .SH VERSIONS The .BR if_nameindex () -function first appeared in glibc 2.3, but before glibc 2.3.3, +function first appeared in glibc 2.1, but before glibc 2.3.4, the implementation only supported interfaces with IPv4 addresses. -Support of interfaces without IPv4 addresses is only available +Support of interfaces that don't have IPv4 addresses is only available on kernels that support netlink. +.SH EXAMPLE +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: +.in +4n +.nf +$ \fB./a.out\fI +1: lo +2: wlan0 +3: em1 +.fi +.in +.SS Program source +.nf +#include <net/if.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + struct if_nameindex *if_ni, *i; + + if_ni = if_nameindex(); + if (if_ni == NULL) { + perror("if_nameindex"); + exit(EXIT_FAILURE); + } + + for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++) + printf("%d: %s\\n", i\->if_index, i\->if_name); + + if_freenameindex(if_ni); + + exit(EXIT_SUCCESS); +} +.fi .SH CONFORMING TO RFC\ 3493, POSIX.1-2001. -.SH HISTORY + This function first appeared in BSDi. .SH SEE ALSO .BR getsockopt (2), [-- Attachment #2: if_nameindex.3 --] [-- Type: application/octet-stream, Size: 3951 bytes --] .\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> .\" and Copyright (c) 2012 Michael Kerrisk <mtk.manpages@gmail.com> .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of .\" this manual under the conditions for verbatim copying, provided that .\" the entire resulting derived work is distributed under the terms of .\" a permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume. .\" no responsibility for errors or omissions, or for damages resulting. .\" from the use of the information contained herein. The author(s) may. .\" not have taken the same level of care in the production of this. .\" manual, which is licensed free of charge, as they might when working. .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .TH IF_NAMEINDEX 3 2012-11-21 "GNU" "Linux Programmer's Manual" .SH NAME if_nameindex, if_freenameindex \- get network interface names and indexes .SH SYNOPSIS .nf .B #include <net/if.h> .sp .BI "struct if_nameindex *if_nameindex(void); .BI "void if_freenameindex(struct if_nameindex *" "ptr" ); .fi .SH DESCRIPTION The .BR if_nameindex () function returns an array of .I if_nameindex structures, each containing information about one of the network interfaces on the local system. The .I if_nameindex structure contains at least the following entries: .sp .in +4n .nf unsigned int if_index; /* Index of interface (1, 2, ...) */ char *if_name; /* Null-terminated name ("eth0", etc.) */ .fi .in .PP The .I if_index field contains the interface index. The .I ifa_name field points to the null-terminated interface name. The end of the array is indicated by entry with .I if_index set to zero and .I ifa_name set to NULL. .PP The data structure returned by .BR if_nameindex () is dynamically allocated and should be freed using .BR if_freenameindex () when no longer needed. .SH RETURN VALUE On success, .BR if_nameindex () returns pointer to the array; on error, a NULL pointer is returned, and .I errno is set appropriately. .SH ERRORS .BR if_nameindex () may fail and set .I errno if: .TP .B ENOBUFS Insufficient resources unavailable. .PP .BR if_nameindex () may also fail for any of the errors specified for .BR socket (2), .BR bind (2), .BR ioctl (2), .BR getsockname (2), .BR recvmsg (2), .BR sendto (2), or .BR malloc (3). .SH VERSIONS The .BR if_nameindex () function first appeared in glibc 2.1, but before glibc 2.3.4, the implementation only supported interfaces with IPv4 addresses. Support of interfaces that don't have IPv4 addresses is only available on kernels that support netlink. .SH EXAMPLE 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: .in +4n .nf $ \fB./a.out\fI 1: lo 2: wlan0 3: em1 .fi .in .SS Program source .nf #include <net/if.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char *argv[]) { struct if_nameindex *if_ni, *i; if_ni = if_nameindex(); if (if_ni == NULL) { perror("if_nameindex"); exit(EXIT_FAILURE); } for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++) printf("%d: %s\\n", i\->if_index, i\->if_name); if_freenameindex(if_ni); exit(EXIT_SUCCESS); } .fi .SH CONFORMING TO RFC\ 3493, POSIX.1-2001. This function first appeared in BSDi. .SH SEE ALSO .BR getsockopt (2), .BR setsockopt (2), .BR getifaddrs (3), .BR if_indextoname (3), .BR if_nameindex (3), .BR if_nametoindex (3), .BR ifconfig (8) ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <CAKgNAkgJ28rsi4fLb_afX=mdfhsYvAm3H_k0qHpihoTfNFF0og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: [RFC] if_nameindex.3: New page documenting if_nameindex(3) and if_freenameindex(3) [not found] ` <CAKgNAkgJ28rsi4fLb_afX=mdfhsYvAm3H_k0qHpihoTfNFF0og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2012-11-29 11:07 ` YOSHIFUJI Hideaki [not found] ` <50B741DB.3060808-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: YOSHIFUJI Hideaki @ 2012-11-29 11:07 UTC (permalink / raw) To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, linux-man-u79uwXL29TY76Z2rM5mHXA Cc: YOSHIFUJI Hideaki Hi, Michael. Michael Kerrisk (man-pages) wrote: > On Fri, Nov 16, 2012 at 6:28 PM, YOSHIFUJI Hideaki > <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> wrote: >> Please review. > > Thanks Hideaki. > > I've merged this into a branch, made a number of fixes, and added an > example program. Could you check my changes in the diff below. (The > complete page is attached.) > + for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++) > + printf("%d: %s\\n", i\->if_index, i\->if_name); Since type of if_index is unsigned int, please use %u here. Thanks. --yoshfuji -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <50B741DB.3060808-VfPWfsRibaP+Ru+s062T9g@public.gmane.org>]
* Re: [RFC] if_nameindex.3: New page documenting if_nameindex(3) and if_freenameindex(3) [not found] ` <50B741DB.3060808-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> @ 2012-12-13 4:20 ` Michael Kerrisk (man-pages) 0 siblings, 0 replies; 4+ messages in thread From: Michael Kerrisk (man-pages) @ 2012-12-13 4:20 UTC (permalink / raw) To: YOSHIFUJI Hideaki; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA On Thu, Nov 29, 2012 at 12:07 PM, YOSHIFUJI Hideaki <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> wrote: > Hi, Michael. > > Michael Kerrisk (man-pages) wrote: >> On Fri, Nov 16, 2012 at 6:28 PM, YOSHIFUJI Hideaki >> <yoshfuji-VfPWfsRibaP+Ru+s062T9g@public.gmane.org> wrote: >>> Please review. >> >> Thanks Hideaki. >> >> I've merged this into a branch, made a number of fixes, and added an >> example program. Could you check my changes in the diff below. (The >> complete page is attached.) > >> + for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++) >> + printf("%d: %s\\n", i\->if_index, i\->if_name); > > Since type of if_index is unsigned int, please use %u here. > Thanks. Thanks. Fixed! Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface"; http://man7.org/tlpi/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-12-13 4:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-16 17:28 [RFC] if_nameindex.3: New page documenting if_nameindex(3) and if_freenameindex(3) YOSHIFUJI Hideaki
[not found] ` <201211161728.qAGHSMj0015535-3Be77hNiKzq6hyM1GC9nJ01gUKqpuoTTXqFh9Ls21Oc@public.gmane.org>
2012-11-22 4:40 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkgJ28rsi4fLb_afX=mdfhsYvAm3H_k0qHpihoTfNFF0og-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-11-29 11:07 ` YOSHIFUJI Hideaki
[not found] ` <50B741DB.3060808-VfPWfsRibaP+Ru+s062T9g@public.gmane.org>
2012-12-13 4:20 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox