site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <net/if.h> #include <ifaddrs.h> #include <errno.h> int main( int argc, char *argv[]) { struct ifaddrs *myaddrs, *ifa; struct sockaddr_in *s4; struct sockaddr_in6 *s6; int status; /* buf must be big enough for an IPv6 address (e.g. 3ffe:2fa0:1010:ca22:020a:95ff:fe8a:1cf8) */ char buf[ 64 ]; status = getifaddrs(&myaddrs); if (status != 0 ) { perror( "getifaddrs" ); exit( 1 ); } for (ifa = myaddrs; ifa != NULL ; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL ) continue ; if ((ifa->ifa_flags & IFF_UP) == 0 ) continue ; if (ifa->ifa_addr->sa_family == AF_INET) { s4 = ( struct sockaddr_in *)(ifa->ifa_addr); if (inet_ntop(ifa->ifa_addr->sa_family, ( void *)&(s4->sin_addr), buf, sizeof (buf)) == NULL ) { printf( "%s: inet_ntop failed!\n" , ifa->ifa_name); } else { printf( "%s: %s\n" , ifa->ifa_name, buf); } } else if (ifa->ifa_addr->sa_family == AF_INET6) { s6 = ( struct sockaddr_in6 *)(ifa->ifa_addr); if (inet_ntop(ifa->ifa_addr->sa_family, ( void *)&(s6->sin6_addr), buf, sizeof (buf)) == NULL ) { printf( "%s: inet_ntop failed!\n" , ifa->ifa_name); } else { printf( "%s: %s\n" , ifa->ifa_name, buf); } } } freeifaddrs(myaddrs); exit( 0 ); }