Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPv6 at programming level in windows

Tags:

c++

windows

ipv6

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?

like image 786
Vijay Avatar asked Apr 11 '11 11:04

Vijay


1 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), 
                           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.

like image 125
Michael J Avatar answered Oct 17 '22 08:10

Michael J