Takahiro Suzuki | 241c10e | 2020-12-17 20:17:57 +0900 | [diff] [blame^] | 1 | // Copyright 2012 Google, Inc. All rights reserved. |
| 2 | // Copyright 2009-2011 Andreas Krennmair. All rights reserved. |
| 3 | // |
| 4 | // Use of this source code is governed by a BSD-style license |
| 5 | // that can be found in the LICENSE file in the root of the source |
| 6 | // tree. |
| 7 | |
| 8 | package layers |
| 9 | |
| 10 | import ( |
| 11 | "encoding/binary" |
| 12 | "github.com/google/gopacket" |
| 13 | ) |
| 14 | |
| 15 | // UDPLite is the layer for UDP-Lite headers (rfc 3828). |
| 16 | type UDPLite struct { |
| 17 | BaseLayer |
| 18 | SrcPort, DstPort UDPLitePort |
| 19 | ChecksumCoverage uint16 |
| 20 | Checksum uint16 |
| 21 | sPort, dPort []byte |
| 22 | } |
| 23 | |
| 24 | // LayerType returns gopacket.LayerTypeUDPLite |
| 25 | func (u *UDPLite) LayerType() gopacket.LayerType { return LayerTypeUDPLite } |
| 26 | |
| 27 | func decodeUDPLite(data []byte, p gopacket.PacketBuilder) error { |
| 28 | udp := &UDPLite{ |
| 29 | SrcPort: UDPLitePort(binary.BigEndian.Uint16(data[0:2])), |
| 30 | sPort: data[0:2], |
| 31 | DstPort: UDPLitePort(binary.BigEndian.Uint16(data[2:4])), |
| 32 | dPort: data[2:4], |
| 33 | ChecksumCoverage: binary.BigEndian.Uint16(data[4:6]), |
| 34 | Checksum: binary.BigEndian.Uint16(data[6:8]), |
| 35 | BaseLayer: BaseLayer{data[:8], data[8:]}, |
| 36 | } |
| 37 | p.AddLayer(udp) |
| 38 | p.SetTransportLayer(udp) |
| 39 | return p.NextDecoder(gopacket.LayerTypePayload) |
| 40 | } |
| 41 | |
| 42 | func (u *UDPLite) TransportFlow() gopacket.Flow { |
| 43 | return gopacket.NewFlow(EndpointUDPLitePort, u.sPort, u.dPort) |
| 44 | } |