patch-traceroute_mod-tcp_c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. --- traceroute-2.0.19.orig/traceroute/mod-tcp.c 2012-03-27 16:01:15.000000000 +0200
  2. +++ traceroute-2.0.19/traceroute/mod-tcp.c 2013-12-29 20:16:23.000000000 +0100
  3. @@ -18,6 +18,24 @@
  4. #include <netinet/ip6.h>
  5. #include <netinet/tcp.h>
  6. +#if !defined(__GLIBC__)
  7. +# define TCPOPT_EOL 0
  8. +# define TCPOPT_NOP 1
  9. +# define TCPOPT_MAXSEG 2
  10. +# define TCPOLEN_MAXSEG 4
  11. +# define TCPOPT_WINDOW 3
  12. +# define TCPOLEN_WINDOW 3
  13. +# define TCPOPT_SACK_PERMITTED 4 /* Experimental */
  14. +# define TCPOLEN_SACK_PERMITTED 2
  15. +# define TCPOPT_SACK 5 /* Experimental */
  16. +# define TCPOPT_TIMESTAMP 8
  17. +# define TCPOLEN_TIMESTAMP 10
  18. +# define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
  19. +
  20. +# define TCPOPT_TSTAMP_HDR \
  21. + (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
  22. +#endif
  23. +
  24. #include "traceroute.h"
  25. @@ -33,11 +51,11 @@ static unsigned int dest_port = 0;
  26. static int raw_sk = -1;
  27. static int last_ttl = 0;
  28. -static u_int8_t buf[1024]; /* enough, enough... */
  29. +static uint8_t buf[1024]; /* enough, enough... */
  30. static size_t csum_len = 0;
  31. static struct tcphdr *th = NULL;
  32. -#define TH_FLAGS(TH) (((u_int8_t *) (TH))[13])
  33. +#define TH_FLAGS(TH) (((uint8_t *) (TH))[13])
  34. #define TH_FIN 0x01
  35. #define TH_SYN 0x02
  36. #define TH_RST 0x04
  37. @@ -164,7 +182,7 @@ static CLIF_option tcp_options[] = {
  38. static int check_sysctl (const char *name) {
  39. int fd, res;
  40. char buf[sizeof (SYSCTL_PREFIX) + strlen (name) + 1];
  41. - u_int8_t ch;
  42. + uint8_t ch;
  43. strcpy (buf, SYSCTL_PREFIX);
  44. strcat (buf, name);
  45. @@ -191,8 +209,8 @@ static int tcp_init (const sockaddr_any
  46. sockaddr_any src;
  47. int mtu;
  48. socklen_t len;
  49. - u_int8_t *ptr;
  50. - u_int16_t *lenp;
  51. + uint8_t *ptr;
  52. + uint16_t *lenp;
  53. dest_addr = *dest;
  54. @@ -286,10 +304,10 @@ static int tcp_init (const sockaddr_any
  55. ptr += len;
  56. }
  57. - lenp = (u_int16_t *) ptr;
  58. - ptr += sizeof (u_int16_t);
  59. - *((u_int16_t *) ptr) = htons ((u_int16_t) IPPROTO_TCP);
  60. - ptr += sizeof (u_int16_t);
  61. + lenp = (uint16_t *) ptr;
  62. + ptr += sizeof (uint16_t);
  63. + *((uint16_t *) ptr) = htons ((uint16_t) IPPROTO_TCP);
  64. + ptr += sizeof (uint16_t);
  65. /* Construct TCP header */
  66. @@ -309,13 +327,13 @@ static int tcp_init (const sockaddr_any
  67. /* Build TCP options */
  68. - ptr = (u_int8_t *) (th + 1);
  69. + ptr = (uint8_t *) (th + 1);
  70. if (flags & TH_SYN) {
  71. *ptr++ = TCPOPT_MAXSEG; /* 2 */
  72. *ptr++ = TCPOLEN_MAXSEG; /* 4 */
  73. - *((u_int16_t *) ptr) = htons (mss ? mss : mtu);
  74. - ptr += sizeof (u_int16_t);
  75. + *((uint16_t *) ptr) = htons (mss ? mss : mtu);
  76. + ptr += sizeof (uint16_t);
  77. }
  78. if (flags & FL_TSTAMP) {
  79. @@ -330,10 +348,10 @@ static int tcp_init (const sockaddr_any
  80. *ptr++ = TCPOPT_TIMESTAMP; /* 8 */
  81. *ptr++ = TCPOLEN_TIMESTAMP; /* 10 */
  82. - *((u_int32_t *) ptr) = random_seq (); /* really! */
  83. - ptr += sizeof (u_int32_t);
  84. - *((u_int32_t *) ptr) = (flags & TH_ACK) ? random_seq () : 0;
  85. - ptr += sizeof (u_int32_t);
  86. + *((uint32_t *) ptr) = random_seq (); /* really! */
  87. + ptr += sizeof (uint32_t);
  88. + *((uint32_t *) ptr) = (flags & TH_ACK) ? random_seq () : 0;
  89. + ptr += sizeof (uint32_t);
  90. }
  91. else if (flags & FL_SACK) {
  92. *ptr++ = TCPOPT_NOP; /* 1 */
  93. @@ -355,7 +373,7 @@ static int tcp_init (const sockaddr_any
  94. if (csum_len > sizeof (buf))
  95. error ("impossible"); /* paranoia */
  96. - len = ptr - (u_int8_t *) th;
  97. + len = ptr - (uint8_t *) th;
  98. if (len & 0x03) error ("impossible"); /* as >>2 ... */
  99. *lenp = htons (len);
  100. @@ -436,7 +454,7 @@ static probe *tcp_check_reply (int sk, i
  101. char *buf, size_t len) {
  102. probe *pb;
  103. struct tcphdr *tcp = (struct tcphdr *) buf;
  104. - u_int16_t sport, dport;
  105. + uint16_t sport, dport;
  106. if (len < 8) return NULL; /* too short */