MCPcopy
hub / github.com/google/gopacket / TestIPOptResetDuringDecoding

Function TestIPOptResetDuringDecoding

layers/ip4_test.go:65–92  ·  view source on GitHub ↗

Tests that the Options slice is properly reset before parsing new data

(t *testing.T)

Source from the content-addressed store, hash-verified

63
64// Tests that the Options slice is properly reset before parsing new data
65func TestIPOptResetDuringDecoding(t *testing.T) {
66 ip := &IPv4{
67 Options: []IPv4Option{{OptionType: 42, OptionLength: 4, OptionData: make([]byte, 2)}},
68 }
69
70 ipWithoutOptions := &IPv4{
71 SrcIP: net.IPv4(192, 168, 1, 1),
72 DstIP: net.IPv4(192, 168, 1, 1),
73 Protocol: IPProtocolTCP,
74 }
75
76 ipBytes, err := serialize(ipWithoutOptions)
77
78 if err != nil {
79 t.Fatalf("Failed to serialize ip layer: %v", err)
80 }
81
82 err = ip.DecodeFromBytes(ipBytes, gopacket.NilDecodeFeedback)
83
84 if err != nil {
85 t.Fatalf("Failed to deserialize ip layer: %v", err)
86 }
87
88 if len(ip.Options) > 0 {
89 t.Fatalf("Options slice has stale data from previous packet")
90 }
91
92}
93
94func serialize(ip *IPv4) ([]byte, error) {
95 buffer := gopacket.NewSerializeBuffer()

Callers

nothing calls this directly

Calls 2

DecodeFromBytesMethod · 0.95
serializeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…