Search code examples
cgethostbynameinetinet-aton

Differences between inet_aton() and gethostbyname() in C?


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.


Solution

  • 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.