tcp.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_ESTABLISHED 1
  29. #define TCP_SYN_SENT 2
  30. #define TCP_SYN_RECV 3
  31. #define TCP_FIN_WAIT1 4
  32. #define TCP_FIN_WAIT2 5
  33. #define TCP_TIME_WAIT 6
  34. #define TCP_CLOSE 7
  35. #define TCP_CLOSE_WAIT 8
  36. #define TCP_LAST_ACK 9
  37. #define TCP_LISTEN 10
  38. #define TCP_CLOSING 11
  39. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  40. #define SOL_TCP 6
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #endif
  44. #ifdef _GNU_SOURCE
  45. #include <endian.h>
  46. struct tcphdr
  47. {
  48. u_int16_t source;
  49. u_int16_t dest;
  50. u_int32_t seq;
  51. u_int32_t ack_seq;
  52. #if __BYTE_ORDER == __LITTLE_ENDIAN
  53. u_int16_t res1:4;
  54. u_int16_t doff:4;
  55. u_int16_t fin:1;
  56. u_int16_t syn:1;
  57. u_int16_t rst:1;
  58. u_int16_t psh:1;
  59. u_int16_t ack:1;
  60. u_int16_t urg:1;
  61. u_int16_t res2:2;
  62. #else
  63. u_int16_t doff:4;
  64. u_int16_t res1:4;
  65. u_int16_t res2:2;
  66. u_int16_t urg:1;
  67. u_int16_t ack:1;
  68. u_int16_t psh:1;
  69. u_int16_t rst:1;
  70. u_int16_t syn:1;
  71. u_int16_t fin:1;
  72. #endif
  73. u_int16_t window;
  74. u_int16_t check;
  75. u_int16_t urg_ptr;
  76. };
  77. #define TCPI_OPT_TIMESTAMPS 1
  78. #define TCPI_OPT_SACK 2
  79. #define TCPI_OPT_WSCALE 4
  80. #define TCPI_OPT_ECN 8
  81. #define TCP_CA_Open 0
  82. #define TCP_CA_Disorder 1
  83. #define TCP_CA_CWR 2
  84. #define TCP_CA_Recovery 3
  85. #define TCP_CA_Loss 4
  86. struct tcp_info
  87. {
  88. u_int8_t tcpi_state;
  89. u_int8_t tcpi_ca_state;
  90. u_int8_t tcpi_retransmits;
  91. u_int8_t tcpi_probes;
  92. u_int8_t tcpi_backoff;
  93. u_int8_t tcpi_options;
  94. u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  95. u_int32_t tcpi_rto;
  96. u_int32_t tcpi_ato;
  97. u_int32_t tcpi_snd_mss;
  98. u_int32_t tcpi_rcv_mss;
  99. u_int32_t tcpi_unacked;
  100. u_int32_t tcpi_sacked;
  101. u_int32_t tcpi_lost;
  102. u_int32_t tcpi_retrans;
  103. u_int32_t tcpi_fackets;
  104. u_int32_t tcpi_last_data_sent;
  105. u_int32_t tcpi_last_ack_sent;
  106. u_int32_t tcpi_last_data_recv;
  107. u_int32_t tcpi_last_ack_recv;
  108. u_int32_t tcpi_pmtu;
  109. u_int32_t tcpi_rcv_ssthresh;
  110. u_int32_t tcpi_rtt;
  111. u_int32_t tcpi_rttvar;
  112. u_int32_t tcpi_snd_ssthresh;
  113. u_int32_t tcpi_snd_cwnd;
  114. u_int32_t tcpi_advmss;
  115. u_int32_t tcpi_reordering;
  116. u_int32_t tcpi_rcv_rtt;
  117. u_int32_t tcpi_rcv_space;
  118. u_int32_t tcpi_total_retrans;
  119. };
  120. #define TCP_MD5SIG_MAXKEYLEN 80
  121. struct tcp_md5sig
  122. {
  123. struct sockaddr_storage tcpm_addr;
  124. u_int16_t __tcpm_pad1;
  125. u_int16_t tcpm_keylen;
  126. u_int32_t __tcpm_pad2;
  127. u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
  128. };
  129. #endif
  130. #endif