(sysdep-CFLAGS): Don't define, not needed any more.
[glibc.git] / inet / test-ifaddrs.c
blob52cda735081517ad5c7f6870c6156b14621e85b8
1 /* Test listing of network interface addresses.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <ifaddrs.h>
25 #include <netinet/in.h>
26 #include <arpa/inet.h>
28 int
29 main (void)
31 int failures = 0;
32 struct ifaddrs *ifaces, *ifa;
34 if (getifaddrs (&ifaces) < 0)
36 if (errno != ENOSYS)
38 printf ("Couldn't get any interfaces: %s.\n", strerror (errno));
39 exit (1);
41 /* The function is simply not implemented. */
42 exit (0);
45 puts ("\
46 Name Flags Address Netmask Broadcast/Destination");
48 for (ifa = ifaces; ifa != NULL; ifa = ifa->ifa_next)
50 char abuf[64], mbuf[64], dbuf[64];
51 inline const char *addr_string (struct sockaddr *sa, char *buf)
53 if (sa == NULL)
54 return "<none>";
56 switch (sa->sa_family)
58 case AF_INET:
59 return inet_ntop (AF_INET,
60 &((struct sockaddr_in *) sa)->sin_addr,
61 buf, sizeof abuf);
62 case AF_INET6:
63 return inet_ntop (AF_INET6,
64 &((struct sockaddr_in6 *) sa)->sin6_addr,
65 buf, sizeof abuf);
66 #ifdef AF_LINK
67 case AF_LINK:
68 return "<link>";
69 #endif
70 case AF_UNSPEC:
71 return "---";
72 default:
73 ++failures;
74 printf ("sa_family=%d %08x\n", sa->sa_family,
75 *(int*)&((struct sockaddr_in *) sa)->sin_addr.s_addr);
76 return "<unexpected sockaddr family>";
79 printf ("%-15s%#.4x %-15s %-15s %-15s\n",
80 ifa->ifa_name, ifa->ifa_flags,
81 addr_string (ifa->ifa_addr, abuf),
82 addr_string (ifa->ifa_netmask, mbuf),
83 addr_string (ifa->ifa_broadaddr, dbuf));
86 freeifaddrs (ifaces);
88 return failures ? 1 : 0;