Frage

I'm studying C and TCP/UDP. As the title... Is there any difference between inet_aton() and gethostbyname() in C? From what I know, both convert an IP address from a string to a number.

War es hilfreich?

Lösung

gethostbyname() is obsolete. You should use getaddrinfo().

inet_aton() only works for IPv4.

Also, inet_aton() only convert a IPv4 notion (0.0.0.0) to int, getaddrinfo does DNS resolution.

Andere Tipps

gethostbyname() is used for getting ip-address from hostname and store them in struct in_addr.Where as inet_aton takes in the ip address in dotted format and converts into network byte order .

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top