The gethostbyname and gethostbyaddr functions indicate an error condition by returning a null pointer and setting the external integer h_errno to indicate the error return status.
When gethostbyname or gethostbyaddr returns an error status, h_ errno, which is very similar to errno, can be checked to determine whether the error is the result of a temporary failure or an invalid or unknown host.
Use the herror routine to print the error message describing the failure. If the argument string to herror is not NULL, it is printed, followed by a colon (:) and a space. The error message is printed with a trailing new-line character.
The <netdb.h> header file declares h_errno on a per-thread basis as:
#define h_errno (*decc$h_errno_get_addr())
The <netdb.h> header file also symbolically defines the error code values that h_errno can accept, as follows:
HOST_NOT_FOUND | No such host is known. |
TRY_AGAIN | Usually a temporary error that means the local server did not receive a response from an authoritative server. A retry at some later time can succeed. |
NO_RECOVERY | An unexpected server failure is encountered. This is a nonrecoverable error. |
NO_DATA | The requested name is valid but does not have an IP address; this is not a temporary error. The name is known to the name server but there is no address associated with this name. Another type of request to the name server using this domain name results in an answer; for example, a mail-forwarder registered for this domain. |
NO_ADDRESS | No address; look for MX record |
Like errno, the value of h_errno is zero at program startup. Checking h_errno is valid only when a failure status is returned by a DEC C RTL routine that is defined to set it.