Things to note when you rewrite Don't forget to freeaddrinfo() Dynamically allocates memory region, unlike gethostbyname() Try to exactly follow the example presented here Tend to make mistakes if you use other constructs (do-while, goto)