iyasar iyasar - 1 month ago 25
C Question

Migration from IPV4 to IPV6 in C codes

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?

R.. R..
Answer

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.

Comments