You shouldn’t be using gethostbyname() anyway
Today's GHOST vulnerability is in gethostbyname(), a Sockets API function from the early 1980s. That function has been obsolete for a decade. What you should be using is getaddrinfo() instead, a newer function that can also handle IPv6.The great thing about getaddrinfo() is the fact that it allows writing code that is agnostic to the IP version. You can see an example of this in my heartleech.c program.
x = getaddrinfo(hostname, port, 0, &addr);
fd = socket(addr->ai_family, SOCK_STREAM, 0);
x = connect(fd, addr->ai_addr, (int)addr->ai_addrlen);
What you see here is your normal call to socket() and connect() just use the address family returned by getaddrinfo(). It doesn't care if that is IPv4, IPv6, or IPv7.
The function actually returns a list of addresses, which may contain a mixture of IPv4 and IPv6 addresses. An example is when you lookup www.google.com:
[ ] resolving "www.google.com"
[+] 74.125.196.105:443
[+] 74.125.196.147:443
[+] 74.125.196.99:443
[+] 74.125.196.104:443
[+] 74.125.196.106:443
[+] 74.125.196.103:443
[+] [2607:f8b0:4002:801::1014]:443
My sample code just chooses the first one in the list, Continue reading

When you’re setting up your monitoring configuration for 
When you’re setting up your monitoring configuration for