1 /* example4.c Example code showing how to use Libidn.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of GNU Libidn.
6 * GNU Libidn is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * GNU Libidn is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU Libidn; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <stringprep.h> /* stringprep_locale_charset() */
26 #include <idna.h> /* idna_to_ascii_lz() */
29 * Compiling using libtool and pkg-config is recommended:
31 * $ libtool cc -o example4 example4.c `pkg-config --cflags --libs libidn`
33 * Input domain encoded as `ISO-8859-1': www.xn--rksmrgsa-0zap8p.example
34 * Read string (length 33): 77 77 77 2e 78 6e 2d 2d 72 6b 73 6d 72 67 73 61 2d 30 7a 61 70 38 70 2e 65 78 61 6d 70 6c 65
35 * ACE label (length 23): 'www.räksmörgåsa.example'
36 * 77 77 77 2e 72 e4 6b 73 6d f6 72 67 e5 73 61 2e 65 78 61 6d 70 6c 65
42 main (int argc
, char *argv
[])
49 printf ("Input domain encoded as `%s': ", stringprep_locale_charset ());
51 fgets (buf
, BUFSIZ
, stdin
);
52 buf
[strlen (buf
) - 1] = '\0';
54 printf ("Read string (length %d): ", strlen (buf
));
55 for (i
= 0; i
< strlen (buf
); i
++)
56 printf ("%02x ", buf
[i
] & 0xFF);
59 rc
= idna_to_ascii_lz (buf
, &p
, 0);
60 if (rc
!= IDNA_SUCCESS
)
62 printf ("ToUnicode() failed... %d\n", rc
);
66 printf ("ACE label (length %d): '%s'\n", strlen (p
), p
);
67 for (i
= 0; i
< strlen (p
); i
++)
68 printf ("%02x ", p
[i
] & 0xFF);