3

Answering another question, I stumbled upon the man page of a function called herror. It appears to be very much like perror except it prints errors related to some host lookup problem. The man page states that this function is “obsolete”. A function hsterror which could be used to turn the error number into a string without printing it is marked obsolete as well.

What I don't see is any indication as to why either of them is obsolete, and what replacement should be used instead. So what is the preferred way to turn an obscure h_errno error number into a user-readable string on a GNU libc linux system? Should every tiny application ship a translation table of its own, and hope that the set of possible error codes doesn't change any time soon?

Community
  • 1
  • 1
MvG
  • 57,380
  • 22
  • 148
  • 276

1 Answers1

4

They are obsolete because gethostbyname* is obsolete. Use getaddrinfo instead, and use gai_strerror for errors.

From the gethostbyname(3) man page:

The gethostbyname*() and gethostbyaddr*() functions are obsolete. Applications should use getaddrinfo(3) and getnameinfo(3) instead.

jxh
  • 69,070
  • 8
  • 110
  • 193
  • Thanks! That message appears a little less pronounced than the one I read first. A link to the new man pages would be great, but in any case I'll accept this answer once I'm allowed to. – MvG Aug 06 '12 at 17:08