1
0

patch-src_traceroute_c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. $Id: update-patches 24 2008-08-31 14:56:13Z wbx $
  2. --- ndisc6-0.9.8.orig/src/traceroute.c 2008-05-01 14:52:28.000000000 +0200
  3. +++ ndisc6-0.9.8/src/traceroute.c 2009-05-10 19:31:06.000000000 +0200
  4. @@ -149,6 +149,7 @@ static ssize_t
  5. recv_payload (int fd, void *buf, size_t len,
  6. struct sockaddr_in6 *addr, int *hlim)
  7. {
  8. + struct cmsghdr *cmsg;
  9. char cbuf[CMSG_SPACE (sizeof (int))];
  10. struct iovec iov =
  11. {
  12. @@ -170,7 +171,7 @@ recv_payload (int fd, void *buf, size_t
  13. return val;
  14. /* ensures the hop limit is 255 */
  15. - for (struct cmsghdr *cmsg = CMSG_FIRSTHDR (&hdr);
  16. + for (cmsg = CMSG_FIRSTHDR (&hdr);
  17. cmsg != NULL;
  18. cmsg = CMSG_NXTHDR (&hdr, cmsg))
  19. if ((cmsg->cmsg_level == IPPROTO_IPV6)
  20. @@ -625,14 +626,16 @@ static void
  21. display (const tracetest_t *tab, unsigned min_ttl, unsigned max_ttl,
  22. unsigned retries)
  23. {
  24. - for (unsigned ttl = min_ttl; ttl <= max_ttl; ttl++)
  25. + unsigned int ttl, col;
  26. +
  27. + for (ttl = min_ttl; ttl <= max_ttl; ttl++)
  28. {
  29. struct sockaddr_in6 hop = { .sin6_family = AF_UNSPEC };
  30. const tracetest_t *line = tab + retries * (ttl - min_ttl);
  31. printf ("%2d ", ttl);
  32. - for (unsigned col = 0; col < retries; col++)
  33. + for (col = 0; col < retries; col++)
  34. {
  35. const tracetest_t *test = line + col;
  36. if (test->result == TRACE_TIMEOUT)
  37. @@ -821,6 +824,7 @@ static void setup_socket (int fd)
  38. static int setsock_rth (int fd, int type, const char **segv, int segc)
  39. {
  40. + int i;
  41. uint8_t hdr[inet6_rth_space (type, segc)];
  42. inet6_rth_init (hdr, sizeof (hdr), type, segc);
  43. @@ -829,7 +833,7 @@ static int setsock_rth (int fd, int type
  44. hints.ai_family = AF_INET6;
  45. hints.ai_flags = AI_IDN;
  46. - for (int i = 0; i < segc; i++)
  47. + for (i = 0; i < segc; i++)
  48. {
  49. struct addrinfo *res;
  50. @@ -868,7 +872,8 @@ static struct
  51. static int prepare_sockets (void)
  52. {
  53. - for (unsigned i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  54. + unsigned int i;
  55. + for (i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  56. {
  57. protofd[i].fd = socket (AF_INET6, SOCK_RAW, protofd[i].protocol);
  58. if (protofd[i].fd == -1)
  59. @@ -883,8 +888,9 @@ static int prepare_sockets (void)
  60. static int get_socket (int protocol)
  61. {
  62. + unsigned int i;
  63. errno = EPROTONOSUPPORT;
  64. - for (unsigned i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  65. + for (i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  66. if (protofd[i].protocol == protocol)
  67. {
  68. int fd = protofd[i].fd;
  69. @@ -902,7 +908,8 @@ static int get_socket (int protocol)
  70. static void drop_sockets (void)
  71. {
  72. - for (unsigned i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  73. + unsigned int i;
  74. + for (i = 0; i < sizeof (protofd) / sizeof (protofd[0]); i++)
  75. if (protofd[i].fd != -1)
  76. close (protofd[i].fd);
  77. }
  78. @@ -914,6 +921,8 @@ traceroute (const char *dsthost, const c
  79. unsigned timeout, unsigned delay, unsigned retries,
  80. size_t packet_len, int min_ttl, int max_ttl)
  81. {
  82. + unsigned int i, j, step, progress;
  83. +
  84. /* Creates ICMPv6 socket to collect error packets */
  85. int icmpfd = get_socket (IPPROTO_ICMPV6);
  86. if (icmpfd == -1)
  87. @@ -1020,7 +1029,7 @@ traceroute (const char *dsthost, const c
  88. .filter = f,
  89. };
  90. - for (unsigned i = 0; i < 4; i++)
  91. + for (i = 0; i < 4; i++)
  92. {
  93. /* A = icmp->ip6_dst.s6_addr32[i]; */
  94. pc->code = BPF_LD + BPF_W + BPF_ABS;
  95. @@ -1076,7 +1085,7 @@ traceroute (const char *dsthost, const c
  96. tracetest_t tab[(1 + max_ttl - min_ttl) * retries];
  97. memset (tab, 0, sizeof (tab));
  98. - for (unsigned step = 1, progress = 0;
  99. + for (step = 1, progress = 0;
  100. step < (1 + max_ttl - min_ttl) + retries;
  101. step++)
  102. {
  103. @@ -1093,10 +1102,10 @@ traceroute (const char *dsthost, const c
  104. mono_nanosleep (&delay_ts);
  105. /* Sends requests */
  106. - for (unsigned i = 0; i < retries; i++)
  107. + for (j = 0; j < retries; j++)
  108. {
  109. - int attempt = (retries - 1) - i;
  110. - int hlim = min_ttl + step + i - retries;
  111. + int attempt = (retries - 1) - j;
  112. + int hlim = min_ttl + step + j - retries;
  113. if ((hlim > max_ttl) || (hlim < min_ttl))
  114. continue;