The following is a patch that demonstrates GNU Libidn's
internationalized domain name features in the GNU InetUtils "ping"
utility.
This is just a teaser, limited by two facts:
1) The real ACE prefix has not been chosen by the RFC editor yet, so
it uses "iesg--" for now.
2) It is likely that this functionality will be wrapped in a system
function similar to gethostbyname() so that each and every network
application does not have to link with GNU Libidn directly.
For more information on GNU Libidn, see:
Simon Josefsson 2003-01-08
latte:/home/jas/src/inetutils/ping# ./ping räksmörgås
PING räksmörgås [iesg--rksmrgs-5wao1o.josefsson.org] (217.13.230.178): 56 data bytes
64 bytes from 217.13.230.178: icmp_seq=0 ttl=54 time=16.128 ms
64 bytes from 217.13.230.178: icmp_seq=1 ttl=54 time=16.872 ms
64 bytes from 217.13.230.178: icmp_seq=2 ttl=54 time=16.923 ms
64 bytes from 217.13.230.178: icmp_seq=3 ttl=54 time=16.076 ms
64 bytes from 217.13.230.178: icmp_seq=4 ttl=54 time=16.825 ms
--- räksmörgås [iesg--rksmrgs-5wao1o.josefsson.org] ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 16.076/16.565/16.923/0.380 ms
latte:/home/jas/src/inetutils/ping#
? config.h
? stamp-h1
Index: configure.ac
===================================================================
RCS file: /cvsroot/inetutils/inetutils/configure.ac,v
retrieving revision 1.16
diff -u -p -r1.16 configure.ac
--- configure.ac 23 Dec 2002 05:05:46 -0000 1.16
+++ configure.ac 8 Jan 2003 12:42:17 -0000
@@ -799,6 +799,19 @@ case "$host" in
;;
esac
+# Check for GNU Libidn
+AC_ARG_WITH(idn,
+ AC_HELP_STRING([--without-idn],
+ [don't use GNU Libidn for IDN]))
+if test "$with_idn" != "no" ; then
+ PKG_CHECK_MODULES(LIBIDN, libidn >= 0.1.2, with_idn=yes, with_idn=no)
+fi
+if test "$with_idn" != "no" ; then
+ AC_DEFINE(HAVE_IDN, 1, [Define to 1 to use GNU Libidn for IDN.])
+fi
+AC_MSG_CHECKING([if GNU Libidn should be used for IDN])
+AC_MSG_RESULT($with_idn)
+
AC_CONFIG_FILES([Makefile libinetutils/Makefile libtelnet/Makefile glob/Makefile
libicmp/Makefile ping/Makefile ftp/Makefile ftpd/Makefile inetd/Makefile
rcp/Makefile
Index: libicmp/Makefile.am
===================================================================
RCS file: /cvsroot/inetutils/inetutils/libicmp/Makefile.am,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile.am
--- libicmp/Makefile.am 11 Feb 2002 04:17:00 -0000 1.3
+++ libicmp/Makefile.am 8 Jan 2003 12:42:17 -0000
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = ../ansi2knr
-INCLUDES = -I$(top_builddir)/include
+INCLUDES = -I$(top_builddir)/include @LIBIDN_CFLAGS@
noinst_LIBRARIES = libicmp.a
Index: libicmp/libping.c
===================================================================
RCS file: /cvsroot/inetutils/inetutils/libicmp/libping.c,v
retrieving revision 1.5
diff -u -p -r1.5 libping.c
--- libicmp/libping.c 11 Aug 2001 08:32:20 -0000 1.5
+++ libicmp/libping.c 8 Jan 2003 12:42:17 -0000
@@ -318,7 +318,17 @@ ping_set_dest (PING *ping, char *host)
}
else
{
- struct hostent *hp = gethostbyname (host);
+ struct hostent *hp;
+#ifdef HAVE_IDN
+ char *p;
+ int rc;
+
+ rc = idna_locale_to_ace (host, &p);
+ hp = gethostbyname (p);
+ free(p);
+#else
+ hp = gethostbyname (host);
+#endif
if (!hp)
return 1;
@@ -327,7 +337,18 @@ ping_set_dest (PING *ping, char *host)
hp->h_length = sizeof (s_in->sin_addr);
memcpy (&s_in->sin_addr, hp->h_addr, hp->h_length);
+#ifdef HAVE_IDN
+ ping->ping_hostname = malloc(strlen(host) +
+ strlen(" [") +
+ strlen(hp->h_name) +
+ strlen("]") + 1);
+ strcpy(ping->ping_hostname, host);
+ strcat(ping->ping_hostname, " [");
+ strcat(ping->ping_hostname, hp->h_name);
+ strcat(ping->ping_hostname, "]");
+#else
ping->ping_hostname = strdup (hp->h_name);
+#endif
}
return 0;
}
Index: ping/Makefile.am
===================================================================
RCS file: /cvsroot/inetutils/inetutils/ping/Makefile.am,v
retrieving revision 1.12
diff -u -p -r1.12 Makefile.am
--- ping/Makefile.am 28 Apr 2002 17:16:30 -0000 1.12
+++ ping/Makefile.am 8 Jan 2003 12:42:17 -0000
@@ -7,7 +7,7 @@ EXTRA_PROGRAMS = ping
man_MANS = ping.8
EXTRA_DIST = $(man_MANS)
-LDADD = -L../libinetutils -linetutils -lm -L../libicmp -licmp
+LDADD = -L../libinetutils -linetutils -lm -L../libicmp -licmp @LIBIDN_LIBS@
INCLUDES = -I$(top_srcdir)/libicmp -I$(top_builddir)/include
ping_SOURCES = ping.c \