I want to adapt my old C codebases, that were written for IPv4, to work with IPv6. What do I need to change so that my C code works with both IPv4 and IPv6?
Find all code that uses inet_aton
, inet_ntoa
, gethostbyname
, gethostbyaddr
, htonl
, htons
, ntohl
, ntohs
, and any direct sockaddr_in
manipulation and replace it with simple calls to getaddrinfo
or getnameinfo
. This will make your code much simpler and more maintainable and IPv6 will automatically work with no additional effort.