forked from pandax381/microps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp.h
118 lines (100 loc) · 2.59 KB
/
tcp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef TCP_H
#define TCP_H
#include <stdint.h>
#include <sys/types.h>
#include "ip.h"
#include "ip6.h"
#define TCP_STATE_CLOSED 1
#define TCP_STATE_LISTEN 2
#define TCP_STATE_SYN_SENT 3
#define TCP_STATE_SYN_RECEIVED 4
#define TCP_STATE_ESTABLISHED 5
#define TCP_STATE_FIN_WAIT1 6
#define TCP_STATE_FIN_WAIT2 7
#define TCP_STATE_CLOSING 8
#define TCP_STATE_TIME_WAIT 9
#define TCP_STATE_CLOSE_WAIT 10
#define TCP_STATE_LAST_ACK 11
/* transition from tcp.c */
#define TCP_PCB_SIZE 16
#define TCP_FLG_FIN 0x01
#define TCP_FLG_SYN 0x02
#define TCP_FLG_RST 0x04
#define TCP_FLG_PSH 0x08
#define TCP_FLG_ACK 0x10
#define TCP_FLG_URG 0x20
#define TCP_FLG_IS(x, y) ((x & 0x3f) == (y))
#define TCP_FLG_ISSET(x, y) ((x & 0x3f) & (y) ? 1 : 0)
#define TCP_PCB_MODE_RFC793 1
#define TCP_PCB_MODE_SOCKET 2
#define TCP_PCB_STATE_FREE 0
#define TCP_PCB_STATE_CLOSED 1
#define TCP_PCB_STATE_LISTEN 2
#define TCP_PCB_STATE_SYN_SENT 3
#define TCP_PCB_STATE_SYN_RECEIVED 4
#define TCP_PCB_STATE_ESTABLISHED 5
#define TCP_PCB_STATE_FIN_WAIT1 6
#define TCP_PCB_STATE_FIN_WAIT2 7
#define TCP_PCB_STATE_CLOSING 8
#define TCP_PCB_STATE_TIME_WAIT 9
#define TCP_PCB_STATE_CLOSE_WAIT 10
#define TCP_PCB_STATE_LAST_ACK 11
#define TCP_DEFAULT_RTO 200000 /* micro seconds */
#define TCP_RETRANSMIT_DEADLINE 12 /* seconds */
#define TCP_TIMEWAIT_SEC 30 /* substitute for 2MSL */
#define TCP_SOURCE_PORT_MIN 49152
#define TCP_SOURCE_PORT_MAX 65535
struct tcp_segment_info {
uint32_t seq;
uint32_t ack;
uint16_t len;
uint16_t wnd;
uint16_t up;
};
struct tcp_hdr {
uint16_t src;
uint16_t dst;
uint32_t seq;
uint32_t ack;
uint8_t off;
uint8_t flg;
uint16_t wnd;
uint16_t sum;
uint16_t up;
};
struct tcp_queue_entry {
struct timeval first;
struct timeval last;
unsigned int rto; /* micro seconds */
uint32_t seq;
uint8_t flg;
size_t len;
};
/* tcp.c */
extern void
tcp_dump(const uint8_t *data, size_t len);
extern char *
tcp_flg_ntoa(uint8_t flg);
extern int
tcp_init(void);
extern int
tcp_open_rfc793(struct ip_endpoint *local, struct ip_endpoint *foreign, int active);
extern int
tcp_state(int id);
extern int
tcp_close(int id);
extern ssize_t
tcp_send(int id, uint8_t *data, size_t len);
extern ssize_t
tcp_receive(int id, uint8_t *buf, size_t size);
extern int
tcp_open(void);
extern int
tcp_bind(int id, struct ip_endpoint *local);
extern int
tcp_connect(int id, struct ip_endpoint *foreign);
extern int
tcp_listen(int id, int backlog);
extern int
tcp_accept(int id, struct ip_endpoint *foreign);
#endif