本文整理匯總了Golang中github.com/google/gopacket.PacketBuilder.NextDecoder方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketBuilder.NextDecoder方法的具體用法?Golang PacketBuilder.NextDecoder怎麽用?Golang PacketBuilder.NextDecoder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/gopacket.PacketBuilder
的用法示例。
在下文中一共展示了PacketBuilder.NextDecoder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: decodeInGRELayer
func decodeInGRELayer(data []byte, p gopacket.PacketBuilder) error {
switch (data[0] >> 4) & 0xf {
case 4:
ip4 := &layers.IPv4{}
err := ip4.DecodeFromBytes(data, p)
p.AddLayer(ip4)
p.SetNetworkLayer(ip4)
if err != nil {
return err
}
return p.NextDecoder(ip4.NextLayerType())
case 6:
ip6 := &layers.IPv6{}
err := ip6.DecodeFromBytes(data, p)
p.AddLayer(ip6)
p.SetNetworkLayer(ip6)
if err != nil {
return err
}
return p.NextDecoder(ip6.NextLayerType())
}
packet := gopacket.NewPacket(data, layers.LayerTypeARP, gopacket.Lazy)
layer := packet.Layer(layers.LayerTypeARP)
p.AddLayer(layer)
return nil
}
示例2: 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)
}
示例3: 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))
}
示例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: 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())
}
示例10: 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())
}
示例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())
}