Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to get IPv6 address using getifaddrs and which version of glibc supports




Hi

Our set up is Linux 2.4.20 version kernel and glibc 2.3.2.-11.9

We were trying to get the ipv6 address using getifaddrs as give bellow


#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);
}


we can able to get only Ipv4 addresses from interface.

I came to know from mailing list getifaddrs() in glibc 2.3 doesnt support Ipv6

please tell us which version of glibc supports getifaddrs() for getting Ipv6 addresses.

cheers,
Srini

______________________________________________________________________
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.