IPv6 at programming level in windows
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.
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:
http://tdistler.com/2011/02/28/cross-platform-ipv6-socket-programming
链接地址: http://www.djcxy.com/p/51940.html上一篇: 自定义Grails验证
下一篇: IPv6在编程级别的Windows