Ditch the sysvinit stuff
[profile/ivi/iputils.git] / packaging / iputils-20070202-idn.patch
1 diff -up iputils-s20100418/Makefile.idn iputils-s20100418/Makefile
2 --- iputils-s20100418/Makefile.idn      2010-04-20 16:07:59.018479157 +0200
3 +++ iputils-s20100418/Makefile  2010-04-20 16:10:06.389481427 +0200
4 @@ -28,8 +28,13 @@ all: $(TARGETS)
5  
6  tftpd: tftpd.o tftpsubs.o
7 -arping: arping.o -lsysfs
8 +arping: arping.o
9 +
10  ping: ping.o ping_common.o
11 -ping6: ping6.o ping_common.o -lresolv -lcrypto
12 +       $(CC) $(CFLAGS) $(LDFLAGS) ping.o ping_common.o -lidn -o ping
13 +
14 +ping6: ping6.o ping_common.o
15 +       $(CC) $(CFLAGS) $(LDFLAGS) ping6.o ping_common.o -lresolv -lcrypto -o ping6
16 +
17  ping.o ping6.o ping_common.o: ping_common.h
18  tftpd.o tftpsubs.o: tftp.h
19  
20 diff -up iputils-s20100418/ping.c.idn iputils-s20100418/ping.c
21 --- iputils-s20100418/ping.c.idn        2010-04-20 16:07:59.038484302 +0200
22 +++ iputils-s20100418/ping.c    2010-04-20 16:07:59.077485007 +0200
23 @@ -58,6 +58,9 @@ char copyright[] =
24   *     This program has to run SUID to ROOT to access the ICMP socket.
25   */
26  
27 +#include <idna.h>
28 +#include <locale.h>
29 +
30  #include "ping_common.h"
31  
32  #include <netinet/ip.h>
33 @@ -123,6 +126,10 @@ main(int argc, char **argv)
34         char *target, hnamebuf[MAX_HOSTNAMELEN];
35         char rspace[3 + 4 * NROUTES + 1];       /* record route space */
36  
37 +       char *idn;
38 +       int rc = 0;
39 +       setlocale(LC_ALL, "");
40 +
41         icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
42         socket_errno = errno;
43  
44 @@ -250,13 +257,27 @@ main(int argc, char **argv)
45                         if (argc == 1)
46                                 options |= F_NUMERIC;
47                 } else {
48 -                       hp = gethostbyname(target);
49 +                       rc = idna_to_ascii_lz (target, &idn, 0);
50 +                       if (rc == IDNA_SUCCESS)
51 +                               hp = gethostbyname (idn);
52 +                       else {
53 +                               fprintf(stderr, "ping: IDN encoding of '%s' failed with error code %d\n", target, rc);
54 +                               exit(2);
55 +                       }
56 +                       free(idn);
57                         if (!hp) {
58                                 fprintf(stderr, "ping: unknown host %s\n", target);
59                                 exit(2);
60                         }
61                         memcpy(&whereto.sin_addr, hp->h_addr, 4);
62 -                       strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
63 +                       rc = idna_to_unicode_lzlz (hp->h_name, &idn, 0);
64 +                       if (rc == IDNA_SUCCESS)
65 +                               strncpy(hnamebuf, idn, sizeof(hnamebuf) - 1);
66 +                       else {
67 +                               fprintf(stderr, "ping: IDN encoding of '%s' failed with error code %d\n", hp->h_name, rc);
68 +                               exit(2);
69 +                       }
70 +                       free(idn);
71                         hnamebuf[sizeof(hnamebuf) - 1] = 0;
72                         hostname = hnamebuf;
73                 }
74 diff -up iputils-s20100418/ping_common.c.idn iputils-s20100418/ping_common.c
75 --- iputils-s20100418/ping_common.c.idn 2010-04-20 16:07:59.039478452 +0200
76 +++ iputils-s20100418/ping_common.c     2010-04-20 16:07:59.069478660 +0200
77 @@ -1,3 +1,5 @@
78 +#include <locale.h>
79 +
80  #include "ping_common.h"
81  #include <ctype.h>
82  #include <sched.h>
83 @@ -98,6 +100,7 @@ static void fill(char *patp)
84  
85  void common_options(int ch)
86  {
87 +       setlocale(LC_ALL, "C");
88         switch(ch) {
89         case 'a':
90                 options |= F_AUDIBLE;
91 @@ -242,6 +245,7 @@ void common_options(int ch)
92         default:
93                 abort();
94         }
95 +       setlocale(LC_ALL, "");
96  }
97  
98