23 struct tcp_header* tcp =
24 (
struct tcp_header*) ((
uint8_t*) ip + ip_hdr_len);
26 uint8_t tcp_hdr_len = ((tcp->offset >> 4) & 0x0F) * 4;
29 if (tcp_hdr_len < 20 || total_len < ip_hdr_len + tcp_hdr_len)
33 auto flags = tcp->flags;
49 uint8_t len_ = ((tcp->offset >> 4) & 0x0F) * 4;
50 uint16_t data_len = total_len - ip_hdr_len - len_;
53 if (data_len > 0 && tcp->flags &
FLAG_PSH) {
57 &&
strncmp((
char*) payload,
"GET ", 4) == 0) {
63 char* http_resp =
"HTTP/1.1 200 OK\r\n"
64 "Content-Length: 13\r\n"
65 "Connection: close\r\n"
89 auto reply_len =
sizeof(
struct tcp_header) + opt_len;
90 struct tcp_header* tcp_reply =
99 memcopy(opt_ptr, opt_buf, opt_len);
100 tcp_reply->offset = (
uint8_t) ((5 + opt_len / 4) << 4);
102 tcp_reply->source_port = tcp->destination_port;
103 tcp_reply->destination_port = tcp->source_port;
107 tcp_reply->flags =
flags;
108 tcp_reply->window =
vxHtons(65535);
110 tcp_reply->checksum = 0;
121 pseudo.src_ip = ip->
dst_ip;
122 pseudo.dst_ip = ip->
src_ip;
131 sum = (sum & 0xFFFF) + (sum >> 16);
133 tcp_reply->checksum = (
uint16_t) (~sum);
147 uint8_t tcp_hdr_len_in = ((tcp->offset >> 4) & 0x0F) * 4;
148 uint16_t incoming_data_len = ip_total_len - ip_hdr_len - tcp_hdr_len_in;
157 struct tcp_header* tcp_reply = (
struct tcp_header*)
netbuff_push(
158 nb,
sizeof(
struct tcp_header));
165 tcp_reply->offset = (5 << 4);
167 tcp_reply->source_port = tcp->destination_port;
168 tcp_reply->destination_port = tcp->source_port;
171 tcp_reply->sequence = tcp->acknowledgment;
175 tcp_reply->acknowledgment =
vxHtonl(seq_in + incoming_data_len);
180 tcp_reply->window =
vxHtons(65535);
181 tcp_reply->checksum = 0;
192 pseudo.src_ip = ip->
dst_ip;
193 pseudo.dst_ip = ip->
src_ip;
201 sizeof(
struct tcp_header));
205 sum = (sum & 0xFFFF) + (sum >> 16);
207 tcp_reply->checksum = (
uint16_t) (~sum);
215 memset(out, 0,
sizeof(*out));
219 uint8_t hdr_len = ((tcp->offset >> 4) & 0x0F) * 4;
278 - sizeof(struct tcp_header);
280 (client_opts->
mss < our_mss) ? client_opts->
mss : our_mss;
283 *p++ = (mss >> 8) & 0xFF;
void ipv4_send(netdev_t *dev, struct netbuff *nb, uint32_t dst_ip, uint8_t protocol, uint8_t mac_dest[6])
void free_netbuff(struct netbuff *netbuff)
void * netbuff_put(struct netbuff *nb, size_t len)
void * netbuff_push(struct netbuff *nb, size_t len)
struct netbuff * create_netbuff()
uint32_t checksum16_raw(const uint16_t *data, size_t length)
static uint16_t vxNtohs(uint16_t netshort)
static uint32_t vxNtohl(uint32_t netlong)
static uint32_t vxHtonl(uint32_t value)
static uint16_t vxHtons(uint16_t value)
int strncmp(const char *s1, const char *s2, size_t n)
void memset(void *ptr, int value, size_t num)
void memcopy(void *dest, void *src, size_t size)
void handle_tcp(netdev_t *dev, struct ipv4_header *ip, uint8_t mac_dst[6])
void send_command(netdev_t *dev, struct ipv4_header *ip, struct tcp_header *tcp, tcp_options_t *opt, uint8_t flags, uint8_t mac_dst[6])
void send_tcp_data(netdev_t *dev, struct ipv4_header *ip, struct tcp_header *tcp, uint8_t *data, size_t len, uint8_t mac_dst[6])
uint8_t build_synack_options(netdev_t *dev, uint8_t *buf, tcp_options_t *client_opts)
void parse_tcp_options(struct tcp_header *tcp, tcp_options_t *out)