()
| 51 | } |
| 52 | |
| 53 | func NewIPDecoder() *IPDecoder { |
| 54 | var ( |
| 55 | ipv4 layers.IPv4 |
| 56 | ipv6 layers.IPv6 |
| 57 | ) |
| 58 | dlpv4 := gopacket.NewDecodingLayerParser(layers.LayerTypeIPv4) |
| 59 | dlpv4.SetDecodingLayerContainer(gopacket.DecodingLayerSparse(nil)) |
| 60 | dlpv4.AddDecodingLayer(&ipv4) |
| 61 | // Stop parsing when it encounter a layer that it doesn't have a parser |
| 62 | dlpv4.IgnoreUnsupported = true |
| 63 | |
| 64 | dlpv6 := gopacket.NewDecodingLayerParser(layers.LayerTypeIPv6) |
| 65 | dlpv6.SetDecodingLayerContainer(gopacket.DecodingLayerSparse(nil)) |
| 66 | dlpv6.AddDecodingLayer(&ipv6) |
| 67 | dlpv6.IgnoreUnsupported = true |
| 68 | |
| 69 | return &IPDecoder{ |
| 70 | ipv4: &ipv4, |
| 71 | ipv6: &ipv6, |
| 72 | layers: 1, |
| 73 | v4parser: dlpv4, |
| 74 | v6parser: dlpv6, |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func (pd *IPDecoder) Decode(packet RawPacket) (*IP, error) { |
| 79 | // Should decode to IP layer |
no outgoing calls