This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Internationalized domain names teaser


There was not much discussion on what API to use for internationalized
domain names last time around, so I made GNU Libidn into a GNU Libc
"add-on" (tested with 2.3.1) and implemented the IMHO simplest and
best approach; a new flag to getaddrinfo().

GNU Libidn is available from <http://www.gnu.org/software/libidn/>,
the instructions for building it as a Libc add-on is included below,
as is a simple example application using the new API.

Do you believe this is useful for inclusion in libc, or should I
continue distribute it as a third-party add-on?  As I'm not a regular
libc hacker, ideally I'd like for someone else to take over maintaince
of the glue code.

Thanks.

Libidn libc/README -- Instructions for building as a GNU Libc add-on.
See the end for copying conditions.

GNU Libidn can be built as part of GNU Libc if you follow these
instructions.  Note that you should note run configure in Libidn.

1) Unpack Libc:

$ tar xfz glibc-2.3.1.tar.gz

2) Unpack Libidn inside the Libc directory:

$ cd glibc-2.3.1
$ tar xfz ~/libidn-0.1.5.tar.gz

3) Set up Libidn for building as a Libc add-on:

$ cd libidn-0.1.5
$ cp libc/Makefile .
$ cp libc/configure .
$ cp libc/getaddrinfo.c ../sysdeps/posix/
$ cp libc/netdb.h ../resolv

pi) If you are using libidn from CVS you must build some files manually:

$ perl gen-unicode-tables.pl -decomp 3.2 UnicodeData-3.2.0.txt LineBreak-3.2.0.txt SpecialCasing-3.2.0.txt CaseFolding-3.2.0.txt CompositionExclusions-3.2.0.txt
$ perl gen-stringprep-tables.pl rfc3454.txt
$ cp stringprep.h.in stringprep.h

4) Configure Libc indicating that the Libidn add-on should be built:

$ cd ..
$ ./configure --enable-add-ons=linuxthreads,libidn --prefix=/usr/local/glibc
$ make install

5) Run the example

$ cd libidn/libc
$ gcc -o example example.c -L/usr/local/glibc/lib -Wl,-rpath,/usr/local/glibc/lib -nostdinc -I/usr/local/glibc/include -I/usr/include -I/usr/lib/gcc-lib/i386-linux/2.95.4/include
$ CHARSET=iso-8859-1 ./example
locale charset `iso-8859-1'
gettaddrinfo(räksmörgås.josefsson.org):
address `217.13.230.178'
canonical name `178.230.13.217.in-addr.dgcsystems.net'
$

The file libc.patch in this directory contains the modifications made
to getaddrinfo.c and netdb.h, should you wish to try this with another
GNU Libc version.

----------------------------------------------------------------------
Copyright (C) 2003 Simon Josefsson

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

/* example.c	Example code showing how to use IDN enabled getaddrinfo().
 * Copyright (C) 2003  Simon Josefsson
 *
 * This file is part of GNU Libidn.
 *
 * GNU Libidn is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * GNU Libidn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GNU Libidn; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#define _GNU_SOURCE 1
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

/*
 * Compiling against IDN enabled Libc:
 *
 * $ gcc -o example example.c -L/usr/local/glibc/lib -Wl,-rpath,/usr/local/glibc/lib -nostdinc -I/usr/local/glibc/include -I/usr/include -I/usr/lib/gcc-lib/i386-linux/2.95.4/include
 * $ CHARSET=iso-8859-1 ./example
 * locale charset `iso-8859-1'
 * gettaddrinfo(räksmörgås.josefsson.org):
 * address `217.13.230.178'
 * canonical name `178.230.13.217.in-addr.dgcsystems.net'
 * $
 *
 * Internally the name iesg--rksmrgsa-0zap8p.josefsson.org is looked
 * up in DNS.
 */

int
main(int argc, char *argv[])
{
  char *in = argc > 1 ? argv[1] : "räksmörgås.josefsson.org";
  struct addrinfo hints;
  struct addrinfo *res = NULL;
  int rc;

  printf("locale charset `%s'\n", stringprep_locale_charset());

  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_CANONNAME|AI_IDN;

  printf("gettaddrinfo(%s):\n", in);
  rc = getaddrinfo(in, NULL, &hints, &res);
  if (rc)
    printf("gai err %d: %s\n", rc, gai_strerror(rc));
  else if (res)
    printf("address `%s'\ncanonical name `%s'\n",
	   res->ai_addr ?
	   inet_ntoa(((struct sockaddr_in*)res->ai_addr)->sin_addr) : "ERROR",
	   res->ai_canonname ? res->ai_canonname : "ERROR");
  else
    printf("Bad magic\n");

  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]