• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to get IPv6 address using getifaddrs and which version of glibc supports
[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


  • Subject: How to get IPv6 address using getifaddrs and which version of glibc supports
  • From: Srinivasa Srini <email@hidden>
  • Date: Sat, 5 Aug 2006 12:38:47 +0530


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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to get IPv6 address using getifaddrs and which version of glibc supports
      • From: almisr <email@hidden>
    • Re: How to get IPv6 address using getifaddrs and which version of glibc supports
      • From: almisr <email@hidden>
    • Re: How to get IPv6 address using getifaddrs and which version of glibc supports
      • From: Eric Albert <email@hidden>
  • Prev by Date: Re: Launchd domain socket permission problem
  • Next by Date: Re: How to get IPv6 address using getifaddrs and which version of glibc supports
  • Previous by thread: Mach-O Runtime PDF on ADC
  • Next by thread: Re: How to get IPv6 address using getifaddrs and which version of glibc supports
  • Index(es):
    • Date
    • Thread