* [PATCH] getifaddrs.3: New manual page
@ 2008-12-09 2:56 Petr Baudis
[not found] ` <20081209025634.GD10491-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Petr Baudis @ 2008-12-09 2:56 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
This patch adds documentation for the getifaddrs() and freeifaddrs()
functions as they are supported in GNU libc. The manual page is based
on the original BSD manpage (with licence as it appears on the top
of the file), but is significantly rewritten for Linux manpages
standards and containing all the differences. A simple example is
provided.
I'm open to relicensing to any of the standard licences, this one
should be compatible even with the classic BSD licence.
I did not do actually any testing on BSD systems about how exactly
this call behaves, I have only tried to figure this out from their
chaotic documentation and it wouldn't surprise me if it would in
fact behave the same as with glibc now. I cannot remember hostnames
of the BSD systems I used to have an account on. ;-)
Few pages are cross-linked to point at getifaddrs(3) now, and
inet_ntop() got another example pointer.
Signed-off-by: Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
---
I will understand if you choose to remove my BUGS note in inet_ntop().
;-)
By the way, it is real pain to find resources like the list of standard
licences on the web page... you just remember you have seen it once but
to click through to it again is a challenge.
diff --git a/man2/bind.2 b/man2/bind.2
index 67a2fcf..7e84e45 100644
--- a/man2/bind.2
+++ b/man2/bind.2
@@ -321,6 +321,7 @@ main(int argc, char *argv[])
.BR listen (2),
.BR socket (2),
.BR getaddrinfo (3),
+.BR getifaddrs (3),
.BR ip (7),
.BR ipv6 (7),
.BR path_resolution (7),
diff --git a/man2/getsockname.2 b/man2/getsockname.2
index 0f4ccb3..cab1bbe 100644
--- a/man2/getsockname.2
+++ b/man2/getsockname.2
@@ -110,6 +110,7 @@ See also
.SH "SEE ALSO"
.BR bind (2),
.BR socket (2),
+.BR getifaddrs (3),
.BR ip (7),
.BR socket (7),
.BR unix (7)
diff --git a/man3/freeifaddrs.3 b/man3/freeifaddrs.3
new file mode 100644
index 0000000..a9d5317
--- /dev/null
+++ b/man3/freeifaddrs.3
@@ -0,0 +1 @@
+man3/getifaddrs.3
diff --git a/man3/getifaddrs.3 b/man3/getifaddrs.3
new file mode 100644
index 0000000..9e51126
--- /dev/null
+++ b/man3/getifaddrs.3
@@ -0,0 +1,231 @@
+.\"
+.\" Copyright (c) 1995, 1999
+.\" Berkeley Software Design, Inc. All rights reserved.
+.\" Copyright (c) 2008 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" 2008-12-08 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
+.\" Rewrite the BSD manpage in the Linux man pages style and account
+.\" for glibc specificities, provide an example.
+.\"
+.TH GETIFADDRS 3 2008-12-08 "GNU" "Linux Programmer's Manual"
+.SH NAME
+getifaddrs, freeifaddrs \- get interface addresses
+.SH SYNOPSIS
+.nf
+.B #include <sys/types.h>
+.B #include <ifaddrs.h>
+.sp
+.BI "int getifaddrs(struct ifaddrs **" "ifap" );
+.sp
+.BI "void freeifaddrs(struct ifaddrs *" "ifa" );
+.fi
+.SH DESCRIPTION
+The
+.BR getifaddrs ()
+function creates a linked list of addresses assigned to the network
+interfaces on the local system and stores its reference in a pointer
+variable referenced by
+.IR ifap .
+The list consists of
+.I ifaddrs
+structures, where each contains the following fields:
+.sp
+.in +4n
+.nf
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ u_int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ union {
+ struct sockaddr *ifu_broadaddr;
+ struct sockaddr *ifu_dstaddr;
+ } ifa_ifu;
+ #define ifa_broadaddr ifa_ifu.ifu_broadaddr
+ #define ifa_dstaddr ifa_ifu.ifu_dstaddr
+ void *ifa_data;
+};
+.fi
+.in
+.PP
+The
+.I ifa_next
+field contains a pointer to the next structure on the list,
+or NULL within the last item of the list.
+.PP
+The
+.I ifa_name
+field contains the interface name.
+.PP
+The
+.I ifa_flags
+field contains the interface flags, as returned by the
+.B SIOCGIFFLAGS
+ioctl (see
+.BR netdevice (7)
+for a list).
+.PP
+The
+.I ifa_addr
+field references the particular interface address.
+(The
+.I sa_family
+sub-field should be consulted to determine the format of the address.)
+.PP
+The
+.I ifa_netmask
+field references the netmask associated with
+.IR ifa_addr ,
+if applicable for the address family.
+.PP
+Depending on whether the bit
+.B IFF_BROADCAST
+or
+.B IFF_POINTOPOINT
+is set in
+.I ifa_flags
+(only one can be set at a time),
+either
+.I ifa_broadaddr
+will contain the broadcast address associated with
+.I ifa_addr
+(if applicable for the address family) or
+.I ifa_dstaddr
+will contain the destination address of the point-to-point interface.
+.PP
+The
+.I ifa_data
+field can reference address family specific data (may be NULL).
+.PP
+The data returned by
+.BR getifaddrs ()
+is dynamically allocated and should be freed using
+.BR freeifaddrs ()
+when no longer needed.
+.SH RETURN VALUES
+On success, zero is returned. On error, -1 is returned, and
+.I errno
+is set appropriately.
+.SH ERRORS
+The
+.BR getifaddrs ()
+may fail and set
+.B errno
+for any of the errors specified for the library routines
+.BR socket (2),
+.BR bind (2),
+.BR sendto (2),
+.BR malloc (3)
+or
+.BR realloc (3).
+.SH CONFORMING TO
+Not in POSIX.1-2001. This function first appeared in BSDi and is
+present on the BSD systems, but with a slightly different
+semantics documented - returning one entry per interface, not per address.
+This means
+.I ifa_addr
+and other fields can be actually NULL if the interface has no address,
+and no link-level address returned if the interface has an IP address
+assigned. Also, the way of choosing either
+.I ifa_broadaddr
+or
+.I ifa_dstaddr
+differs on various sytems, but the BSD-derived documentation generally
+appears to be confused and obsolete on this point.
+.\" i.e. commonly it still says one of them will be NULL, even if
+.\" the ifa_ifu union is already present
+
+The function first appeared in GNU libc 2.3, but supported only IPv4
+addresses until GNU libc 2.3.3.
+.SH NOTES
+The addresses returned on Linux will be usually the IPv4 and IPv6 addresses
+assigned to the interface, but also one
+.B AF_PACKET
+address per interface containing lower-level details about the interface
+and its physical layer. In this case, the
+.I ifa_data
+field may contain a pointer to the
+.I struct net_device_stats
+as defined in
+.B <linux/netdevice.h>
+which contains various interface attributes and statistics.
+.SH EXAMPLE
+The program below demonstrates the use of
+.BR getifaddrs (),
+.BR freeifaddrs (),
+and
+.BR inet_ntop (3).
+Here is an example output:
+.in
+\&
+.nf
+[lo] family 17, see <bits/socket.h>
+[eth0] family 17, see <bits/socket.h>
+[eth1] family 17, see <bits/socket.h>
+[lo] 127.0.0.1
+[lo] 127.0.0.2
+[eth1] 192.168.6.4
+[lo] ::1
+[eth1] fe80::213:ceff:fee5:da26
+.fi
+.in
+.SS Program source
+\&
+.nf
+#include <arpa/inet.h>
+#include <ifaddrs.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ struct ifaddrs *ifaddr;
+ if (getifaddrs(&ifaddr) < 0) {
+ perror("getifaddrs");
+ return EXIT_FAILURE;
+ }
+ while (ifaddr) {
+ char buf[256];
+ snprintf(buf, sizeof(buf), "family %d, see <bits/socket.h>",
+ ifaddr->ifa_addr->sa_family);
+ if (ifaddr->ifa_addr->sa_family == AF_INET) {
+ inet_ntop(AF_INET, &((struct sockaddr_in *)
+ ifaddr->ifa_addr)->sin_addr,
+ buf, sizeof(buf));
+ } else if (ifaddr->ifa_addr->sa_family == AF_INET6) {
+ inet_ntop(AF_INET6, &((struct sockaddr_in6 *)
+ ifaddr->ifa_addr)->sin6_addr,
+ buf, sizeof(buf));
+ }
+ printf("[%s] %s\\n", ifaddr->ifa_name, buf);
+ ifaddr = ifaddr->ifa_next;
+ }
+ freeifaddrs(ifaddr);
+ return EXIT_SUCCESS;
+}
+.fi
+.SH SEE ALSO
+.BR bind (2),
+.BR getsockname (2),
+.BR socket (2),
+.BR packet (7),
+.BR ifconfig (8)
diff --git a/man3/inet_ntop.3 b/man3/inet_ntop.3
index 7de0ffa..e93f51c 100644
--- a/man3/inet_ntop.3
+++ b/man3/inet_ntop.3
@@ -110,8 +110,13 @@ but 2.2 and later have
.SH BUGS
.B AF_INET6
converts IPv4-mapped IPv6 addresses into an IPv6 format.
+
+The interface is painful to use since it does not operate on
+sockaddrs, as apparent from the first example.
.SH EXAMPLE
See
+.BR getifaddrs (3)
+and
.BR inet_pton (3).
.SH "SEE ALSO"
.BR getnameinfo (3),
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <20081209025634.GD10491-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
@ 2009-01-13 17:09 ` Petr Baudis
2009-01-14 10:24 ` Michael Kerrisk
2009-01-14 11:55 ` Michael Kerrisk
2 siblings, 0 replies; 7+ messages in thread
From: Petr Baudis @ 2009-01-13 17:09 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
Hi,
On Tue, Dec 09, 2008 at 03:56:34AM +0100, Petr Baudis wrote:
> This patch adds documentation for the getifaddrs() and freeifaddrs()
> functions as they are supported in GNU libc. The manual page is based
> on the original BSD manpage (with licence as it appears on the top
> of the file), but is significantly rewritten for Linux manpages
> standards and containing all the differences. A simple example is
> provided.
>
> I'm open to relicensing to any of the standard licences, this one
> should be compatible even with the classic BSD licence.
>
> I did not do actually any testing on BSD systems about how exactly
> this call behaves, I have only tried to figure this out from their
> chaotic documentation and it wouldn't surprise me if it would in
> fact behave the same as with glibc now. I cannot remember hostnames
> of the BSD systems I used to have an account on. ;-)
>
> Few pages are cross-linked to point at getifaddrs(3) now, and
> inet_ntop() got another example pointer.
>
> Signed-off-by: Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
ping? :-)
Petr "Pasky" Baudis
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <20081209025634.GD10491-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
2009-01-13 17:09 ` Petr Baudis
@ 2009-01-14 10:24 ` Michael Kerrisk
2009-01-14 11:55 ` Michael Kerrisk
2 siblings, 0 replies; 7+ messages in thread
From: Michael Kerrisk @ 2009-01-14 10:24 UTC (permalink / raw)
To: Petr Baudis; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
Hi Petr,
Petr Baudis wrote:
> This patch adds documentation for the getifaddrs() and freeifaddrs()
> functions as they are supported in GNU libc.
Thanks for this. I already sent you my revision of this page.
I've committed that page for the upcoming 3.17 release, which
will still be a few days away, which will allow time for you
to send me any fixes you think may be required.
> The manual page is based
> on the original BSD manpage (with licence as it appears on the top
> of the file), but is significantly rewritten for Linux manpages
> standards and containing all the differences.
I made a lot of edits to your page. Between your work and my
work, I think there is little if any BSD content left in the page,
so:
* I've removed the BSD copyright line
* Added Linux Foundation/Michael Kerrisk to the copyright
* Changed the license to the verbatim license -- but if you
would like a different license, let me know.
> A simple example is
> provided.
As noted, I rewrote the example program.
> I'm open to relicensing to any of the standard licences, this one
> should be compatible even with the classic BSD licence.
See above.
> I did not do actually any testing on BSD systems about how exactly
> this call behaves, I have only tried to figure this out from their
> chaotic documentation and it wouldn't surprise me if it would in
> fact behave the same as with glibc now. I cannot remember hostnames
> of the BSD systems I used to have an account on. ;-)
Okay.
> Few pages are cross-linked to point at getifaddrs(3) now, and
> inet_ntop() got another example pointer.
Some further comments below.
> diff --git a/man2/bind.2 b/man2/bind.2
> index 67a2fcf..7e84e45 100644
> --- a/man2/bind.2
> +++ b/man2/bind.2
> @@ -321,6 +321,7 @@ main(int argc, char *argv[])
> .BR listen (2),
> .BR socket (2),
> .BR getaddrinfo (3),
> +.BR getifaddrs (3),
Applied.
> .BR ip (7),
> .BR ipv6 (7),
> .BR path_resolution (7),
> diff --git a/man2/getsockname.2 b/man2/getsockname.2
> index 0f4ccb3..cab1bbe 100644
> --- a/man2/getsockname.2
> +++ b/man2/getsockname.2
> @@ -110,6 +110,7 @@ See also
> .SH "SEE ALSO"
> .BR bind (2),
> .BR socket (2),
> +.BR getifaddrs (3),
Applied.
> .BR ip (7),
> .BR socket (7),
> .BR unix (7)
> diff --git a/man3/freeifaddrs.3 b/man3/freeifaddrs.3
> new file mode 100644
> index 0000000..a9d5317
> --- /dev/null
> +++ b/man3/freeifaddrs.3
> @@ -0,0 +1 @@
> +man3/getifaddrs.3
I think you meant
.so man3/getifaddrs.3
here.
Applied.
> diff --git a/man3/getifaddrs.3 b/man3/getifaddrs.3
> new file mode 100644
> index 0000000..9e51126
...
Covered in another mail.
> --- a/man3/inet_ntop.3
> +++ b/man3/inet_ntop.3
> @@ -110,8 +110,13 @@ but 2.2 and later have
> .SH BUGS
> .B AF_INET6
> converts IPv4-mapped IPv6 addresses into an IPv6 format.
> +
> +The interface is painful to use since it does not operate on
> +sockaddrs, as apparent from the first example.
> .SH EXAMPLE
> See
> +.BR getifaddrs (3)
> +and
> .BR inet_pton (3).
> .SH "SEE ALSO"
> .BR getnameinfo (3),
Not applied, since the example program I added uses getnameinfo() instead.
Thanks for all of this work Petr!
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <20081209025634.GD10491-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
2009-01-13 17:09 ` Petr Baudis
2009-01-14 10:24 ` Michael Kerrisk
@ 2009-01-14 11:55 ` Michael Kerrisk
[not found] ` <cfd18e0f0901140355j6758cb29i5b356667aedc467-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2 siblings, 1 reply; 7+ messages in thread
From: Michael Kerrisk @ 2009-01-14 11:55 UTC (permalink / raw)
To: Petr Baudis; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
Hello Petr,
On Tue, Dec 9, 2008 at 3:56 PM, Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org> wrote:
> This patch adds documentation for the getifaddrs() and freeifaddrs()
> functions as they are supported in GNU libc. The manual page is based
> on the original BSD manpage (with licence as it appears on the top
> of the file), but is significantly rewritten for Linux manpages
> standards and containing all the differences. A simple example is
> provided.
I've taken your page and done some heavy editing, including rewriting
the example program.
> I'm open to relicensing to any of the standard licences, this one
> should be compatible even with the classic BSD licence.
By now, I think little, if any, of the BSD page remains. I'd be
inclined to switch to the verbatim license? Okay with you?
> I did not do actually any testing on BSD systems about how exactly
> this call behaves, I have only tried to figure this out from their
> chaotic documentation and it wouldn't surprise me if it would in
> fact behave the same as with glibc now. I cannot remember hostnames
> of the BSD systems I used to have an account on. ;-)
>
> Few pages are cross-linked to point at getifaddrs(3) now, and
> inet_ntop() got another example pointer.
In my example program, getnameinfo() is used, rather than inet_ntop().
> Signed-off-by: Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
>
> ---
>
> I will understand if you choose to remove my BUGS note in inet_ntop().
> ;-)
>
> By the way, it is real pain to find resources like the list of standard
> licences on the web page... you just remember you have seen it once but
> to click through to it again is a challenge.
Thanks for noting that. I will add another link on the web site, to help this.
My revised version of the page below. Could you take a look please.
Cheers,
Michael
.\" Copyright (c) 1995, 1999
.\" Berkeley Software Design, Inc. All rights reserved.
.\" Copyright (c) 2008 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
.\" and copyright (c) 2009, Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" 2008-12-08 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
.\" Rewrite the BSD manpage in the Linux man pages style and account
.\" for glibc specificities, provide an example.
.\" 2009-01-14 mtk, many edits and changes, rewrote example program.
.\"
.TH GETIFADDRS 3 2009-01-14 "GNU" "Linux Programmer's Manual"
.SH NAME
getifaddrs, freeifaddrs \- get interface addresses
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <ifaddrs.h>
.sp
.BI "int getifaddrs(struct ifaddrs **" "ifap" );
.sp
.BI "void freeifaddrs(struct ifaddrs *" "ifa" );
.fi
.SH DESCRIPTION
The
.BR getifaddrs ()
function creates a linked list of structures describing
the network interfaces of the local system,
and stores the address of the first item of the list in
.IR *ifap .
The list consists of
.I ifaddrs
structures, defined as follows:
.sp
.in +4n
.nf
struct ifaddrs {
struct ifaddrs *ifa_next; /* Next item in list */
char *ifa_name; /* Name of interface */
unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */
struct sockaddr *ifa_addr; /* Address of interface */
struct sockaddr *ifa_netmask; /* Netmask of interface */
union {
struct sockaddr *ifu_broadaddr;
/* Broadcast address of interface */
struct sockaddr *ifu_dstaddr;
/* Point-to-point destination address */
} ifa_ifu;
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
void *ifa_data; /* Address-specific data */
};
.fi
.in
.PP
The
.I ifa_next
field contains a pointer to the next structure on the list,
or NULL if this is the last item of the list.
.PP
The
.I ifa_name
points to the null-terminated interface name.
.\" The constant
.\" .B IF NAMESIZE
.\" indicates the maximum length of this field.
.PP
The
.I ifa_flags
field contains the interface flags, as returned by the
.B SIOCGIFFLAGS
.BR ioctl (2)
operation (see
.BR netdevice (7)
for a list of these flags).
.PP
The
.I ifa_addr
field points to a structure containing the interface address.
(The
.I sa_family
sub-field should be consulted to determine the format of the
address structure.)
.PP
The
.I ifa_netmask
field points to a structure containing the netmask associated with
.IR ifa_addr ,
if applicable for the address family.
.PP
Depending on whether the bit
.B IFF_BROADCAST
or
.B IFF_POINTOPOINT
is set in
.I ifa_flags
(only one can be set at a time),
either
.I ifa_broadaddr
will contain the broadcast address associated with
.I ifa_addr
(if applicable for the address family) or
.I ifa_dstaddr
will contain the destination address of the point-to-point interface.
.PP
The
.I ifa_data
field points to a buffer containing address-family-specific data;
this field may be NULL if there is no such data for this interface.
.PP
The data returned by
.BR getifaddrs ()
is dynamically allocated and should be freed using
.BR freeifaddrs ()
when no longer needed.
.SH RETURN VALUES
On success,
.BR getifaddrs ()
returns zero;
on error, -1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.BR getifaddrs ()
may fail and set
.I errno
for any of the errors specified for
.BR socket (2),
.BR bind (2),
.\" FIXME Petr, I added getsockname() and recvmsg(); do you agree?
.BR getsockname (2),
.BR recvmsg (2),
.BR sendto (2),
.BR malloc (3),
or
.BR realloc (3).
.SH VERSIONS
The
.BR getifaddrs ()
function first appeared in glibc 2.3, but before glibc 2.3.3,
the implementation only supported IPv4 addresses;
IPv6 support was added in glibc 2.3.3.
.SH CONFORMING TO
Not in POSIX.1-2001.
This function first appeared in BSDi and is
present on the BSD systems, but with slightly different
semantics documented\(emreturning one entry per interface,
not per address.
This means
.I ifa_addr
and other fields can actually be NULL if the interface has no address,
and no link-level address is returned if the interface has an IP address
assigned.
Also, the way of choosing either
.I ifa_broadaddr
or
.I ifa_dstaddr
differs on various sytems.
.\" , but the BSD-derived documentation generally
.\" appears to be confused and obsolete on this point.
.\" i.e., commonly it still says one of them will be NULL, even if
.\" the ifa_ifu union is already present
.SH NOTES
The addresses returned on Linux will usually be the IPv4 and IPv6 addresses
assigned to the interface, but also one
.B AF_PACKET
address per interface containing lower-level details about the interface
and its physical layer.
In this case, the
.I ifa_data
field may contain a pointer to a
.IR "struct net_device_stats" ,
defined in
.IR <linux/netdevice.h> ,
which contains various interface attributes and statistics.
.SH EXAMPLE
The program below demonstrates the use of
.BR getifaddrs (),
.BR freeifaddrs (),
and
.BR inet_ntop (3).
Here is what we see when running this program on one system:
.in +4n
.nf
$ \fB./a.out\fP
lo address family: 17 (AF_PACKET)
eth0 address family: 17 (AF_PACKET)
lo address family: 2 (AF_INET)
address: <127.0.0.1>
eth0 address family: 2 (AF_INET)
address: <10.1.1.4>
lo address family: 10 (AF_INET6)
address: <::1>
eth0 address family: 10 (AF_INET6)
address: <fe80::2d0:59ff:feda:eb51%eth0>
.fi
.in
.SS Program source
\&
.nf
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
struct ifaddrs *ifaddr;
struct net_device_stats *ndsp;
int family, s;
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == \-1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
while (ifaddr != NULL) { /* Walk through linked list */
family = ifaddr\->ifa_addr\->sa_family;
/* Display interface name and family (including symbolic
form of the latter for the common families) */
printf("%\-6s address family: %d%s\\n",
ifaddr\->ifa_name, family,
(family == AF_PACKET) ? " (AF_PACKET)" :
(family == AF_INET) ? " (AF_INET)" :
(family == AF_INET6) ? " (AF_INET6)" : "");
/* For an AF_INET* interface address, display the address */
if (family == AF_INET || family == AF_INET6) {
s = getnameinfo(ifaddr\->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("getnameinfo() failed: %s\\n", gai_strerror(s));
exit(EXIT_FAILURE);
}
printf("\\taddress: <%s>\\n", host);
}
ifaddr = ifaddr\->ifa_next;
}
freeifaddrs(ifaddr);
exit(EXIT_SUCCESS);
}
.fi
.SH SEE ALSO
.BR bind (2),
.BR getsockname (2),
.BR socket (2),
.BR packet (7),
.BR ifconfig (8)
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <cfd18e0f0901140355j6758cb29i5b356667aedc467-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2009-01-14 23:27 ` Michael Kerrisk
[not found] ` <cfd18e0f0901141527g4518e063p642d0a4464c9804d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Michael Kerrisk @ 2009-01-14 23:27 UTC (permalink / raw)
To: Petr Baudis
Cc: Wichmann, Mats D,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
[CC += "Wichmann, Mats D" <mats.d.wichmann-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>]
Hello Petr,
On Tue, Dec 9, 2008 at 3:56 PM, Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org> wrote:
> This patch adds documentation for the getifaddrs() and freeifaddrs()
> functions as they are supported in GNU libc. The manual page is based
> on the original BSD manpage (with licence as it appears on the top
> of the file), but is significantly rewritten for Linux manpages
> standards and containing all the differences. A simple example is
> provided.
I've taken your page and done some heavy editing, including rewriting
the example program.
> I'm open to relicensing to any of the standard licences, this one
> should be compatible even with the classic BSD licence.
By now, I think little, if any, of the BSD page remains. I'd be
inclined to switch to the verbatim license? Okay with you?
> I did not do actually any testing on BSD systems about how exactly
> this call behaves, I have only tried to figure this out from their
> chaotic documentation and it wouldn't surprise me if it would in
> fact behave the same as with glibc now. I cannot remember hostnames
> of the BSD systems I used to have an account on. ;-)
>
> Few pages are cross-linked to point at getifaddrs(3) now, and
> inet_ntop() got another example pointer.
In my example program, getnameinfo() is used, rather than inet_ntop().
> Signed-off-by: Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
>
> ---
>
> I will understand if you choose to remove my BUGS note in inet_ntop().
> ;-)
>
> By the way, it is real pain to find resources like the list of standard
> licences on the web page... you just remember you have seen it once but
> to click through to it again is a challenge.
Thanks for noting that. I will add another link on the web site, to help this.
My revised version of the page below. Could you take a look please.
Cheers,
Michael
.\" Copyright (c) 1995, 1999
.\" Berkeley Software Design, Inc. All rights reserved.
.\" Copyright (c) 2008 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
.\" and copyright (c) 2009, Linux Foundation, written by Michael Kerrisk
.\" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" 2008-12-08 Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org>
.\" Rewrite the BSD manpage in the Linux man pages style and account
.\" for glibc specificities, provide an example.
.\" 2009-01-14 mtk, many edits and changes, rewrote example program.
.\"
.TH GETIFADDRS 3 2009-01-14 "GNU" "Linux Programmer's Manual"
.SH NAME
getifaddrs, freeifaddrs \- get interface addresses
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <ifaddrs.h>
.sp
.BI "int getifaddrs(struct ifaddrs **" "ifap" );
.sp
.BI "void freeifaddrs(struct ifaddrs *" "ifa" );
.fi
.SH DESCRIPTION
The
.BR getifaddrs ()
function creates a linked list of structures describing
the network interfaces of the local system,
and stores the address of the first item of the list in
.IR *ifap .
The list consists of
.I ifaddrs
structures, defined as follows:
.sp
.in +4n
.nf
struct ifaddrs {
struct ifaddrs *ifa_next; /* Next item in list */
char *ifa_name; /* Name of interface */
unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */
struct sockaddr *ifa_addr; /* Address of interface */
struct sockaddr *ifa_netmask; /* Netmask of interface */
union {
struct sockaddr *ifu_broadaddr;
/* Broadcast address of interface */
struct sockaddr *ifu_dstaddr;
/* Point-to-point destination address */
} ifa_ifu;
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
void *ifa_data; /* Address-specific data */
};
.fi
.in
.PP
The
.I ifa_next
field contains a pointer to the next structure on the list,
or NULL if this is the last item of the list.
.PP
The
.I ifa_name
points to the null-terminated interface name.
.\" The constant
.\" .B IF NAMESIZE
.\" indicates the maximum length of this field.
.PP
The
.I ifa_flags
field contains the interface flags, as returned by the
.B SIOCGIFFLAGS
.BR ioctl (2)
operation (see
.BR netdevice (7)
for a list of these flags).
.PP
The
.I ifa_addr
field points to a structure containing the interface address.
(The
.I sa_family
sub-field should be consulted to determine the format of the
address structure.)
.PP
The
.I ifa_netmask
field points to a structure containing the netmask associated with
.IR ifa_addr ,
if applicable for the address family.
.PP
Depending on whether the bit
.B IFF_BROADCAST
or
.B IFF_POINTOPOINT
is set in
.I ifa_flags
(only one can be set at a time),
either
.I ifa_broadaddr
will contain the broadcast address associated with
.I ifa_addr
(if applicable for the address family) or
.I ifa_dstaddr
will contain the destination address of the point-to-point interface.
.PP
The
.I ifa_data
field points to a buffer containing address-family-specific data;
this field may be NULL if there is no such data for this interface.
.PP
The data returned by
.BR getifaddrs ()
is dynamically allocated and should be freed using
.BR freeifaddrs ()
when no longer needed.
.SH RETURN VALUES
On success,
.BR getifaddrs ()
returns zero;
on error, -1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.BR getifaddrs ()
may fail and set
.I errno
for any of the errors specified for
.BR socket (2),
.BR bind (2),
.\" FIXME Petr, I added getsockname() and recvmsg(); do you agree?
.BR getsockname (2),
.BR recvmsg (2),
.BR sendto (2),
.BR malloc (3),
or
.BR realloc (3).
.SH VERSIONS
The
.BR getifaddrs ()
function first appeared in glibc 2.3, but before glibc 2.3.3,
the implementation only supported IPv4 addresses;
IPv6 support was added in glibc 2.3.3.
.SH CONFORMING TO
Not in POSIX.1-2001.
This function first appeared in BSDi and is
present on the BSD systems, but with slightly different
semantics documented\(emreturning one entry per interface,
not per address.
This means
.I ifa_addr
and other fields can actually be NULL if the interface has no address,
and no link-level address is returned if the interface has an IP address
assigned.
Also, the way of choosing either
.I ifa_broadaddr
or
.I ifa_dstaddr
differs on various sytems.
.\" , but the BSD-derived documentation generally
.\" appears to be confused and obsolete on this point.
.\" i.e., commonly it still says one of them will be NULL, even if
.\" the ifa_ifu union is already present
.SH NOTES
The addresses returned on Linux will usually be the IPv4 and IPv6 addresses
assigned to the interface, but also one
.B AF_PACKET
address per interface containing lower-level details about the interface
and its physical layer.
In this case, the
.I ifa_data
field may contain a pointer to a
.IR "struct net_device_stats" ,
defined in
.IR <linux/netdevice.h> ,
which contains various interface attributes and statistics.
.SH EXAMPLE
The program below demonstrates the use of
.BR getifaddrs (),
.BR freeifaddrs (),
and
.BR inet_ntop (3).
Here is what we see when running this program on one system:
.in +4n
.nf
$ \fB./a.out\fP
lo address family: 17 (AF_PACKET)
eth0 address family: 17 (AF_PACKET)
lo address family: 2 (AF_INET)
address: <127.0.0.1>
eth0 address family: 2 (AF_INET)
address: <10.1.1.4>
lo address family: 10 (AF_INET6)
address: <::1>
eth0 address family: 10 (AF_INET6)
address: <fe80::2d0:59ff:feda:eb51%eth0>
.fi
.in
.SS Program source
\&
.nf
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
struct ifaddrs *ifaddr;
struct net_device_stats *ndsp;
int family, s;
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == \-1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
while (ifaddr != NULL) { /* Walk through linked list */
family = ifaddr\->ifa_addr\->sa_family;
/* Display interface name and family (including symbolic
form of the latter for the common families) */
printf("%\-6s address family: %d%s\\n",
ifaddr\->ifa_name, family,
(family == AF_PACKET) ? " (AF_PACKET)" :
(family == AF_INET) ? " (AF_INET)" :
(family == AF_INET6) ? " (AF_INET6)" : "");
/* For an AF_INET* interface address, display the address */
if (family == AF_INET || family == AF_INET6) {
s = getnameinfo(ifaddr\->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6),
host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("getnameinfo() failed: %s\\n", gai_strerror(s));
exit(EXIT_FAILURE);
}
printf("\\taddress: <%s>\\n", host);
}
ifaddr = ifaddr\->ifa_next;
}
freeifaddrs(ifaddr);
exit(EXIT_SUCCESS);
}
.fi
.SH SEE ALSO
.BR bind (2),
.BR getsockname (2),
.BR socket (2),
.BR packet (7),
.BR ifconfig (8)
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <cfd18e0f0901141527g4518e063p642d0a4464c9804d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2009-01-20 23:48 ` Petr Baudis
[not found] ` <20090120234828.GE21648-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Petr Baudis @ 2009-01-20 23:48 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
Cc: Wichmann, Mats D,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Hi,
On Thu, Jan 15, 2009 at 12:27:14PM +1300, Michael Kerrisk wrote:
> On Tue, Dec 9, 2008 at 3:56 PM, Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org> wrote:
> > I'm open to relicensing to any of the standard licences, this one
> > should be compatible even with the classic BSD licence.
>
> By now, I think little, if any, of the BSD page remains. I'd be
> inclined to switch to the verbatim license? Okay with you?
sure.
> .SH ERRORS
> .BR getifaddrs ()
> may fail and set
> .I errno
> for any of the errors specified for
> .BR socket (2),
> .BR bind (2),
> .\" FIXME Petr, I added getsockname() and recvmsg(); do you agree?
Makes sense.
> .BR getsockname (2),
> .BR recvmsg (2),
> .BR sendto (2),
> .BR malloc (3),
> or
> .BR realloc (3).
> .SH VERSIONS
> The
> .BR getifaddrs ()
> function first appeared in glibc 2.3, but before glibc 2.3.3,
> the implementation only supported IPv4 addresses;
> IPv6 support was added in glibc 2.3.3.
We might add that support for getting addresses other than IPv4 is
available only if the kernel supports netlink.
> .SH EXAMPLE
> The program below demonstrates the use of
> .BR getifaddrs (),
> .BR freeifaddrs (),
> and
> .BR inet_ntop (3).
getnameinfo() now.
> Here is what we see when running this program on one system:
> .in +4n
> .nf
>
> $ \fB./a.out\fP
> lo address family: 17 (AF_PACKET)
> eth0 address family: 17 (AF_PACKET)
> lo address family: 2 (AF_INET)
> address: <127.0.0.1>
> eth0 address family: 2 (AF_INET)
> address: <10.1.1.4>
> lo address family: 10 (AF_INET6)
> address: <::1>
> eth0 address family: 10 (AF_INET6)
> address: <fe80::2d0:59ff:feda:eb51%eth0>
> .fi
> .in
> .SS Program source
> \&
> .nf
> #include <arpa/inet.h>
> #include <sys/socket.h>
> #include <netdb.h>
> #include <ifaddrs.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int
> main(int argc, char *argv[])
> {
> struct ifaddrs *ifaddr;
> struct net_device_stats *ndsp;
Unused.
> int family, s;
> char host[NI_MAXHOST];
>
> if (getifaddrs(&ifaddr) == \-1) {
> perror("getifaddrs");
> exit(EXIT_FAILURE);
> }
>
> while (ifaddr != NULL) { /* Walk through linked list */
> family = ifaddr\->ifa_addr\->sa_family;
>
> /* Display interface name and family (including symbolic
> form of the latter for the common families) */
>
> printf("%\-6s address family: %d%s\\n",
I'd %s\t here instead, personally.
> ifaddr\->ifa_name, family,
> (family == AF_PACKET) ? " (AF_PACKET)" :
> (family == AF_INET) ? " (AF_INET)" :
> (family == AF_INET6) ? " (AF_INET6)" : "");
>
> /* For an AF_INET* interface address, display the address */
>
> if (family == AF_INET || family == AF_INET6) {
> s = getnameinfo(ifaddr\->ifa_addr,
> (family == AF_INET) ? sizeof(struct sockaddr_in) :
> sizeof(struct sockaddr_in6),
> host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
> if (s != 0) {
> printf("getnameinfo() failed: %s\\n", gai_strerror(s));
> exit(EXIT_FAILURE);
> }
I have mixed feelings about this test, since superfluous tests IMHO
obscure the example. Not sure if it can actually ever fail...
> printf("\\taddress: <%s>\\n", host);
> }
>
> ifaddr = ifaddr\->ifa_next;
> }
>
> freeifaddrs(ifaddr);
> exit(EXIT_SUCCESS);
> }
--
Petr "Pasky" Baudis
The average, healthy, well-adjusted adult gets up at seven-thirty
in the morning feeling just terrible. -- Jean Kerr
--
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] 7+ messages in thread
* Re: [PATCH] getifaddrs.3: New manual page
[not found] ` <20090120234828.GE21648-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
@ 2009-01-22 20:22 ` Michael Kerrisk
0 siblings, 0 replies; 7+ messages in thread
From: Michael Kerrisk @ 2009-01-22 20:22 UTC (permalink / raw)
To: Petr Baudis
Cc: Wichmann, Mats D,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Hi Petr,
On Wed, Jan 21, 2009 at 12:48 PM, Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org> wrote:
> Hi,
>
> On Thu, Jan 15, 2009 at 12:27:14PM +1300, Michael Kerrisk wrote:
>> On Tue, Dec 9, 2008 at 3:56 PM, Petr Baudis <pasky-AlSwsSmVLrQ@public.gmane.org> wrote:
>> > I'm open to relicensing to any of the standard licences, this one
>> > should be compatible even with the classic BSD licence.
>>
>> By now, I think little, if any, of the BSD page remains. I'd be
>> inclined to switch to the verbatim license? Okay with you?
>
> sure.
Okay -- done (already).
>> .SH ERRORS
>> .BR getifaddrs ()
>> may fail and set
>> .I errno
>> for any of the errors specified for
>> .BR socket (2),
>> .BR bind (2),
>> .\" FIXME Petr, I added getsockname() and recvmsg(); do you agree?
>
> Makes sense.
Thanks for the ACK.
>> .BR getsockname (2),
>> .BR recvmsg (2),
>> .BR sendto (2),
>> .BR malloc (3),
>> or
>> .BR realloc (3).
>> .SH VERSIONS
>> The
>> .BR getifaddrs ()
>> function first appeared in glibc 2.3, but before glibc 2.3.3,
>> the implementation only supported IPv4 addresses;
>> IPv6 support was added in glibc 2.3.3.
>
> We might add that support for getting addresses other than IPv4 is
> available only if the kernel supports netlink.
Done.
>> .SH EXAMPLE
>> The program below demonstrates the use of
>> .BR getifaddrs (),
>> .BR freeifaddrs (),
>> and
>> .BR inet_ntop (3).
>
> getnameinfo() now.
FIxed.
>> Here is what we see when running this program on one system:
>> .in +4n
>> .nf
>>
>> $ \fB./a.out\fP
>> lo address family: 17 (AF_PACKET)
>> eth0 address family: 17 (AF_PACKET)
>> lo address family: 2 (AF_INET)
>> address: <127.0.0.1>
>> eth0 address family: 2 (AF_INET)
>> address: <10.1.1.4>
>> lo address family: 10 (AF_INET6)
>> address: <::1>
>> eth0 address family: 10 (AF_INET6)
>> address: <fe80::2d0:59ff:feda:eb51%eth0>
>> .fi
>> .in
>> .SS Program source
>> \&
>> .nf
>> #include <arpa/inet.h>
>> #include <sys/socket.h>
>> #include <netdb.h>
>> #include <ifaddrs.h>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <unistd.h>
>>
>> int
>> main(int argc, char *argv[])
>> {
>> struct ifaddrs *ifaddr;
>> struct net_device_stats *ndsp;
>
> Unused.
Bother! That was from an alternate version of the program that I was
using to test that stuff. Thanks!
>> int family, s;
>> char host[NI_MAXHOST];
>>
>> if (getifaddrs(&ifaddr) == \-1) {
>> perror("getifaddrs");
>> exit(EXIT_FAILURE);
>> }
>>
>> while (ifaddr != NULL) { /* Walk through linked list */
>> family = ifaddr\->ifa_addr\->sa_family;
>>
>> /* Display interface name and family (including symbolic
>> form of the latter for the common families) */
>>
>> printf("%\-6s address family: %d%s\\n",
>
> I'd %s\t here instead, personally.
Changed.
>> ifaddr\->ifa_name, family,
>> (family == AF_PACKET) ? " (AF_PACKET)" :
>> (family == AF_INET) ? " (AF_INET)" :
>> (family == AF_INET6) ? " (AF_INET6)" : "");
>>
>> /* For an AF_INET* interface address, display the address */
>>
>> if (family == AF_INET || family == AF_INET6) {
>> s = getnameinfo(ifaddr\->ifa_addr,
>> (family == AF_INET) ? sizeof(struct sockaddr_in) :
>> sizeof(struct sockaddr_in6),
>> host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
>> if (s != 0) {
>> printf("getnameinfo() failed: %s\\n", gai_strerror(s));
>> exit(EXIT_FAILURE);
>> }
>
> I have mixed feelings about this test, since superfluous tests IMHO
> obscure the example. Not sure if it can actually ever fail...
Perhaps it never can. But it's good practice to always check errors,
especially for examples provided in man pages.
[...]
The fixes will be in 3.18. Thanks for checking the page!
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
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] 7+ messages in thread
end of thread, other threads:[~2009-01-22 20:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-09 2:56 [PATCH] getifaddrs.3: New manual page Petr Baudis
[not found] ` <20081209025634.GD10491-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
2009-01-13 17:09 ` Petr Baudis
2009-01-14 10:24 ` Michael Kerrisk
2009-01-14 11:55 ` Michael Kerrisk
[not found] ` <cfd18e0f0901140355j6758cb29i5b356667aedc467-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-01-14 23:27 ` Michael Kerrisk
[not found] ` <cfd18e0f0901141527g4518e063p642d0a4464c9804d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-01-20 23:48 ` Petr Baudis
[not found] ` <20090120234828.GE21648-DDGJ70k9y3lX+M3pkMnKjw@public.gmane.org>
2009-01-22 20:22 ` Michael Kerrisk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox