Author: Jaret Cantu <jaret.cantu@timesys.com>
Date:   Tue Oct 27 20:54:38 2015 -0400

    Check for libidn add-on before using GNU-exclusive flags.
    
    The GNU-exclusive IDN flags for getaddrinfo are only usable
    with glibc and when it was built with the libidn add-on. The
    flags may still be defined when support does not exist, and
    attempting to pass the unsupported flags into getaddrinfo
    will cause it to fail.
    
    Since there is no header which provides information about
    which glibc add-ons are enabled, check for the usability of
    libcidn, which is only present when the libidn add-on was
    built for glibc.

diff --git a/ftp/ftp.c b/ftp/ftp.c
index 9813586..907686d 100644
--- a/ftp/ftp.c
+++ b/ftp/ftp.c
@@ -154,11 +154,13 @@ hookup (char *host, int port)
   hints.ai_family = usefamily;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   status = getaddrinfo (rhost, portstr, &hints, &res);
diff --git a/ping/libping.c b/ping/libping.c
index 4a9f73d..1c9f6d5 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -283,11 +283,13 @@ ping_set_dest (PING * ping, char *host)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET;
   hints.ai_flags = AI_CANONNAME;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-# endif
-# ifdef AI_CANONIDN
+#  endif
+#  ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+#  endif
 # endif
 
   rc = getaddrinfo (p, NULL, &hints, &res);
diff --git a/ping/ping6.c b/ping/ping6.c
index b0e0bf1..67ba703 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -1015,11 +1015,13 @@ ping_set_dest (PING * ping, char *host)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET6;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   err = getaddrinfo (rhost, NULL, &hints, &result);
diff --git a/src/tftp.c b/src/tftp.c
index 1d3c353..37b4cf6 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -330,11 +330,13 @@ resolve_name (char *name)
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = SOCK_DGRAM;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   err = getaddrinfo (rname, "tftp", &hints, &aiptr);
diff --git a/src/traceroute.c b/src/traceroute.c
index 785dc6f..e7b39aa 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -294,10 +294,12 @@ main (int argc, char **argv)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-# ifdef AI_CANONIDN
+#  ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+#  endif
 # endif
 #endif
 
diff --git a/talk/get_addrs.c b/talk/get_addrs.c
index 6015a50..a3186d3 100644
--- a/talk/get_addrs.c
+++ b/talk/get_addrs.c
@@ -110,8 +110,10 @@ get_addrs (char *my_machine_name, char *his_machine_name)
   /* The talk-protocol is IPv4 only!  */
   hints.ai_family = AF_INET;
   hints.ai_socktype = SOCK_DGRAM;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
+#  endif
 # endif
 
   err = getaddrinfo (lhost, NULL, &hints, &res);
diff --git a/telnet/commands.c b/telnet/commands.c
index cd0c75a..2b8e6c6 100644
--- a/telnet/commands.c
+++ b/telnet/commands.c
@@ -2619,8 +2619,10 @@ tn (int argc, char *argv[])
 
 #ifdef IPV6
   hints.ai_socktype = SOCK_STREAM;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags = AI_IDN;
+#  endif
 # endif
 
   err = getaddrinfo (hostp, portp, &hints, &result);
diff --git a/config.hin b/config.hin
index c496c65..7c8862b 100644
--- a/config.hin
+++ b/config.hin
@@ -973,6 +973,9 @@
 /* Define to 1 if you have the <langinfo.h> header file. */
 #undef HAVE_LANGINFO_H
 
+/* Define to 1 if you have the `cidn' library (-lcidn). */
+#undef HAVE_LIBCIDN
+
 /* Define to 1 if you have the <libintl.h> header file. */
 #undef HAVE_LIBINTL_H
 
diff --git a/configure b/configure
index 25b68f0..6220f37 100755
--- a/configure
+++ b/configure
@@ -40514,6 +40514,55 @@ $as_echo "no" >&6; }
   fi
   CPPFLAGS=$save_CPPFLAGS
 fi
+# Check for libidn as part of the C library.
+saved_LIBS="$LIBS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for idna_to_ascii_lz in -lcidn" >&5
+$as_echo_n "checking for idna_to_ascii_lz in -lcidn... " >&6; }
+if ${ac_cv_lib_cidn_idna_to_ascii_lz+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcidn  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char idna_to_ascii_lz ();
+int
+main ()
+{
+return idna_to_ascii_lz ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_cidn_idna_to_ascii_lz=yes
+else
+  ac_cv_lib_cidn_idna_to_ascii_lz=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_cidn_idna_to_ascii_lz" >&5
+$as_echo "$ac_cv_lib_cidn_idna_to_ascii_lz" >&6; }
+if test "x$ac_cv_lib_cidn_idna_to_ascii_lz" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBCIDN 1
+_ACEOF
+
+  LIBS="-lcidn $LIBS"
+
+fi
+
+LIBS="$saved_LIBS"
+
 
 
 
