PageRenderTime 21ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/net-misc/iputils/files/iputils-20070202-idn.patch

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