tcp.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #ifndef _NETINET_TCP_H
  2. #define _NETINET_TCP_H
  3. #include <features.h>
  4. #define TCP_NODELAY 1
  5. #define TCP_MAXSEG 2
  6. #define TCP_CORK 3
  7. #define TCP_KEEPIDLE 4
  8. #define TCP_KEEPINTVL 5
  9. #define TCP_KEEPCNT 6
  10. #define TCP_SYNCNT 7
  11. #define TCP_LINGER2 8
  12. #define TCP_DEFER_ACCEPT 9
  13. #define TCP_WINDOW_CLAMP 10
  14. #define TCP_INFO 11
  15. #define TCP_QUICKACK 12
  16. #define TCP_CONGESTION 13
  17. #define TCP_MD5SIG 14
  18. #define TCP_THIN_LINEAR_TIMEOUTS 16
  19. #define TCP_THIN_DUPACK 17
  20. #define TCP_USER_TIMEOUT 18
  21. #define TCP_REPAIR 19
  22. #define TCP_REPAIR_QUEUE 20
  23. #define TCP_QUEUE_SEQ 21
  24. #define TCP_REPAIR_OPTIONS 22
  25. #define TCP_FASTOPEN 23
  26. #define TCP_TIMESTAMP 24
  27. #define TCP_NOTSENT_LOWAT 25
  28. #define TCP_CC_INFO 26
  29. #define TCP_SAVE_SYN 27
  30. #define TCP_SAVED_SYN 28
  31. #define TCP_REPAIR_WINDOW 29
  32. #define TCP_ESTABLISHED 1
  33. #define TCP_SYN_SENT 2
  34. #define TCP_SYN_RECV 3
  35. #define TCP_FIN_WAIT1 4
  36. #define TCP_FIN_WAIT2 5
  37. #define TCP_TIME_WAIT 6
  38. #define TCP_CLOSE 7
  39. #define TCP_CLOSE_WAIT 8
  40. #define TCP_LAST_ACK 9
  41. #define TCP_LISTEN 10
  42. #define TCP_CLOSING 11
  43. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  44. #define TCPOPT_EOL 0
  45. #define TCPOPT_NOP 1
  46. #define TCPOPT_MAXSEG 2
  47. #define TCPOPT_WINDOW 3
  48. #define TCPOPT_SACK_PERMITTED 4
  49. #define TCPOPT_SACK 5
  50. #define TCPOPT_TIMESTAMP 8
  51. #define TCPOLEN_SACK_PERMITTED 2
  52. #define TCPOLEN_WINDOW 3
  53. #define TCPOLEN_MAXSEG 4
  54. #define TCPOLEN_TIMESTAMP 10
  55. #define SOL_TCP 6
  56. #include <sys/types.h>
  57. #include <sys/socket.h>
  58. #include <stdint.h>
  59. #include <endian.h>
  60. typedef uint32_t tcp_seq;
  61. #define TH_FIN 0x01
  62. #define TH_SYN 0x02
  63. #define TH_RST 0x04
  64. #define TH_PUSH 0x08
  65. #define TH_ACK 0x10
  66. #define TH_URG 0x20
  67. struct tcphdr {
  68. #ifdef _GNU_SOURCE
  69. #ifdef __GNUC__
  70. __extension__
  71. #endif
  72. union { struct {
  73. uint16_t source;
  74. uint16_t dest;
  75. uint32_t seq;
  76. uint32_t ack_seq;
  77. #if __BYTE_ORDER == __LITTLE_ENDIAN
  78. uint16_t res1:4;
  79. uint16_t doff:4;
  80. uint16_t fin:1;
  81. uint16_t syn:1;
  82. uint16_t rst:1;
  83. uint16_t psh:1;
  84. uint16_t ack:1;
  85. uint16_t urg:1;
  86. uint16_t res2:2;
  87. #else
  88. uint16_t doff:4;
  89. uint16_t res1:4;
  90. uint16_t res2:2;
  91. uint16_t urg:1;
  92. uint16_t ack:1;
  93. uint16_t psh:1;
  94. uint16_t rst:1;
  95. uint16_t syn:1;
  96. uint16_t fin:1;
  97. #endif
  98. uint16_t window;
  99. uint16_t check;
  100. uint16_t urg_ptr;
  101. }; struct {
  102. #endif
  103. uint16_t th_sport;
  104. uint16_t th_dport;
  105. uint32_t th_seq;
  106. uint32_t th_ack;
  107. #if __BYTE_ORDER == __LITTLE_ENDIAN
  108. uint8_t th_x2:4;
  109. uint8_t th_off:4;
  110. #else
  111. uint8_t th_off:4;
  112. uint8_t th_x2:4;
  113. #endif
  114. uint8_t th_flags;
  115. uint16_t th_win;
  116. uint16_t th_sum;
  117. uint16_t th_urp;
  118. #ifdef _GNU_SOURCE
  119. }; };
  120. #endif
  121. };
  122. #endif
  123. #ifdef _GNU_SOURCE
  124. #define TCPI_OPT_TIMESTAMPS 1
  125. #define TCPI_OPT_SACK 2
  126. #define TCPI_OPT_WSCALE 4
  127. #define TCPI_OPT_ECN 8
  128. #define TCP_CA_Open 0
  129. #define TCP_CA_Disorder 1
  130. #define TCP_CA_CWR 2
  131. #define TCP_CA_Recovery 3
  132. #define TCP_CA_Loss 4
  133. struct tcp_info {
  134. uint8_t tcpi_state;
  135. uint8_t tcpi_ca_state;
  136. uint8_t tcpi_retransmits;
  137. uint8_t tcpi_probes;
  138. uint8_t tcpi_backoff;
  139. uint8_t tcpi_options;
  140. uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  141. uint8_t tcpi_delivery_rate_app_limited : 1;
  142. uint32_t tcpi_rto;
  143. uint32_t tcpi_ato;
  144. uint32_t tcpi_snd_mss;
  145. uint32_t tcpi_rcv_mss;
  146. uint32_t tcpi_unacked;
  147. uint32_t tcpi_sacked;
  148. uint32_t tcpi_lost;
  149. uint32_t tcpi_retrans;
  150. uint32_t tcpi_fackets;
  151. uint32_t tcpi_last_data_sent;
  152. uint32_t tcpi_last_ack_sent;
  153. uint32_t tcpi_last_data_recv;
  154. uint32_t tcpi_last_ack_recv;
  155. uint32_t tcpi_pmtu;
  156. uint32_t tcpi_rcv_ssthresh;
  157. uint32_t tcpi_rtt;
  158. uint32_t tcpi_rttvar;
  159. uint32_t tcpi_snd_ssthresh;
  160. uint32_t tcpi_snd_cwnd;
  161. uint32_t tcpi_advmss;
  162. uint32_t tcpi_reordering;
  163. uint32_t tcpi_rcv_rtt;
  164. uint32_t tcpi_rcv_space;
  165. uint32_t tcpi_total_retrans;
  166. uint64_t tcpi_pacing_rate;
  167. uint64_t tcpi_max_pacing_rate;
  168. uint64_t tcpi_bytes_acked;
  169. uint64_t tcpi_bytes_received;
  170. uint32_t tcpi_segs_out;
  171. uint32_t tcpi_segs_in;
  172. uint32_t tcpi_notsent_bytes;
  173. uint32_t tcpi_min_rtt;
  174. uint32_t tcpi_data_segs_in;
  175. uint32_t tcpi_data_segs_out;
  176. uint64_t tcpi_delivery_rate;
  177. };
  178. #define TCP_MD5SIG_MAXKEYLEN 80
  179. struct tcp_md5sig {
  180. struct sockaddr_storage tcpm_addr;
  181. uint16_t __tcpm_pad1;
  182. uint16_t tcpm_keylen;
  183. uint32_t __tcpm_pad2;
  184. uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  185. };
  186. struct tcp_repair_window {
  187. uint32_t snd_wl1;
  188. uint32_t snd_wnd;
  189. uint32_t max_window;
  190. uint32_t rcv_wnd;
  191. uint32_t rcv_wup;
  192. };
  193. #endif
  194. #endif