Windows Programming Level IPv6

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

Can I just change the IPv4 address to IPV6 and save all the other programs, will it work?

+7
source share
2 answers

It really depends on what your program does.

The IPV6 address is 16 bytes, not the four used by IPV4. 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.

The connection is a little different:

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

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

You should use something like getaddrinfo () for init SockAddr, since gethostbyname () does not work for IPV6.

bind (), listen () and accept () are more similar. Once the socket is installed, read, write, etc. Independent of IP version.

If you work at a higher level (for example, HTTP), your program does not need any changes, but a link to different libraries may be required.

+2
source

The IPv6 specification (RFC 3493) defines some new API methods and data structures. Microsoft has introduced an earlier version of the API (RFC 2553) on Windows, so there are some differences. This link describes the differences and breaks down which APIs are supported in which version of Windows:

http://tdistler.com/2011/02/28/cross-platform-ipv6-socket-programming

+2
source

All Articles