herror deprecated

2019-07-07 08:43发布

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?

1条回答
看我几分像从前
2楼-- · 2019-07-07 09:09

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.

查看更多
登录 后发表回答