IPv6 Support

In order to support both IPv4 and IPv6 on Windows XP with Service Pack 1 (SP1) and on Windows Server 2003, an application has to create two sockets, one socket for use with IPv4 and one socket for use with IPv6. These two sockets must be handled separately by the application.

If a TCP/IP service provider on Windows XP with SP1 and on Windows Server 2003 supports IPv4 and IPv6 addressing, it must create two separate sockets and listen separately on these sockets:

  • Once for IPv4.
  • Once for the IPv6 address family.

Windows Vista and later offer the ability to create a single IPv6 socket which can handle both IPv6 and IPv4 traffic. For example, a TCP listening socket for IPv6 is created, put into dual stack mode, and bound to port 5001. This dual-stack socket can accept connections from IPv6 TCP clients connecting to port 5001 and from IPv4 TCP clients connecting to port 5001. This feature allows for greatly simplified application design and reduces the resource overhead required of posting operations on two separate sockets. However, there are some restrictions that must be met in order to use a dual-stack socket. For more information, see Dual-Stack Sockets.

WSAEnumProtocols returns two WSAPROTOCOL_INFO structures for each of the supported socket types (SOCK_STREAM, SOCK_DGRAM, SOCK_RAW). The iAddressFamily must by set to AF_INET for IPv4 addressing, and to AF_INET6 for IPv6 addressing.

The IPv6 addresses are described in the following structures.

struct in_addr6 {
    u_char    s6_addr[16];             /* IPv6 address */
};

struct sockaddr_in6 {
    short             sin6_family;     /* AF_INET6 */
    u_short           sin6_port;       /* Transport level port number */
    u_long            sin6_flowinfo;   /* IPv6 flow information */
    struct in_addr6   sin6_addr;       /* IPv6 address */
    u_long            sin6_scope_id;   /* set of interfaces for a scope */
   };

If an application uses Windows Sockets 1.1 functions and wants to use IPv6 addresses, it may continue to use all the old functions that take the sockaddr structure as one of the parameters (bind, connect, sendto, and recvfrom, accept, and so forth). The only change that is required is to use sockaddr_in6 instead of sockaddr_in.

However, the name resolution functions (gethostbyname, gethostbyaddr, and so forth) and address conversion functions (inet_addr, inet_ntoa) cannot be reused because they assume an IP address is 4 bytes in length. An application that wants to perform name resolution and address conversion for IPv6 addresses must use Windows Sockets 2-specific functions. Many new functions have been introduced to enable Windows Sockets 2 applications to take advantage of IPv6, including the getaddrinfo and getnameinfo functions.

For more information on how to enable IPv6 capabilities in an application, see the IPv6 Guide for Windows Sockets Applications.

 

 

Community Additions

ADD
Show:
© 2014 Microsoft