本文整理汇总了Golang中gopacket.PacketBuilder.SetTransportLayer方法的典型用法代码示例。如果您正苦于以下问题:Golang PacketBuilder.SetTransportLayer方法的具体用法?Golang PacketBuilder.SetTransportLayer怎么用?Golang PacketBuilder.SetTransportLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gopacket.PacketBuilder
的用法示例。
在下文中一共展示了PacketBuilder.SetTransportLayer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: decodeUDP
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())
}
示例2: decodeTCP
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)
}
示例3: decodeSCTP
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)
}
示例4: decodeUDPLite
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)
}
示例5: decodeRUDP
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)
}