+ amfree(buf);
+}
+
+int
+check_name_give_sockaddr(
+ const char *hostname,
+ struct sockaddr *addr,
+ char **errstr)
+{
+ int result;
+ struct addrinfo *res = NULL, *res1;
+ char *canonname;
+
+ result = resolve_hostname(hostname, 0, &res, &canonname);
+ if (result != 0) {
+ dbprintf(_("check_name_give_sockaddr: resolve_hostname('%s'): %s\n"), hostname, gai_strerror(result));
+ *errstr = newvstrallocf(*errstr,
+ _("check_name_give_sockaddr: resolve_hostname('%s'): %s"),
+ hostname, gai_strerror(result));
+ goto error;
+ }
+ if (canonname == NULL) {
+ dbprintf(_("resolve_hostname('%s') did not return a canonical name\n"), hostname);
+ *errstr = newvstrallocf(*errstr,
+ _("check_name_give_sockaddr: resolve_hostname('%s') did not return a canonical name"),
+ hostname);
+ goto error;
+ }
+
+ if (strncasecmp(hostname, canonname, strlen(hostname)) != 0) {
+ dbprintf(_("%s doesn't resolve to itself, it resolves to %s\n"),
+ hostname, canonname);
+ *errstr = newvstrallocf(*errstr,
+ _("%s doesn't resolve to itself, it resolves to %s"),
+ hostname, canonname);
+ goto error;
+ }
+
+ for(res1=res; res1 != NULL; res1 = res1->ai_next) {
+ if (cmp_sockaddr((struct sockaddr_storage *)res1->ai_addr, (struct sockaddr_storage *)addr, 1) == 0) {
+ freeaddrinfo(res);
+ amfree(canonname);
+ return 0;
+ }
+ }
+
+ dbprintf(_("%s doesn't resolve to %s"),
+ hostname, str_sockaddr((struct sockaddr_storage *)addr));
+ *errstr = newvstrallocf(*errstr,
+ "%s doesn't resolve to %s",
+ hostname, str_sockaddr((struct sockaddr_storage *)addr));
+error:
+ if (res) freeaddrinfo(res);
+ amfree(canonname);
+ return -1;