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?
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),
sizeof(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With