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.
Michael j
source share