本文整理匯總了Golang中github.com/google/gopacket.PacketBuilder類的典型用法代碼示例。如果您正苦於以下問題:Golang PacketBuilder類的具體用法?Golang PacketBuilder怎麽用?Golang PacketBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PacketBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: decodeSCTPEmptyLayer
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPEmptyLayer{
SCTPChunk: decodeSCTPChunk(data),
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例3: 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())
}
示例4: 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())
}
示例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: 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())
}
示例7: 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)
}
示例8: 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))
}
示例9: 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)
}
示例10: 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)
}
示例11: 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())
}
示例12: 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)
}
示例13: decodeIPSecESP
func decodeIPSecESP(data []byte, p gopacket.PacketBuilder) error {
i := &IPSecESP{
BaseLayer: BaseLayer{data, nil},
SPI: binary.BigEndian.Uint32(data[:4]),
Seq: binary.BigEndian.Uint32(data[4:8]),
Encrypted: data[8:],
}
p.AddLayer(i)
return nil
}
示例14: decodeDNS
// decodeDNS decodes the byte slice into a DNS type. It also
// setups the application Layer in PacketBuilder.
func decodeDNS(data []byte, p gopacket.PacketBuilder) error {
d := &DNS{}
err := d.DecodeFromBytes(data, p)
if err != nil {
return err
}
p.AddLayer(d)
p.SetApplicationLayer(d)
return nil
}
示例15: decodeSCTPEmptyLayer
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
chunk, err := decodeSCTPChunk(data)
if err != nil {
return err
}
sc := &SCTPEmptyLayer{
SCTPChunk: chunk,
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}