int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type, FAR struct hostent *host, FAR char *buf, size_t buflen, int *h_errnop) { FAR FILE *stream; int herrnocode; int nread; DEBUGASSERT(addr != NULL && host != NULL && buf != NULL); DEBUGASSERT(type == AF_INET || type == AF_INET6); /* Make sure that the h_errno has a non-error code */ if (h_errnop) { *h_errnop = 0; } #ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback address */ if (lib_localhost(addr, len, type, host, buf, buflen, h_errnop) == 0) { /* Yes.. we are done */ return OK; } #endif /* TODO: * * 1. Look in the DNS cache to see if we have the address mapping already * in place. If not, * 2. Perform a reverse DNS lookup. And if that fails as well, then * finally * 3. Search the hosts file for a match. */ /* Search the hosts file for a match */ return lib_hostfile_lookup(addr, len, type, host, buf, buflen, h_errnop); }
int gethostbyname_r(FAR const char *name, FAR struct hostent *host, FAR char *buf, size_t buflen, int *h_errnop) { #ifdef CONFIG_NETDB_DNSCLIENT int ret; #endif DEBUGASSERT(name != NULL && host != NULL && buf != NULL); /* Make sure that the h_errno has a non-error code */ if (h_errnop) { *h_errnop = 0; } /* Check for a numeric hostname */ if (lib_numeric_address(name, host, buf, buflen) == 0) { /* Yes.. we are done */ return OK; } #ifdef CONFIG_NET_LOOPBACK /* Check for the local loopback host name */ if (lib_localhost(name, host, buf, buflen) == 0) { /* Yes.. we are done */ return OK; } #endif /* Try to find the name in the HOSTALIASES environment variable */ /* REVISIT: Not implemented */ #ifdef CONFIG_NETDB_DNSCLIENT #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 /* Check if we already have this hostname mapping cached */ ret = lib_find_answer(name, host, buf, buflen); if (ret >= 0) { /* Found the address mapping in the cache */ return OK; } #endif /* Try to get the host address using the DNS name server */ ret = lib_dns_lookup(name, host, buf, buflen); if (ret >= 0) { /* Successful DNS lookup! */ return OK; } #endif /* CONFIG_NETDB_DNSCLIENT */ #ifdef CONFIG_NETDB_HOSTFILE /* Search the hosts file for a match */ return lib_hostfile_lookup(name, host, buf, buflen, h_errnop); #else /* The host file file is not supported. The host name mapping was not * found from any lookup heuristic */ if (h_errnop) { *h_errnop = HOST_NOT_FOUND; } return ERROR; #endif }