Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gethostbyname replacement for IPv6 addresses

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.

like image 391
rkellerm Avatar asked Apr 08 '10 10:04

rkellerm


People also ask

What can I use instead of Gethostbyname?

Note The gethostbyname function has been deprecated by the introduction of the getaddrinfo function. Developers creating Windows Sockets 2 applications are urged to use the getaddrinfo function instead of gethostbyname.

Will we run out of IPv6 addresses?

Will IPv6 addresses run out eventually? In practical terms, no. There are 2^128 or 340 trillion, trillion, trillion IPv6 addresses, which is more than 100 times the number of atoms on the surface of the Earth. This will be more than sufficient to support trillions of Internet devices for the forseeable future.

Which options are valid types of IPv6 addresses?

The three types of IPv6 addresses are: unicast, anycast, and multicast.

What would you use to replace a group of consecutive zeros in an IPv6 address?

You can use the two colon notation to replace any contiguous fields of all zeros in the IPv6 address. For example, the IPv6 address 2001:0db8:3c4d:0015:0000:d234::3eee:0000 can be collapsed into 2001:db8:3c4d:15:0:d234:3eee::.


2 Answers

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

like image 137
Damien_The_Unbeliever Avatar answered Oct 07 '22 18:10

Damien_The_Unbeliever


Use getaddrinfo, which deprecates the old gethostbyname function.

like image 27
Marcelo Cantos Avatar answered Oct 07 '22 18:10

Marcelo Cantos