diff --git a/ares/CHANGES b/ares/CHANGES
index 3c91e27d061966be3a0e706bb3d5e925fa7038c7..d96078499df81c6e314a1d6e55dda023284720da 100644
--- a/ares/CHANGES
+++ b/ares/CHANGES
@@ -1,5 +1,12 @@
   Changelog for the c-ares project
 
+* May 10, 2006
+
+- Bram Matthys brought my attention to a libtool peculiarity where detecting
+  things such as C++ compiler actually is a bad thing and since we don't need
+  that detection I added a work-around, much inspired by a previous patch by
+  Paolo Bonzini. This also shortens the configure script quite a lot.
+
 * May 3, 2006
 
 - Nick Mathewson added the ARES_OPT_SOCK_STATE_CB option that when set makes
diff --git a/ares/acinclude.m4 b/ares/acinclude.m4
index 64804dc95e89f2ed1eccaf2f6702b56c4e8bb09a..9a5c7e77583245cee42aea7187af4c9ed8e1f4f9 100644
--- a/ares/acinclude.m4
+++ b/ares/acinclude.m4
@@ -826,3 +826,39 @@ else
 fi
 ])
 
+# Prevent libtool for checking how to run C++ compiler and check for other
+# tools we don't want to use. We do this by m4-defining the _LT_AC_TAGCONFIG
+# variable to the code to run, as by default it uses a much more complicated
+# approach. The code below that is actually added seems to be used for cases
+# where configure has trouble figuring out what C compiler to use but where
+# the installed libtool has an idea.
+#
+# This function is a re-implemented version of the Paolo Bonzini fix posted to
+# the c-ares mailing list by Bram Matthys on May 6 2006. My version removes
+# redundant code but also adds the LTCFLAGS check that wasn't in that patch.
+#
+# Some code in this function was extracted from the generated configure script.
+#
+# CARES_CLEAR_LIBTOOL_TAGS
+AC_DEFUN([CARES_CLEAR_LIBTOOL_TAGS],
+  [m4_define([_LT_AC_TAGCONFIG], [
+  if test -f "$ltmain"; then
+    if test ! -f "${ofile}"; then
+      AC_MSG_WARN([output file `$ofile' does not exist])
+    fi
+
+    if test -z "$LTCC"; then
+      eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
+      if test -z "$LTCC"; then
+        AC_MSG_WARN([output file `$ofile' does not look like a libtool
+script])
+      else
+        AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
+      fi
+    fi
+    if test -z "$LTCFLAGS"; then
+      eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
+    fi
+  fi
+  ])]
+)
diff --git a/ares/configure.ac b/ares/configure.ac
index ea38b8923464fa95f6792c16a9816335337a4d8f..f862f8bf3eb7405ea7cc6cd5937203f343193250 100644
--- a/ares/configure.ac
+++ b/ares/configure.ac
@@ -66,6 +66,7 @@ AC_HELP_STRING([--disable-debug],[Disable debug options]),
 )
 
 dnl libtool setup
+CARES_CLEAR_LIBTOOL_TAGS
 AC_PROG_LIBTOOL
 
 dnl Checks for header files.
@@ -433,7 +434,8 @@ int main()
   }
   ], [
        AC_MSG_RESULT(yes)
-       AC_DEFINE_UNQUOTED(HAVE_INET_NTOP_IPV6,1,[Define to 1 if inet_ntop supports IPv6.])
+       AC_DEFINE_UNQUOTED(HAVE_INET_NTOP_IPV6,1,
+          [Define to 1 if inet_ntop supports IPv6.])
      ], AC_MSG_RESULT(no),AC_MSG_RESULT(no))
 fi
 
@@ -499,13 +501,15 @@ dnl and get the types of five of its arguments.
 CURL_CHECK_FUNC_GETNAMEINFO
 
 
-dnl God bless non-standardized functions! We need to see which getservbyport_r variant is available
+dnl God bless non-standardized functions! We need to see which getservbyport_r
+dnl variant is available
 CARES_CHECK_GETSERVBYPORT_R
 
 CURL_CHECK_NONBLOCKING_SOCKET
 
 AC_C_BIGENDIAN(
-    [AC_DEFINE(ARES_BIG_ENDIAN, 1, [define this if ares is built for a big endian system])],
+    [AC_DEFINE(ARES_BIG_ENDIAN, 1,
+      [define this if ares is built for a big endian system])],
     ,
     [AC_MSG_WARN([couldn't figure out endianess, assuming little endian!])]
 )