00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #ifndef NET_TCP_HEADER_H_
00039 #define NET_TCP_HEADER_H_
00040
00041 #include <sys/types.h>
00042
00044 #define TCP_HEADER_SIZE sizeof(tcp_header_t)
00045
00049 #define TCP_HEADER_LENGTH(header) (GET_TCP_HEADER_LENGTH(header) * 4U)
00050
00054 #define TCP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4U))
00055
00059 typedef struct tcp_header tcp_header_t;
00060
00064 typedef struct tcp_option tcp_option_t;
00065
00067 typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
00068
00070 struct tcp_header {
00071 uint16_t source_port;
00072 uint16_t destination_port;
00073 uint32_t sequence_number;
00074 uint32_t acknowledgement_number;
00075
00076 uint8_t hlr;
00077
00078 #define GET_TCP_HEADER_LENGTH(header) \
00079 (((header)->hlr & 0xf0) >> 4)
00080 #define SET_TCP_HEADER_LENGTH(header, length) \
00081 ((header)->hlr = \
00082 ((length & 0x0f) << 4) | ((header)->hlr & 0x0f))
00083
00084 #define GET_TCP_HEADER_RESERVED1(header) \
00085 ((header)->hlr & 0x0f)
00086 #define SET_TCP_HEADER_RESERVED1(header, reserved1) \
00087 ((header)->hlr = \
00088 (reserved1 & 0x0f) | ((header)->hlr & 0xf0))
00089
00090
00091 uint8_t ruaprsf;
00092
00093 #define GET_TCP_HEADER_RESERVED2(header) \
00094 (((header)->ruaprsf & 0xc0) >> 6)
00095 #define SET_TCP_HEADER_RESERVED2(header, reserved2) \
00096 ((header)->ruaprsf = \
00097 ((reserved2 & 0x03) << 6) | ((header)->ruaprsf & 0x3f))
00098
00099 #define GET_TCP_HEADER_URGENT(header) \
00100 (((header)->ruaprsf & 0x20) >> 5)
00101 #define SET_TCP_HEADER_URGENT(header, urgent) \
00102 ((header)->ruaprsf = \
00103 ((urgent & 0x01) << 5) | ((header)->ruaprsf & 0xdf))
00104
00105 #define GET_TCP_HEADER_ACKNOWLEDGE(header) \
00106 (((header)->ruaprsf & 0x10) >> 4)
00107 #define SET_TCP_HEADER_ACKNOWLEDGE(header, acknowledge) \
00108 ((header)->ruaprsf = \
00109 ((acknowledge & 0x01) << 4) | ((header)->ruaprsf & 0xef))
00110
00111 #define GET_TCP_HEADER_PUSH(header) \
00112 (((header)->ruaprsf & 0x08) >> 3)
00113 #define SET_TCP_HEADER_PUSH(header, push) \
00114 ((header)->ruaprsf = \
00115 ((push & 0x01) << 3) | ((header)->ruaprsf & 0xf7))
00116
00117 #define GET_TCP_HEADER_RESET(header) \
00118 (((header)->ruaprsf & 0x04) >> 2)
00119 #define SET_TCP_HEADER_RESET(header, reset) \
00120 ((header)->ruaprsf = \
00121 ((reset & 0x01) << 2) | ((header)->ruaprsf & 0xfb))
00122
00123 #define GET_TCP_HEADER_SYNCHRONIZE(header) \
00124 (((header)->ruaprsf & 0x02) >> 1)
00125 #define SET_TCP_HEADER_SYNCHRONIZE(header, synchronize) \
00126 ((header)->ruaprsf = \
00127 ((synchronize & 0x01) << 1) | ((header)->ruaprsf & 0xfd))
00128
00129 #define GET_TCP_HEADER_FINALIZE(header) \
00130 ((header)->ruaprsf & 0x01)
00131 #define SET_TCP_HEADER_FINALIZE(header, finalize) \
00132 ((header)->ruaprsf = \
00133 (finalize & 0x01) | ((header)->ruaprsf & 0xfe))
00134
00135 uint16_t window;
00136 uint16_t checksum;
00137 uint16_t urgent_pointer;
00138 } __attribute__ ((packed));
00139
00141 struct tcp_option {
00143 uint8_t type;
00145 uint8_t length;
00146 };
00147
00149 struct tcp_max_segment_size_option {
00154 tcp_option_t option;
00155
00157 uint16_t max_segment_size;
00158 } __attribute__ ((packed));
00159
00160 #endif
00161