Use getaddrinfo(3) and inet_ntop/inet_pton

Using getaddrinfo(3) simplifies the socket creation process and is also required for supporting IPv6. The IP address formatting and parsing functions inet_ntop(3) and inet_pton(3) support both IPv4 and IPv6 string formats.

I'm also working on an ipv6 branch which depends on this branch, I've decided to separate them as the addrinfo code should be of use even without ipv6 support.

The `make test` suite currently passes.