MCPcopy Create free account
hub / github.com/Edgio/vflow / TestDecodeIPv4Header

Function TestDecodeIPv4Header

packet/network_test.go:27–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25import "testing"
26
27func TestDecodeIPv4Header(t *testing.T) {
28 p := NewPacket()
29
30 p.data = []byte{
31 0x45, 0x0, 0x0, 0x4b, 0x8,
32 0xf8, 0x0, 0x0, 0x3e, 0x11,
33 0x82, 0x91, 0xc0, 0xe5, 0xd8,
34 0x8f, 0xc0, 0xe5, 0x96, 0xbe,
35 0x64, 0x9b, 0x0, 0x35, 0x0,
36 }
37 err := p.decodeIPv4Header()
38 if err != nil {
39 t.Error("unexpected error", err)
40 }
41
42 ipv4 := p.L3.(IPv4Header)
43
44 if ipv4.Version != 4 {
45 t.Error("unexpected version, got", ipv4.Version)
46 }
47
48 if ipv4.TOS != 0 {
49 t.Error("unexpected TOS, got", ipv4.TOS)
50 }
51 if ipv4.TotalLen != 75 {
52 t.Error("unexpected TotalLen, got", ipv4.TotalLen)
53 }
54 if ipv4.Flags != 0 {
55 t.Error("unexpected Flags, got", ipv4.Flags)
56 }
57
58 if ipv4.FragOff != 0 {
59 t.Error("unexpected FragOff", ipv4.FragOff)
60 }
61
62 if ipv4.TTL != 62 {
63 t.Error("unexpected TTL, got", ipv4.TTL)
64 }
65
66 if ipv4.Protocol != 17 {
67 t.Error("unexpected protocol, got", ipv4.Protocol)
68 }
69
70 if ipv4.Checksum != 33425 {
71 t.Error("unexpected checksum, got", ipv4.Checksum)
72 }
73 if ipv4.Src != "192.229.216.143" {
74 t.Error("unexpected src addr, got", ipv4.Src)
75 }
76
77 if ipv4.Dst != "192.229.150.190" {
78 t.Error("unexpected dst addr, got", ipv4.Dst)
79 }
80}

Callers

nothing calls this directly

Calls 2

decodeIPv4HeaderMethod · 0.95
NewPacketFunction · 0.85

Tested by

no test coverage detected