-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp_option.go
131 lines (110 loc) · 2.18 KB
/
tcp_option.go
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
119
120
121
122
123
124
125
126
127
128
129
130
131
package packemon
import "bytes"
type Mss struct {
Kind uint8
Length uint8
Value uint16
}
type SackPermitted struct {
Kind uint8
Length uint8
}
type Timestamps struct {
Kind uint8
Length uint8
Value uint32
EchoReply uint32
}
type NoOperation struct {
Kind uint8
}
type WindowScale struct {
Kind uint8
Length uint8
ShiftCount uint8
}
// synパケットの中を覗いて下
func Options() []byte {
buf := &bytes.Buffer{}
m := &Mss{
Kind: 0x02,
Length: 0x04,
Value: 0x05b4, // 1460
}
buf.WriteByte(m.Kind)
buf.WriteByte(m.Length)
WriteUint16(buf, m.Value)
s := &SackPermitted{
Kind: 0x04,
Length: 0x02,
}
buf.WriteByte(s.Kind)
buf.WriteByte(s.Length)
t := &Timestamps{
Kind: 0x08,
Length: 0x0a,
Value: 0xd4091f09,
EchoReply: 0x00000000,
}
buf.WriteByte(t.Kind)
buf.WriteByte(t.Length)
WriteUint32(buf, t.Value)
WriteUint32(buf, t.EchoReply)
n := &NoOperation{
Kind: 0x01,
}
buf.WriteByte(n.Kind)
w := &WindowScale{
Kind: 0x03,
Length: 0x03,
ShiftCount: 0x07,
}
buf.WriteByte(w.Kind)
buf.WriteByte(w.Length)
buf.WriteByte(w.ShiftCount)
return buf.Bytes()
}
// synパケットの中を覗いて下
func OptionsOfAck() []byte {
buf := &bytes.Buffer{}
n := &NoOperation{
Kind: 0x01,
}
buf.WriteByte(n.Kind)
buf.WriteByte(n.Kind)
t := &Timestamps{
Kind: 0x08,
Length: 0x0a,
Value: 0xdbe1c2c4,
EchoReply: 0x796a7651,
}
buf.WriteByte(t.Kind)
buf.WriteByte(t.Length)
WriteUint32(buf, t.Value)
WriteUint32(buf, t.EchoReply)
return buf.Bytes()
}
// http getリクエスト時のtcp optionを覗いて
// https://atmarkit.itmedia.co.jp/ait/articles/0401/29/news080_2.html
// 「オプション」フィールド:32bit単位で可変長
func OptionsOfhttp() []byte {
buf := &bytes.Buffer{}
n := &NoOperation{
Kind: 0x01,
}
buf.WriteByte(n.Kind)
buf.WriteByte(n.Kind)
t := &Timestamps{
Kind: 0x08,
Length: 0x0a,
Value: 0x5d1fbc0b,
EchoReply: 0x7a7519d3,
}
buf.WriteByte(t.Kind)
buf.WriteByte(t.Length)
WriteUint32(buf, t.Value)
WriteUint32(buf, t.EchoReply)
// padding := []byte{0x00, 0x00, 0x00}
// buf.Write(padding)
return buf.Bytes()
}