/******************************************************* * Get the full host name from the cache using either * the host name or the address depending on what is * supplied. *****************************************************/ char *get_cached_fullhostname(const char *hostname,const struct sockaddr_in *sai) { struct addrinfo *pAddrInfo = NULL; if (hostname != NULL) pAddrInfo = cache.getFromCache(hostname); if ((pAddrInfo == NULL) && (sai != NULL)) pAddrInfo = cache.getFromCache(sai->sin_addr.s_addr); if (pAddrInfo == NULL) return(NULL); return(pAddrInfo->ai_canonname); } /* END get_cached_fullhostname() */
bool overwrite_cache( const char *hostname, struct addrinfo **addr) { return(cache.overwrite_cache(hostname, addr)); }
/************************************************************* * Get the full addrinfo structure returned by getaddrinfo * from the cache. ************************************************************/ struct addrinfo *get_cached_addrinfo_full(const char *hostname) { struct addrinfo *pAddrInfo = NULL; if(hostname != NULL) pAddrInfo = cache.getFromCache(hostname); if(pAddrInfo == NULL) return NULL; return pAddrInfo; } /* END get_cached_addrinfo() */
/************************************************************* * Get the address from the host name. ***********************************************************/ struct sockaddr_in *get_cached_addrinfo(const char *hostname) { struct addrinfo *pAddrInfo = NULL; if(hostname != NULL) pAddrInfo = cache.getFromCache(hostname); if(pAddrInfo == NULL) return NULL; return (struct sockaddr_in *)pAddrInfo->ai_addr; } /* END get_cached_addrinfo() */
/******************************************************* * Get the host name associated with an address. *****************************************************/ const char *get_cached_nameinfo( const struct sockaddr_in *sai) { const char *hostname = cache.getHostName(sai->sin_addr.s_addr); // Look up the hostname if it isn't currently in the cache if (hostname == NULL) { char host_buf[MAXLINE]; memset(&host_buf, 0, sizeof(host_buf)); if (!getnameinfo((struct sockaddr *)sai, sizeof(*sai), host_buf, sizeof(host_buf), NULL, 0, 0)) { insert_addr_name_info(NULL, host_buf); hostname = cache.getHostName(sai->sin_addr.s_addr); } } return(hostname); } /* END get_cached_nameinfo() */
/***************************************************************************** * Add a new addrinfo struct to the cache along with the host name if its not * already in the cache. ***************************************************************************/ struct addrinfo * insert_addr_name_info(struct addrinfo *pAddrInfo,const char *host) { if(pAddrInfo == NULL) { struct addrinfo hints; memset(&hints,0,sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET; hints.ai_flags = AI_CANONNAME; if(getaddrinfo(host,NULL,&hints,&pAddrInfo) != 0) { return NULL; } } return cache.addToCache(pAddrInfo,host); } /* END insert_addr_name_info() */
void dumpAddrCache() { cache.dumpCache(); }
/******************************************************* * Get the host name associated with an address. *****************************************************/ char *get_cached_nameinfo(const struct sockaddr_in *sai) { return cache.getHostName(sai->sin_addr.s_addr); } /* END get_cached_nameinfo() */