DecodeFromBytes decodes the given bytes into this layer.
(data []byte, df gopacket.DecodeFeedback)
| 27 | |
| 28 | // DecodeFromBytes decodes the given bytes into this layer. |
| 29 | func (l *Loopback) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { |
| 30 | if len(data) < 4 { |
| 31 | return errors.New("Loopback packet too small") |
| 32 | } |
| 33 | |
| 34 | // The protocol could be either big-endian or little-endian, we're |
| 35 | // not sure. But we're PRETTY sure that the value is less than |
| 36 | // 256, so we can check the first two bytes. |
| 37 | var prot uint32 |
| 38 | if data[0] == 0 && data[1] == 0 { |
| 39 | prot = binary.BigEndian.Uint32(data[:4]) |
| 40 | } else { |
| 41 | prot = binary.LittleEndian.Uint32(data[:4]) |
| 42 | } |
| 43 | if prot > 0xFF { |
| 44 | return fmt.Errorf("Invalid loopback protocol %q", data[:4]) |
| 45 | } |
| 46 | |
| 47 | l.Family = ProtocolFamily(prot) |
| 48 | l.BaseLayer = BaseLayer{data[:4], data[4:]} |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | // CanDecode returns the set of layer types that this DecodingLayer can decode. |
| 53 | func (l *Loopback) CanDecode() gopacket.LayerClass { |
no test coverage detected