本文整理匯總了Golang中github.com/google/gopacket.PacketBuilder.AddLayer方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketBuilder.AddLayer方法的具體用法?Golang PacketBuilder.AddLayer怎麽用?Golang PacketBuilder.AddLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/gopacket.PacketBuilder
的用法示例。
在下文中一共展示了PacketBuilder.AddLayer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: decodeLLC
func decodeLLC(data []byte, p gopacket.PacketBuilder) error {
l := &LLC{
DSAP: data[0] & 0xFE,
IG: data[0]&0x1 != 0,
SSAP: data[1] & 0xFE,
CR: data[1]&0x1 != 0,
Control: data[2],
}
/*
if l.Control&0x1 == 0 || l.Control&0x3 == 0x1 {
l.Control = l.Control<<8 | uint16(data[3])
l.Contents = data[:4]
l.Payload = data[4:]
} else {
l.Contents = data[:3]
l.Payload = data[3:]
}
*/
l.Contents = data[:3]
l.Payload = data[3:]
p.AddLayer(l)
if l.DSAP == 0xAA && l.SSAP == 0xAA {
return p.NextDecoder(LayerTypeSNAP)
} else if l.DSAP == 0x42 && l.SSAP == 0x42 && l.Control == 0x03 {
return p.NextDecoder(LayerTypeBPDU)
}
return p.NextDecoder(gopacket.DecodeUnknown)
}
示例2: decodeSCTPChunkTypeUnknown
func decodeSCTPChunkTypeUnknown(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPUnknownChunkType{SCTPChunk: decodeSCTPChunk(data)}
sc.bytes = data[:sc.ActualLength]
p.AddLayer(sc)
p.SetErrorLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例3: decodeVXLAN
func decodeVXLAN(data []byte, p gopacket.PacketBuilder) error {
vx := &VXLAN{}
// VNI is a 24bit number, Uint32 requires 32 bits
var buf [4]byte
copy(buf[1:], data[4:7])
// RFC 7348 https://tools.ietf.org/html/rfc7348
vx.ValidIDFlag = data[0]&0x08 > 0 // 'I' bit per RFC7348
vx.VNI = binary.BigEndian.Uint32(buf[:]) // VXLAN Network Identifier per RFC7348
// Group Based Policy https://tools.ietf.org/html/draft-smith-vxlan-group-policy-00
vx.GBPExtension = data[0]&0x80 > 0 // 'G' bit per the group policy draft
vx.GBPDontLearn = data[1]&0x40 > 0 // 'D' bit - the egress VTEP MUST NOT learn the source address of the encapsulated frame.
vx.GBPApplied = data[1]&0x80 > 0 // 'A' bit - indicates that the group policy has already been applied to this packet.
vx.GBPGroupPolicyID = binary.BigEndian.Uint16(data[2:4]) // Policy ID as per the group policy draft
// Layer information
const vxlanLength = 8
vx.Contents = data[:vxlanLength]
vx.Payload = data[vxlanLength:]
p.AddLayer(vx)
return p.NextDecoder(LinkTypeEthernet)
}
示例4: decodeSCTPEmptyLayer
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPEmptyLayer{
SCTPChunk: decodeSCTPChunk(data),
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例5: decodeSCTPShutdown
func decodeSCTPShutdown(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPShutdown{
SCTPChunk: decodeSCTPChunk(data),
CumulativeTSNAck: binary.BigEndian.Uint32(data[4:8]),
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例6: decodeSCTPCookieEcho
func decodeSCTPCookieEcho(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPCookieEcho{
SCTPChunk: decodeSCTPChunk(data),
}
sc.Cookie = data[4:sc.Length]
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例7: decodeMoldUDP64
func decodeMoldUDP64(data []byte, p gopacket.PacketBuilder) error {
m := &MoldUDP64{}
if err := m.DecodeFromBytes(data, p); err != nil {
return err
}
p.AddLayer(m)
return p.NextDecoder(m.NextLayerType())
}
示例8: decodeLoopback
func decodeLoopback(data []byte, p gopacket.PacketBuilder) error {
l := Loopback{}
if err := l.DecodeFromBytes(data, gopacket.NilDecodeFeedback); err != nil {
return err
}
p.AddLayer(&l)
return p.NextDecoder(l.Family)
}
示例9: decodeMach
func decodeMach(data []byte, p gopacket.PacketBuilder) (err error) {
panic("FIXME")
defer errs.PassE(&err)
m := &Mach{}
errs.CheckE(m.DecodeFromBytes(data, p))
p.AddLayer(m)
return p.NextDecoder(m.NextLayerType())
}
示例10: Decode
func (a TomMessageType) Decode(data []byte, p gopacket.PacketBuilder) error {
layer := TomMessageTypeMetadata[a].CreateLayer()
if err := layer.DecodeFromBytes(data, p); err != nil {
return err
}
p.AddLayer(layer)
return p.NextDecoder(layer.NextLayerType())
}
示例11: decodeLinuxSLL
func decodeLinuxSLL(data []byte, p gopacket.PacketBuilder) error {
sll := &LinuxSLL{}
if err := sll.DecodeFromBytes(data, p); err != nil {
return err
}
p.AddLayer(sll)
p.SetLinkLayer(sll)
return p.NextDecoder(sll.EthernetType)
}
示例12: decodeICMPv4
func decodeICMPv4(data []byte, p gopacket.PacketBuilder) error {
i := &ICMPv4{}
err := i.DecodeFromBytes(data, p)
if err != nil {
return err
}
p.AddLayer(i)
return p.NextDecoder(gopacket.LayerTypePayload)
}
示例13: decodeDHCPv4
func decodeDHCPv4(data []byte, p gopacket.PacketBuilder) error {
dhcp := &DHCPv4{}
err := dhcp.DecodeFromBytes(data, p)
if err != nil {
return err
}
p.AddLayer(dhcp)
return p.NextDecoder(gopacket.LayerTypePayload)
}
示例14: decodeIPv6HopByHop
func decodeIPv6HopByHop(data []byte, p gopacket.PacketBuilder) error {
i := &IPv6HopByHop{}
err := i.DecodeFromBytes(data, p)
p.AddLayer(i)
if err != nil {
return err
}
return p.NextDecoder(i.NextHeader)
}
示例15: decodeVxlan
func decodeVxlan(data []byte, p gopacket.PacketBuilder) error {
v := &VXLAN{BaseLayer: BaseLayer{Contents: data}}
err := v.DecodeFromBytes(data, p)
p.AddLayer(v)
if err != nil {
return err
}
return p.NextDecoder(v.NextLayerType())
}