Tests that the Options slice is properly reset before parsing new data
(t *testing.T)
| 63 | |
| 64 | // Tests that the Options slice is properly reset before parsing new data |
| 65 | func 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 | |
| 94 | func serialize(ip *IPv4) ([]byte, error) { |
| 95 | buffer := gopacket.NewSerializeBuffer() |
nothing calls this directly
no test coverage detected
searching dependent graphs…