summaryrefslogtreecommitdiff
path: root/sql/hostname.cc
diff options
context:
space:
mode:
authorAlexander Nozdrin <alexander.nozdrin@oracle.com>2011-04-08 14:23:36 +0400
committerAlexander Nozdrin <alexander.nozdrin@oracle.com>2011-04-08 14:23:36 +0400
commit31e7450c608e38479b41da8e4e0fc7dad5d4246f (patch)
tree9a31e755274165f13c43c7199d63beb42ba0ce1f /sql/hostname.cc
parentb2fee393b029e5e2ec7c0a3161d665dad9fa720f (diff)
downloadmariadb-git-31e7450c608e38479b41da8e4e0fc7dad5d4246f.tar.gz
A patch for Bug#12325375: THE SERVER ON WINXP DOES NOT ALLOW CONNECTIONS
IF NO DNS-SERVER AVAILABLE. The thing is that on Windows XP getnameinfo() returns WSANO_DATA when hostname-lookup is not available. The problem was that this error code was treated as serious error and the client connection got rejected. The fix is to treat all errors from getnameinfo() as not ciritical, but add IP-address to the host cache only for EAI_NONAME (or WSANO_DATA).
Diffstat (limited to 'sql/hostname.cc')
-rw-r--r--sql/hostname.cc50
1 files changed, 22 insertions, 28 deletions
diff --git a/sql/hostname.cc b/sql/hostname.cc
index 5311d9ada73..d34df68587c 100644
--- a/sql/hostname.cc
+++ b/sql/hostname.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -366,41 +366,35 @@ bool ip_to_hostname(struct sockaddr_storage *ip_storage,
err_code= vio_getnameinfo(ip, hostname_buffer, NI_MAXHOST, NULL, 0,
NI_NAMEREQD);
- if (err_code == EAI_NONAME)
+ if (err_code)
{
- /*
- There is no reverse address mapping for the IP address. A host name
- can not be resolved.
- */
+ // NOTE: gai_strerror() returns a string ending by a dot.
- DBUG_PRINT("error", ("IP address '%s' could not be resolved: "
- "no reverse address mapping.",
- (const char *) ip_key));
+ DBUG_PRINT("error", ("IP address '%s' could not be resolved: %s",
+ (const char *) ip_key,
+ (const char *) gai_strerror(err_code)));
- sql_print_warning("IP address '%s' could not be resolved: "
- "no reverse address mapping.",
- (const char *) ip_key);
+ sql_print_warning("IP address '%s' could not be resolved: %s",
+ (const char *) ip_key,
+ (const char *) gai_strerror(err_code));
- err_status= add_hostname(ip_key, NULL);
+ if (vio_is_no_name_error(err_code))
+ {
+ /*
+ The no-name error means that there is no reverse address mapping
+ for the IP address. A host name can not be resolved.
- *hostname= NULL;
- *connect_errors= 0; /* New IP added to the cache. */
+ If it is not the no-name error, we should not cache the hostname
+ (or rather its absence), because the failure might be transient.
+ */
- DBUG_RETURN(err_status);
- }
- else if (err_code)
- {
- DBUG_PRINT("error", ("IP address '%s' could not be resolved: "
- "getnameinfo() returned %d.",
- (const char *) ip_key,
- (int) err_code));
+ add_hostname(ip_key, NULL);
- sql_print_warning("IP address '%s' could not be resolved: "
- "getnameinfo() returned error (code: %d).",
- (const char *) ip_key,
- (int) err_code);
+ *hostname= NULL;
+ *connect_errors= 0; /* New IP added to the cache. */
+ }
- DBUG_RETURN(TRUE);
+ DBUG_RETURN(FALSE);
}
DBUG_PRINT("info", ("IP '%s' resolved to '%s'.",