summaryrefslogtreecommitdiffstats
path: root/man3/getifaddrs.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/getifaddrs.3')
-rw-r--r--man3/getifaddrs.352
1 files changed, 25 insertions, 27 deletions
diff --git a/man3/getifaddrs.3 b/man3/getifaddrs.3
index c814dc2d8..3f82c9350 100644
--- a/man3/getifaddrs.3
+++ b/man3/getifaddrs.3
@@ -14,7 +14,7 @@
.\" for glibc specificities, provide an example.
.\" 2009-01-14 mtk, many edits and changes, rewrote example program.
.\"
-.TH getifaddrs 3 2023-02-05 "Linux man-pages 6.03"
+.TH getifaddrs 3 2023-07-20 "Linux man-pages 6.05.01"
.SH NAME
getifaddrs, freeifaddrs \- get interface addresses
.SH LIBRARY
@@ -142,34 +142,25 @@ for any of the errors specified for
.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 supported only IPv4 addresses;
-IPv6 support was added in glibc 2.3.3.
-Support of address families other than IPv4 is available only
-on kernels that support netlink.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
-.ad l
-.nh
.TS
allbox;
lbx lb lb
l l l.
Interface Attribute Value
T{
+.na
+.nh
.BR getifaddrs (),
.BR freeifaddrs ()
T} Thread safety MT-Safe
.TE
-.hy
-.ad
.sp 1
.SH STANDARDS
-Not in POSIX.1.
+None.
+.SH HISTORY
This function first appeared in BSDi and is
present on the BSD systems, but with slightly different
semantics documented\[em]returning one entry per interface,
@@ -188,6 +179,13 @@ differs on various systems.
.\" 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
+.PP
+.BR getifaddrs ()
+first appeared in glibc 2.3, but before glibc 2.3.3,
+the implementation supported only IPv4 addresses;
+IPv6 support was added in glibc 2.3.3.
+Support of address families other than IPv4 is available only
+on kernels that support netlink.
.SH NOTES
The addresses returned on Linux will usually be the IPv4 and IPv6 addresses
assigned to the interface, but also one
@@ -247,40 +245,40 @@ wlp3s0 AF_INET6 (10)
#include <stdlib.h>
#include <unistd.h>
#include <linux/if_link.h>
-
+\&
int main(int argc, char *argv[])
{
struct ifaddrs *ifaddr;
int family, s;
char host[NI_MAXHOST];
-
+\&
if (getifaddrs(&ifaddr) == \-1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
}
-
+\&
/* Walk through linked list, maintaining head pointer so we
can free list later. */
-
+\&
for (struct ifaddrs *ifa = ifaddr; ifa != NULL;
ifa = ifa\->ifa_next) {
if (ifa\->ifa_addr == NULL)
continue;
-
+\&
family = ifa\->ifa_addr\->sa_family;
-
+\&
/* Display interface name and family (including symbolic
form of the latter for the common families). */
-
+\&
printf("%\-8s %s (%d)\en",
ifa\->ifa_name,
(family == AF_PACKET) ? "AF_PACKET" :
(family == AF_INET) ? "AF_INET" :
(family == AF_INET6) ? "AF_INET6" : "???",
family);
-
+\&
/* For an AF_INET* interface address, display the address. */
-
+\&
if (family == AF_INET || family == AF_INET6) {
s = getnameinfo(ifa\->ifa_addr,
(family == AF_INET) ? sizeof(struct sockaddr_in) :
@@ -291,19 +289,19 @@ int main(int argc, char *argv[])
printf("getnameinfo() failed: %s\en", gai_strerror(s));
exit(EXIT_FAILURE);
}
-
+\&
printf("\et\etaddress: <%s>\en", host);
-
+\&
} else if (family == AF_PACKET && ifa\->ifa_data != NULL) {
struct rtnl_link_stats *stats = ifa\->ifa_data;
-
+\&
printf("\et\ettx_packets = %10u; rx_packets = %10u\en"
"\et\ettx_bytes = %10u; rx_bytes = %10u\en",
stats\->tx_packets, stats\->rx_packets,
stats\->tx_bytes, stats\->rx_bytes);
}
}
-
+\&
freeifaddrs(ifaddr);
exit(EXIT_SUCCESS);
}