Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net Add a small example.



details:   https://anonhg.NetBSD.org/src/rev/1278e7ee1d05
branches:  trunk
changeset: 785966:1278e7ee1d05
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Apr 07 22:54:26 2013 +0000

description:
Add a small example.

diffstat:

 lib/libc/net/getifaddrs.3 |  34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diffs (55 lines):

diff -r 6b16f19def19 -r 1278e7ee1d05 lib/libc/net/getifaddrs.3
--- a/lib/libc/net/getifaddrs.3 Sun Apr 07 19:17:11 2013 +0000
+++ b/lib/libc/net/getifaddrs.3 Sun Apr 07 22:54:26 2013 +0000
@@ -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 @@
 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



Home | Main Index | Thread Index | Old Index