Compartir a través de


Creating IP Agnostic Applications - Part 1

In Windows Vista and Windows Server "Longhorn," IPv6 is installed and enabled by default.  When both IPv4 and IPv6 are enabled on these OSs, the TCP/IP stack prefers to use IPv6 over IPv4.  For example, APIs such as ConnectByName will attempt to connect first via IPv6.  See this post for a detailed discussion of address sorting.

Since the IPv6 stack has been enhanced, is installed by default and the preferred network layer, it is important when writing network code to ensure your application is IP agnostic.  That is, your application should be able to function well when:

  • IPv4 and IPv6 are installed
  • IPv4 is the only network layer protocol installed
  • IPv6 is the only network layer protocol installed

At first glance this requirement may seem like significant added complexity for an application developer, but there is good news :).  We have been actively working on ways to make writing IP agnostic applications simple.  The remainder of this post will talk about how to get started making your apps IPv6 aware.  In a subsequent post, I hope to drill down into specific topics.  

Check Out the Porting Guide

When writing such applications, I suggest reading the Winsock IPv6 Porting Guide.  This document is applicable to Windows Vista and Windows Server Longhorn as well as many prior OSs such as Windows XP and Window Server 2003.  While the document speaks directly to the use of native code Winsock APIs, the concepts presented are directly applicable to both native and managed code (ie. .Net Framework).  Would a version of this document targeted at managed code development be useful?  Are there areas of the porting guide you would like expanded?  If so, please let us know.

How to Check if IPv4 or IPv6 is Installed    

One of the first tasks you may need to do is determine if IPv4 and/or IPv6 are installed on the machine.  I believe there a number of suggested methods out there, but the recommended method which will reliably tell you if a protocol is installed is to attempt to create a socket for the address family in question. 

For Winsock developers, this is accomplished by calling the socket or WSASocket function with the address family parameter set to AF_INET to test IPv4 availability and AF_INET6 for IPv6.

For .Net Framework applications, use the Socket.SupportsIPv4 property to test IPv4 availability and Socket.OSSupportsIPv6 for IPv6. 

Note: There is a Socket.SupportsIPv6 property, but this is NOT the one you want in this case.  For compat reasons we could not change the meaning of this property which does not tell you whether the machine has IPv6 installed, but instead gives back the value of a legacy configuration switch.

Previous Posts

Brad Williamson has posted already on a couple of the APIs available on Windows Vista & Windows Server "Longhorn" which simplify connection establishment for IP agnostic apps.

 

-Mike Flasko

Comments

  • Anonymous
    August 29, 2006
    Suggestion: add Socket.OSSupportsIPv4 and forget about Socket.SupportsIPv?
  • Anonymous
    September 01, 2006
    Thanks for the suggestion.  We will look at this and other options for better alignment in the future.
  • Anonymous
    September 09, 2006
    hi

    with Vista , what are the appliations only working with ipv6 . I heard something about a feature allowing the applications  sharing between users in a local network . Is it true ? are they other applications like that ?

    thanks for your reply
  • Anonymous
    September 11, 2006
    That would be Windows Meeting Space, and while it does use ipv6, it can run on a ipv4 infrastructure via link local or ipv6 over ipv4 transition technologies, see http://www.microsoft.com/technet/windowsvista/library/8a70907e-9137-4426-a46f-a2d1eeadbd5a.mspx#ETKAE .  All applications using the Windows Peer to Peer Collaboration Foundation Technologies require IPv6 in this way.

    -- Ari
  • Anonymous
    October 24, 2006
    With the adoption of IPv6 ever increasing (ie. it is the preferred protocol on Windows Vista) it is important