Use getaddrinfo() to figure out if a numeric address is IPv4 or IPv6.