views:

229

answers:

2

Hi,

I have a program that uses gethostbyname (in Windows) in order to convert IP address to hostname.

But, it works only for IPv4...

What is the correct replacement for IPv6?

Thanks.

+2  A: 

Looking up gethostbyname in MSDN tells us that it's deprecated and we should look at getaddrinfo, which has all kinds of options for dealing with other addressing families.

Or if you're doing address to name translation, you'll end up at getnameinfo

Damien_The_Unbeliever
Thank you. It works.
rursw1
+1  A: 

Use getaddrinfo, which deprecates the old gethostbyname function.

Marcelo Cantos
You **should** even use it for IPv4 addresses as well. You can produce protocol-independant code (same code that works for both IPv4 and IPv6) very easily.
ereOn
+1 good point, @ereOn.
Marcelo Cantos
Thank you. It works.
rursw1