-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathtransport_test.go
95 lines (80 loc) · 2.22 KB
/
transport_test.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
//: ----------------------------------------------------------------------------
//: Copyright (C) 2017 Verizon. All Rights Reserved.
//: All Rights Reserved
//:
//: file: transport_test.go
//: details: TODO
//: author: Mehrdad Arshad Rad
//: date: 02/01/2017
//:
//: Licensed under the Apache License, Version 2.0 (the "License");
//: you may not use this file except in compliance with the License.
//: You may obtain a copy of the License at
//:
//: http://www.apache.org/licenses/LICENSE-2.0
//:
//: Unless required by applicable law or agreed to in writing, software
//: distributed under the License is distributed on an "AS IS" BASIS,
//: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//: See the License for the specific language governing permissions and
//: limitations under the License.
//: ----------------------------------------------------------------------------
package packet
import "testing"
func TestDecoderUDP(t *testing.T) {
b := []byte{
0xa3, 0x6c, 0x0, 0x35, 0x0,
0x3d, 0xc8, 0xdc, 0x81, 0x9f,
}
udp, err := decodeUDP(b)
if err != nil {
t.Error("unexpected error", err)
}
if udp.SrcPort != 41836 {
t.Error("expected src port:41836, got", udp.SrcPort)
}
if udp.DstPort != 53 {
t.Error("expected dst port:53, got", udp.DstPort)
}
}
func TestDecodeTCP(t *testing.T) {
b := []byte{
0xa5, 0x8e, 0x20, 0xfb, 0x54,
0x1, 0x4f, 0x1c, 0x52, 0x7f,
0x0, 0xf9, 0x50, 0x10, 0x1,
0x2a, 0xbb, 0xde, 0x0, 0x0,
}
tcp, err := decodeTCP(b)
if err != nil {
t.Error("unexpected error", err)
}
if tcp.SrcPort != 42382 {
t.Error("expected src port:4382, got", tcp.SrcPort)
}
if tcp.DstPort != 8443 {
t.Error("expected dst port:8443, got", tcp.DstPort)
}
if tcp.Flags != 16 {
t.Error("expected flags:16, got", tcp.Flags)
}
}
func TestDecodeTCP2(t *testing.T) {
b := []byte{
0xa5, 0x8e, 0x20, 0xfb, 0x54,
0x1, 0x4f, 0x1c, 0x52, 0x7f,
0x0, 0xf9, 0x51, 0x10, 0x1,
0x2a, 0xbb, 0xde, 0x0, 0x0,
}
tcp, err := decodeTCP(b)
if err != nil {
t.Error("unexpected error", err)
}
// NS flag
if tcp.Flags != 272 {
t.Error("expected flags:272, got", tcp.Flags)
}
// check dataoffset
if tcp.DataOffset != 5 {
t.Error("expected dataoffset:5, got", tcp.DataOffset)
}
}