nfs_client *clientlist[MCL_MAXTYPES] = { NULL, };
+/* if canonical is set, then we *know* this is already a canonical name
+ * so hostname lookup is avoided.
+ * This is used when reading /proc/fs/nfs/exports
+ */
nfs_client *
-client_lookup(char *hname)
+client_lookup(char *hname, int canonical)
{
nfs_client *clp = NULL;
int htype;
htype = client_gettype(hname);
- if (htype == MCL_FQDN) {
+ if (htype == MCL_FQDN && !canonical) {
+ struct hostent *hp2;
hp = gethostbyname(hname);
if (hp == NULL || hp->h_addrtype != AF_INET) {
xlog(L_ERROR, "%s has non-inet addr", hname);
return NULL;
}
- hp = hostent_dup (hp);
+ /* make sure we have canonical name */
+ hp2 = hostent_dup(hp);
+ hp = gethostbyaddr(hp2->h_addr, hp2->h_length,
+ hp2->h_addrtype);
+ if (hp) {
+ hp = hostent_dup(hp);
+ /* but now we might not have all addresses... */
+ if (hp2->h_addr_list[1]) {
+ struct hostent *hp3 =
+ gethostbyname(hp->h_name);
+ if (hp3) {
+ free(hp);
+ hp = hostent_dup(hp3);
+ }
+ }
+ free(hp2);
+ } else
+ hp = hp2;
+
hname = (char *) hp->h_name;
for (clp = clientlist[htype]; clp; clp = clp->m_next) {
}
} else {
for (clp = clientlist[htype]; clp; clp = clp->m_next) {
- if (strcmp(hname, clp->m_hostname)==0)
+ if (strcasecmp(hname, clp->m_hostname)==0)
break;
}
}