Subject: Retrieving my IPv6 addresses

From: [email-masked]
Date: Tue, 3 Apr 2001 17:08:08 +0300

Hi all!

	I'm coding one application in W2000 that needs to know its own IP
addresses to send that information to the peer (if anybody knows SCTP,
that's what I'm coding).

	I thought that the function that should do this is getipnodebyname,
passing it the hostname of my machine, but that function is not supported by
Windows 2000. I'm not sure, but I guess that getaddrinfo does more or less
the same... This is the code that prints on the screen the IP addresses:

#include <winsock2.h>
#include <ws2tcpip.h>
#include <tpipv6.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define IPPROTO_SCTP 132;

void main ()
{
  char buffer[256], *port = "10000";
  WSADATA wsaData;
  int order;
  struct addrinfo hints, *addrInfo, *auxAddrInfo;

  WSAStartup(MAKEWORD(2, 2), &wsaData);
  gethostname(buffer, sizeof(buffer));
  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_SCTP;

  getaddrinfo(buffer, port, &hints, &addrInfo);
  for (auxAddrInfo = addrInfo; auxAddrInfo != NULL; auxAddrInfo =
auxAddrInfo->ai_next)
  {
    if (auxAddrInfo->ai_family == PF_INET)
      printf("IPv4 address: %s.\n", inet_ntoa(((struct sockaddr_in *)
auxAddrInfo->ai_addr)->sin_addr));
    if (auxAddrInfo->ai_family == PF_INET6)
    {
      printf("IPv6 address: ");
      for (order = 0; order < 16; order = order + 2)
      {
        printf("%x", ntohs(*((unsigned short *) &(((struct sockaddr_in6 *)
auxAddrInfo->ai_addr)->sin6_addr.s6_addr[order]))));
        printf((order < 14) ? ":" : ".\n");
      }
    }
  }
  return;
}

	When I use ipv6 if, I can see several IPv6 addresses, but using this
program I only retrieve IPv4 addresses... What is more, if I modify

	hints.ai_family = PF_UNSPEC;

	with

	hints.ai_family = PF_INET6;

	I receive the EAI_NONAME error ("No such host is known"). The
hostname is the one that gethostname gives me, a real one, so, does this
maybe have to do with the DNS server? I really don't know why this happens,
but in any case, how can I retrieve the IP address of my machine (and having
any which is of IPv6 type)?

	Also, I'm afraid that there is not yet any support for SOCK_RAW. If
I modify

	hints.ai_socktype = SOCK_DGRAM;

	with

	hints.ai_socktype = SOCK_RAW;

	I receive the EAI_SOCKTYPE error ("The support for the specified
socket type does not exist in this address family."). Using raw sockets is
vital for my program... is it true that there isn't any support for them
yet?

	Thanks in advance!

	BR Iván Arias Rodríguez
--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to [email-masked]
--------------------------------------------------------------------