Take the 2-minute tour ×

What is the difference between IPv6 and IPv4 at programming level in windows?

Can we just change IPv4 address to IPV6 and keep all other program same, will it work?

share|improve this question
difference in respect of coding –  Vijay Apr 11 '11 at 12:00
Asynchronous name resolves do not work with IPv6 (have to use getnameinfo, which honestly is an ordeal). Other than that, in theory everything should be exactly the same if you have used "good practice", since all the structs have been opaque for a long time, so you won't know if something changes under the hood. See this for how to write AF-agnostic code: kame.net/newsletter/19980604 –  Damon Apr 11 '11 at 12:07
For Vista and later you can set an option on a socket so you can use it for both IPv4 and IPv6 purposes. Have a look at msdn.microsoft.com/en-us/library/ms738649(v=vs.85).aspx to help you. Careful use of APIs and structures can allow to do it all in agnostic ways. –  Boofhead Apr 11 '11 at 12:14
You haven't selected either of the answers. If neither meets your needs, could you please supply a bit more information about what you are looking for? –  Michael J Apr 13 '11 at 16:53
@michael Your answer is pretty much closer. I wanted to know where do i have to make changes in order to make ipv4 program to work with ipv6. –  Vijay Apr 14 '11 at 5:29
add comment

2 Answers

It really depends on what your program does.

An IPV6 address takes 16 bytes, rather than the four used by IPV4. The string representations are also different.

To create a socket is almost the same:

            sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

Just change PF_INET to PF_INET6.

Connect is a little different:

            nRet = connect(sock, 
                           reinterpret_cast<SOCKADDR *>(&SockAddr), 

In IPV4, SockAddr is a sockaddr_in struct, in IPV6 it is a sockaddr_in6.

You have to use something like getaddrinfo() to init SockAddr as gethostbyname() doesn't work for IPV6.

bind(), listen() and accept() are more of the same. Once the socket is established, reading, writing, etc. are independent of the IP version.

If you are working at a higher level (such as HTTP) your program shouldn't need any change, but it might need to link to different libraries.

share|improve this answer
add comment

The IPv6 spec (RFC 3493) defines some new API methods and data structures. Microsoft implemented the early version of the API (RFC 2553) in Windows so there are some differences. This link describes the differences and breaks down what API's are supported on what version of Windows:


share|improve this answer
add comment

Your Answer


