func decodeTCP(data []byte, p gopacket.PacketBuilder) error { tcp := &TCP{} err := tcp.DecodeFromBytes(data, p) p.AddLayer(tcp) p.SetTransportLayer(tcp) if err != nil { return err } return p.NextDecoder(gopacket.LayerTypePayload) }
func decodeUDP(data []byte, p gopacket.PacketBuilder) error { udp := &UDP{} err := udp.DecodeFromBytes(data, p) p.AddLayer(udp) p.SetTransportLayer(udp) if err != nil { return err } return p.NextDecoder(udp.NextLayerType()) }
func decodeSCTP(data []byte, p gopacket.PacketBuilder) error { sctp := &SCTP{} err := sctp.DecodeFromBytes(data, p) p.AddLayer(sctp) p.SetTransportLayer(sctp) if err != nil { return err } return p.NextDecoder(sctpChunkTypePrefixDecoder) }
func decodeUDPLite(data []byte, p gopacket.PacketBuilder) error { udp := &UDPLite{ SrcPort: UDPLitePort(binary.BigEndian.Uint16(data[0:2])), sPort: data[0:2], DstPort: UDPLitePort(binary.BigEndian.Uint16(data[2:4])), dPort: data[2:4], ChecksumCoverage: binary.BigEndian.Uint16(data[4:6]), Checksum: binary.BigEndian.Uint16(data[6:8]), BaseLayer: BaseLayer{data[:8], data[8:]}, } p.AddLayer(udp) p.SetTransportLayer(udp) return p.NextDecoder(gopacket.LayerTypePayload) }
func decodeSCTP(data []byte, p gopacket.PacketBuilder) error { sctp := &SCTP{ SrcPort: SCTPPort(binary.BigEndian.Uint16(data[:2])), sPort: data[:2], DstPort: SCTPPort(binary.BigEndian.Uint16(data[2:4])), dPort: data[2:4], VerificationTag: binary.BigEndian.Uint32(data[4:8]), Checksum: binary.BigEndian.Uint32(data[8:12]), BaseLayer: BaseLayer{data[:12], data[12:]}, } p.AddLayer(sctp) p.SetTransportLayer(sctp) return p.NextDecoder(sctpChunkTypePrefixDecoder) }
func decodeRUDP(data []byte, p gopacket.PacketBuilder) error { r := &RUDP{ SYN: data[0]&0x80 != 0, ACK: data[0]&0x40 != 0, EACK: data[0]&0x20 != 0, RST: data[0]&0x10 != 0, NUL: data[0]&0x08 != 0, Version: data[0] & 0x3, HeaderLength: data[1], SrcPort: RUDPPort(data[2]), DstPort: RUDPPort(data[3]), DataLength: binary.BigEndian.Uint16(data[4:6]), Seq: binary.BigEndian.Uint32(data[6:10]), Ack: binary.BigEndian.Uint32(data[10:14]), Checksum: binary.BigEndian.Uint32(data[14:18]), } if r.HeaderLength < 9 { return fmt.Errorf("RUDP packet with too-short header length %d", r.HeaderLength) } hlen := int(r.HeaderLength) * 2 r.Contents = data[:hlen] r.Payload = data[hlen : hlen+int(r.DataLength)] r.VariableHeaderArea = data[18:hlen] headerData := r.VariableHeaderArea switch { case r.SYN: if len(headerData) != 6 { return fmt.Errorf("RUDP packet invalid SYN header length: %d", len(headerData)) } r.RUDPHeaderSYN = &RUDPHeaderSYN{ MaxOutstandingSegments: binary.BigEndian.Uint16(headerData[:2]), MaxSegmentSize: binary.BigEndian.Uint16(headerData[2:4]), OptionFlags: binary.BigEndian.Uint16(headerData[4:6]), } case r.EACK: if len(headerData)%4 != 0 { return fmt.Errorf("RUDP packet invalid EACK header length: %d", len(headerData)) } r.RUDPHeaderEACK = &RUDPHeaderEACK{make([]uint32, len(headerData)/4)} for i := 0; i < len(headerData); i += 4 { r.SeqsReceivedOK[i/4] = binary.BigEndian.Uint32(headerData[i : i+4]) } } p.AddLayer(r) p.SetTransportLayer(r) return p.NextDecoder(gopacket.LayerTypePayload) }