Checks that when a serialized version of p is decoded, p and the serialized version of p are the same. Does not work for packets where the order of options can change, like icmpv6 router advertisements, dhcpv6, etc.
(p gopacket.Packet, t *testing.T)
| 43 | // Checks that when a serialized version of p is decoded, p and the serialized version of p are the same. |
| 44 | // Does not work for packets where the order of options can change, like icmpv6 router advertisements, dhcpv6, etc. |
| 45 | func checkSerialization(p gopacket.Packet, t *testing.T) { |
| 46 | buf := gopacket.NewSerializeBuffer() |
| 47 | opts := gopacket.SerializeOptions{ |
| 48 | ComputeChecksums: false, |
| 49 | FixLengths: false, |
| 50 | } |
| 51 | if err := gopacket.SerializePacket(buf, opts, p); err != nil { |
| 52 | t.Error("Failed to encode packet:", err) |
| 53 | } |
| 54 | |
| 55 | p2 := gopacket.NewPacket(buf.Bytes(), LinkTypeEthernet, gopacket.Default) |
| 56 | if p2.ErrorLayer() != nil { |
| 57 | t.Error("Failed to decode the re-encoded packet:", p2.ErrorLayer().Error()) |
| 58 | } |
| 59 | |
| 60 | if p2.Dump() != p.Dump() { |
| 61 | t.Errorf("The decoded and the re-encoded packet are different!\nDecoded:\n%s\n Re-Encoded:\n%s", p.Dump(), p2.Dump()) |
| 62 | } |
| 63 | } |
no test coverage detected
searching dependent graphs…