]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/core/iputils/patches/iputils-s20071127-idn.patch
b575006c868ba3e2532af1a6b996759891cf8c4a
[people/ms/ipfire-3.x.git] / pkgs / core / iputils / patches / iputils-s20071127-idn.patch
1 --- iputils-s20070202/ping.c.idn 2007-08-06 14:45:36.000000000 +0200
2 +++ iputils-s20070202/ping.c 2007-08-06 14:45:36.000000000 +0200
3 @@ -58,6 +58,9 @@
4 * This program has to run SUID to ROOT to access the ICMP socket.
5 */
6
7 +#include <idna.h>
8 +#include <locale.h>
9 +
10 #include "ping_common.h"
11
12 #include <netinet/ip.h>
13 @@ -122,6 +128,10 @@
14 char *target, hnamebuf[MAXHOSTNAMELEN];
15 char rspace[3 + 4 * NROUTES + 1]; /* record route space */
16
17 + char *idn;
18 + int rc = 0;
19 + setlocale(LC_ALL, "");
20 +
21 icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
22 socket_errno = errno;
23
24 @@ -242,13 +254,27 @@
25 if (argc == 1)
26 options |= F_NUMERIC;
27 } else {
28 + rc = idna_to_ascii_lz (target, &idn, 0);
29 + if (rc == IDNA_SUCCESS)
30 + hp = gethostbyname (idn);
31 + else {
32 + fprintf(stderr, "ping: IDN encoding of '%s' failed with error code %d\n", target, rc);
33 + exit(2);
34 + }
35 + free(idn);
36 - hp = gethostbyname(target);
37 if (!hp) {
38 fprintf(stderr, "ping: unknown host %s\n", target);
39 exit(2);
40 }
41 memcpy(&whereto.sin_addr, hp->h_addr, 4);
42 + rc = idna_to_unicode_lzlz (hp->h_name, &idn, 0);
43 + if (rc == IDNA_SUCCESS)
44 + strncpy(hnamebuf, idn, sizeof(hnamebuf) - 1);
45 + else {
46 + fprintf(stderr, "ping: IDN encoding of '%s' failed with error code %d\n", hp->h_name, rc);
47 + exit(2);
48 + }
49 + free(idn);
50 - strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
51 hnamebuf[sizeof(hnamebuf) - 1] = 0;
52 hostname = hnamebuf;
53 }
54 --- iputils-s20070202/Makefile.idn 2007-08-06 14:45:36.000000000 +0200
55 +++ iputils-s20070202/Makefile 2007-08-06 14:45:36.000000000 +0200
56 @@ -27,8 +27,13 @@
57
58
59 tftpd: tftpd.o tftpsubs.o
60 +
61 ping: ping.o ping_common.o
62 + $(CC) $(CFLAGS) ping.o ping_common.o -lidn -o ping
63 +
64 ping6: ping6.o ping_common.o
65 + $(CC) $(CFLAGS) ping6.o ping_common.o -o ping6
66 +
67 ping.o ping6.o ping_common.o: ping_common.h
68 tftpd.o tftpsubs.o: tftp.h
69
70 --- iputils-s20070202/ping6.c.idn 2007-08-06 14:45:36.000000000 +0200
71 +++ iputils-s20070202/ping6.c 2007-08-06 14:45:36.000000000 +0200
72 @@ -66,6 +66,9 @@
73 * More statistics could always be gathered.
74 * This program has to run SUID to ROOT to access the ICMP socket.
75 */
76 +#define _GNU_SOURCE
77 +#include <locale.h>
78 +
79 #include "ping_common.h"
80
81 #include <linux/filter.h>
82 @@ -210,6 +216,8 @@
83 int err, csum_offset, sz_opt;
84 static uint32_t scope_id = 0;
85
86 + setlocale(LC_ALL, "");
87 +
88 icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
89 socket_errno = errno;
90
91 @@ -296,6 +306,7 @@
92
93 memset(&hints, 0, sizeof(hints));
94 hints.ai_family = AF_INET6;
95 + hints.ai_flags = AI_IDN;
96 gai = getaddrinfo(target, NULL, &hints, &ai);
97 if (gai) {
98 fprintf(stderr, "unknown host\n");
99 @@ -328,6 +341,7 @@
100
101 memset(&hints, 0, sizeof(hints));
102 hints.ai_family = AF_INET6;
103 + hints.ai_flags = AI_IDN;
104 gai = getaddrinfo(target, NULL, &hints, &ai);
105 if (gai) {
106 fprintf(stderr, "unknown host\n");
107 --- iputils-s20070202/ping_common.c.idn 2007-08-06 14:45:36.000000000 +0200
108 +++ iputils-s20070202/ping_common.c 2007-08-06 14:47:41.000000000 +0200
109 @@ -1,3 +1,5 @@
110 +#include <locale.h>
111 +
112 #include "ping_common.h"
113 #include <ctype.h>
114 #include <sched.h>
115 @@ -97,6 +102,7 @@
116
117 void common_options(int ch)
118 {
119 + setlocale(LC_ALL, "C");
120 switch(ch) {
121 case 'a':
122 options |= F_AUDIBLE;
123 @@ -222,6 +230,7 @@
124 default:
125 abort();
126 }
127 + setlocale(LC_ALL, "");
128 }
129
130