+ if (hp) {
+ /*
+ * If name returned by gethostbyaddr is in our domain,
+ * attempt to verify that we haven't been fooled by someone
+ * in a remote net; look up the name and check that this
+ * address corresponds to the name.
+ */
+ if (local_domain(hp->h_name)) {
+ strncpy(remotehost, hp->h_name, sizeof(remotehost) - 1);
+ remotehost[sizeof(remotehost) - 1] = 0;
+ hp = gethostbyname(remotehost);
+ if (hp == NULL) {
+ syslog(LOG_INFO,
+ "Couldn't look up address for %s",
+ remotehost);
+ error("Couldn't look up address for your host");
+ exit(1);
+ } else for (; ; hp->h_addr_list++) {
+ if (!bcmp(hp->h_addr_list[0],
+ (caddr_t)&fromp->sin_addr,
+ sizeof(fromp->sin_addr)))
+ break;
+ if (hp->h_addr_list[0] == NULL) {
+ syslog(LOG_NOTICE,
+ "Host addr %s not listed for host %s",
+ inet_ntoa(fromp->sin_addr),
+ hp->h_name);
+ error("Host address mismatch");
+ exit(1);
+ }
+ }
+ }
+ hostname = hp->h_name;
+ } else
+ hostname = inet_ntoa(fromp->sin_addr);
+