X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fexport%2Fhostname.c;h=8a23a89b7874466b8146946e5ec65a15b96d57b8;hp=f88e0a485290cb878ab670f4b6917648c3903485;hb=5d954d871fb265af584faef5df6e2e7e6ada7c3b;hpb=77c32fa565d6af59cbeb8601e08efa9af6ef3d81 diff --git a/support/export/hostname.c b/support/export/hostname.c index f88e0a4..8a23a89 100644 --- a/support/export/hostname.c +++ b/support/export/hostname.c @@ -5,7 +5,9 @@ * */ -#include "config.h" +#ifdef HAVE_CONFIG_H +#include +#endif /* #define TEST @@ -118,7 +120,7 @@ hostent_dup (struct hostent *hp) len_addr_list += align (hp->h_length, ALIGNMENT) + sizeof (char *); } - + cp = (struct hostent *) xmalloc (len_ent + len_name + len_aliases + len_addr_list); @@ -219,51 +221,50 @@ matchhostname (const char *h1, const char *h2) /* Map IP to hostname, and then map back to addr to make sure it is a - * reliable hostname + * reliable hostname */ struct hostent * get_reliable_hostbyaddr(const char *addr, int len, int type) { - struct hostent *hp; + struct hostent *hp = NULL; + struct hostent *reverse; + struct hostent *forward; char **sp; - struct hostent *forward = NULL; - char *tmpname; - hp = gethostbyaddr(addr, len , type); - if (!hp) - return hp; + reverse = gethostbyaddr (addr, len, type); + if (!reverse) + return NULL; /* must make sure the hostent is authorative. */ - hp = hostent_dup (hp); - tmpname = xstrdup((hp)->h_name); - if (tmpname) { - forward = gethostbyname(tmpname); - free(tmpname); - } + reverse = hostent_dup (reverse); + forward = gethostbyname (reverse->h_name); + if (forward) { /* now make sure the "addr" is in the list */ for (sp = forward->h_addr_list ; *sp ; sp++) { - if (memcmp(*sp, addr, forward->h_length)==0) + if (memcmp (*sp, addr, forward->h_length) == 0) break; } - - if (!*sp) { + + if (*sp) { + /* it's valid */ + hp = hostent_dup (forward); + } + else { /* it was a FAKE */ - xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse", - forward->h_name, inet_ntoa(*(struct in_addr*)addr)); - return NULL; + xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse", + reverse->h_name, inet_ntoa(*(struct in_addr*)addr)); } - free (hp); - hp = hostent_dup (forward); } else { /* never heard of it. misconfigured DNS? */ - xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist", - forward->h_name, inet_ntoa(*(struct in_addr*)addr)); - return NULL; + xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist", + reverse->h_name, inet_ntoa(*(struct in_addr*)addr)); } + + free (reverse); return hp; } @@ -276,7 +277,7 @@ print_host (struct hostent *hp) if (hp) { - printf ("official hostname: %s\n", hp->h_name); + printf ("official hostname: %s\n", hp->h_name); printf ("aliases:\n"); for (sp = hp->h_aliases; *sp; sp++) printf (" %s\n", *sp);