PageRenderTime 24ms CodeModel.GetById 44ms RepoModel.GetById 1ms app.codeStats 0ms

/iputils-20070202-idn.patch

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