Module Name: src
Committed By: christos
Date: Sun Apr 7 22:54:26 UTC 2013
Modified Files:
src/lib/libc/net: getifaddrs.3
Log Message:
Add a small example.
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/net/getifaddrs.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/net/getifaddrs.3
diff -u src/lib/libc/net/getifaddrs.3:1.12 src/lib/libc/net/getifaddrs.3:1.13
--- src/lib/libc/net/getifaddrs.3:1.12 Mon Mar 22 15:30:54 2010
+++ src/lib/libc/net/getifaddrs.3 Sun Apr 7 18:54:26 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: getifaddrs.3,v 1.12 2010/03/22 19:30:54 joerg Exp $
+.\" $NetBSD: getifaddrs.3,v 1.13 2013/04/07 22:54:26 christos Exp $
.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp
.\"
.\" Copyright (c) 1995, 1999
@@ -21,7 +21,7 @@
.\" 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.
-.Dd April 21, 2009
+.Dd April 7, 2013
.Dt GETIFADDRS 3
.Os
.Sh NAME
@@ -133,6 +133,36 @@ Upon successful completion, a value of 0
Otherwise, a value of -1 is returned and
.Va errno
is set to indicate the error.
+.Sh EXAMPLES
+The following example program prints a list of all addresses configured
+on the system.
+.Bd -literal -offset indent
+#include \*[Lt]sys/types.h\*[Gt]
+#include \*[Lt]sys/socket.h\*[Gt]
+#include \*[Lt]stdio.h\*[Gt]
+#include \*[Lt]ifaddrs.h\*[Gt]
+#include \*[Lt]util.h\*[Gt]
+#include \*[Lt]err.h\*[Gt]
+#include \*[Lt]stdlib.h\*[Gt]
+
+int
+main(int argc, char *argv[])
+{
+ struct ifaddrs *ifa, *a;
+
+ if (getifaddrs(\*[Am]ifa) == -1)
+ err(EXIT_FAILURE, "getifaddrs");
+
+ for (a = ifa; a; a = a->ifa_next) {
+ char buf[1024];
+ sockaddr_snprintf(buf, sizeof(buf), "%f %a",
+ a->ifa_addr);
+ printf("%s %x %s\\n", a->ifa_name, a->ifa_flags, buf);
+ }
+ freeifaddrs(ifa);
+ return EXIT_SUCCESS;
+}
+.Ed
.Sh ERRORS
The
.Fn getifaddrs