Поделиться через


Changing the Application Source Code to Support IPv6 (Windows Embedded CE 6.0)

1/6/2010

Due to the size difference between the IPv6 address and the IPv4 address, you must change functions and data structures that are hard-coded in your application to handle the larger sized addresses. You must change structures that rely on a specific IP address version to ones that are not version specific.

Protocols that your application depends on for services, such as Remote Procedure Call (RPC), may also have functions and structures that are IP version dependent. You may need to modify your application in terms of their usage.

You will use the Checkv4 output in this procedure. You can obtain the Checkv4 utility from the IPv6 Technology Preview, available for download at this Microsoft Web site.

Note

Some recommendations made by the Checkv4 utility require structures that are available only in recent versions of the Ws2tcpip.h header file, such as SOCKADDR_IN6 structure. These header files are available in Microsoft® Platform Builder version 4.1 and later.

Best Practices

  • Decide how to display the IPv4 and IPv6 addresses as described in Deciding How to Display IP Addresses.
  • Consider the appropriate approach to each user interface.
    Consider whether the information that the interface element provides for IPv4 is appropriate for IPv6. You must also ensure that the user interface is long enough to display IPv6 addresses.
  • Ensure that the application accommodates the appropriate length of IP address, based on whether IPv4 or IPv6 is used.

To change data structures and functions to support IPv6

  1. Using the Checkv4 output as a guide, fix the structures and declarations to enable IPv4/IPv6 compatibility.

Note

Although the Checkv4 utility can help you find common literal strings, it may not accurately reflect changes that you need to make in your code. The checkv4 output provides enough information to get you started on changing your code. You should thoroughly search and test your code base to ensure that it is free of potential problems associated with literal strings.

The following table shows the functions and structures you must typically change.

Change from Change to

GetAdaptersInfo

GetAdaptersAddresses

gethostbyaddr

getnameinfo

gethostbyname

getaddrinfo

gethostname

getaddrinfo 

-or-

getnameinfo

hostent

getaddrinfo

inet_addr

WSAStringToAddress 

-or-

getaddrinfo with the ai_flag of AI_NUMERICHOST

inet_ntoa

WSAStringToAddress 

-or-

getaddrinfo with the ai_flag of AI_NUMERICHOST

IP_ADAPTER_INFO

IP_ADAPTER_ADDRESSES

SOCKADDR

SOCKADDR_STORAGE

SOCKADDR_IN

SOCKADDR_STORAGE

Note

To see client or server sample IPv4-only code that has been annotated with comments regarding how to handle the checkv4 ouput, see Annotated Client Code with Checkv4 Output and Annotated Server Code with Checkv4 Output.

Note

To see this same code after it has been changed to support both IPv4 and IPv6, see the appropriate code in IP Independent Source Code Examples.

  1. When using the getaddrinfo function, the application must perform name resolution before it opens the socket. For example, for IPv4, you could open the socket, then perform name resolution, and finally connect to the interface. For IPv6, you must always perform the name resolution first.
  2. As you review the code, make the following changes to support IPv6:
    • Review the source code for hard-coded loopback addresses or other literal strings. Change them to code that works with both IPv4 and IPv6.
      Hard coded addresses or integer constants, such as INADDR_LOOPBACK, present a problem when you convert from IPv4 to IPv4/IPv6 or create IP version-independent programs.
    • Review the user interface, including informational dialog boxes. Consider whether the information is appropriate for IPv6.
    • Perform a visual review of the user interface; look for any element that is dependent on a specific length for the IP address string.
      For example, look for dialog boxes that display the IP address where an IPv6 address might not have enough display room.
      For each element that is dependent on an IP address string, determine whether it is appropriate to display the address when using IPv6. If it is possible that either IPv4 or IPv6 is in use, ensure that the user interface can accommodate either. Replace or augment any controls with user interface controls that can display an entire IPv6 address.
  3. Determine whether the application relies on underlying protocols or programming interfaces, such as DCOM. If the underlying protocol or interface does not handle IPv6 in a transparent manner, make the appropriate programmatic changes to handle IPv6 addresses.

Next, you must test your application or Device in an IPv6 environment as described in Testing your Application or Device in an IPv6 Environment.

See Also

Tasks

How to Convert an Application from IPv4 to IPv4/IPv6