本文整理汇总了Golang中github.com/google/gopacket.DecodeFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeFunc函数的具体用法?Golang DecodeFunc怎么用?Golang DecodeFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeFunc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
layers.MPLSPayloadDecoder = gopacket.DecodeFunc(decodeMPLS)
layers.EthernetTypeMetadata[ethernetTypeDot1QSTag] = layers.EthernetTypeMetadata[layers.EthernetTypeDot1Q]
layers.EthernetTypeMetadata[ethernetTypeDot1QITag] = layers.EnumMetadata{
DecodeWith: gopacket.DecodeFunc(decodePBB),
Name: "PBB",
LayerType: LayerTypePBB,
}
layers.EthernetTypeMetadata[ethernetTypeLwapp] = layers.EnumMetadata{
DecodeWith: gopacket.DecodeFunc(decodeLwapp),
Name: "Lwapp",
LayerType: LayerTypeLwapp,
}
}
开发者ID:skyportsystems,项目名称:suppl,代码行数:14,代码来源:suppl.go
示例2: decodeSCTPEmptyLayer
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPEmptyLayer{
SCTPChunk: decodeSCTPChunk(data),
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:CNDonny,项目名称:scope,代码行数:7,代码来源:sctp.go
示例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))
}
开发者ID:CNDonny,项目名称:scope,代码行数:7,代码来源:sctp.go
示例4: 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))
}
开发者ID:CNDonny,项目名称:scope,代码行数:8,代码来源:sctp.go
示例5: 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))
}
开发者ID:CNDonny,项目名称:scope,代码行数:8,代码来源:sctp.go
示例6: 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))
}
开发者ID:cdshann,项目名称:minimega,代码行数:11,代码来源:sctp.go
示例7: decodeEthernetCTP
func decodeEthernetCTP(data []byte, p gopacket.PacketBuilder) error {
c := &EthernetCTP{
SkipCount: binary.LittleEndian.Uint16(data[:2]),
BaseLayer: BaseLayer{data[:2], data[2:]},
}
if c.SkipCount%2 != 0 {
return fmt.Errorf("EthernetCTP skip count is odd: %d", c.SkipCount)
}
p.AddLayer(c)
return p.NextDecoder(gopacket.DecodeFunc(decodeEthernetCTPFromFunctionType))
}
开发者ID:nplanel,项目名称:gopacket,代码行数:11,代码来源:ctp.go
示例8: decodeSCTPHeartbeat
func decodeSCTPHeartbeat(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPHeartbeat{
SCTPChunk: decodeSCTPChunk(data),
}
paramData := data[4:sc.Length]
for len(paramData) > 0 {
p := SCTPHeartbeatParameter(decodeSCTPParameter(paramData))
paramData = paramData[p.ActualLength:]
sc.Parameters = append(sc.Parameters, p)
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:CNDonny,项目名称:scope,代码行数:13,代码来源:sctp.go
示例9: decodeMPLS
func decodeMPLS(data []byte, p gopacket.PacketBuilder) error {
decoded := binary.BigEndian.Uint32(data[:4])
mpls := &MPLS{
Label: decoded >> 12,
TrafficClass: uint8(decoded>>9) & 0x7,
StackBottom: decoded&0x100 != 0,
TTL: uint8(decoded),
BaseLayer: BaseLayer{data[:4], data[4:]},
}
p.AddLayer(mpls)
if mpls.StackBottom {
return p.NextDecoder(MPLSPayloadDecoder)
}
return p.NextDecoder(gopacket.DecodeFunc(decodeMPLS))
}
开发者ID:hgGeorg,项目名称:mongo,代码行数:15,代码来源:mpls.go
示例10: decodeSCTPData
func decodeSCTPData(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPData{
SCTPChunk: decodeSCTPChunk(data),
Unordered: data[1]&0x4 != 0,
BeginFragment: data[1]&0x2 != 0,
EndFragment: data[1]&0x1 != 0,
TSN: binary.BigEndian.Uint32(data[4:8]),
StreamId: binary.BigEndian.Uint16(data[8:10]),
StreamSequence: binary.BigEndian.Uint16(data[10:12]),
PayloadProtocol: binary.BigEndian.Uint32(data[12:16]),
}
// Length is the length in bytes of the data, INCLUDING the 16-byte header.
sc.PayloadData = data[16:sc.Length]
p.AddLayer(sc)
p.SetApplicationLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:CNDonny,项目名称:scope,代码行数:17,代码来源:sctp.go
示例11: decodeSCTPInit
func decodeSCTPInit(data []byte, p gopacket.PacketBuilder) error {
sc := &SCTPInit{
SCTPChunk: decodeSCTPChunk(data),
InitiateTag: binary.BigEndian.Uint32(data[4:8]),
AdvertisedReceiverWindowCredit: binary.BigEndian.Uint32(data[8:12]),
OutboundStreams: binary.BigEndian.Uint16(data[12:14]),
InboundStreams: binary.BigEndian.Uint16(data[14:16]),
InitialTSN: binary.BigEndian.Uint32(data[16:20]),
}
paramData := data[20:sc.ActualLength]
for len(paramData) > 0 {
p := SCTPInitParameter(decodeSCTPParameter(paramData))
paramData = paramData[p.ActualLength:]
sc.Parameters = append(sc.Parameters, p)
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:CNDonny,项目名称:scope,代码行数:18,代码来源:sctp.go
示例12: decodeSCTPError
func decodeSCTPError(data []byte, p gopacket.PacketBuilder) error {
// remarkably similar to decodeSCTPHeartbeat ;)
chunk, err := decodeSCTPChunk(data)
if err != nil {
return err
}
sc := &SCTPError{
SCTPChunk: chunk,
}
paramData := data[4:sc.Length]
for len(paramData) > 0 {
p := SCTPErrorParameter(decodeSCTPParameter(paramData))
paramData = paramData[p.ActualLength:]
sc.Parameters = append(sc.Parameters, p)
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:cdshann,项目名称:minimega,代码行数:18,代码来源:sctp.go
示例13: decodeCiscoDiscovery
func decodeCiscoDiscovery(data []byte, p gopacket.PacketBuilder) error {
c := &CiscoDiscovery{
Version: data[0],
TTL: data[1],
Checksum: binary.BigEndian.Uint16(data[2:4]),
}
if c.Version != 1 && c.Version != 2 {
return fmt.Errorf("Invalid CiscoDiscovery version number %d", c.Version)
}
var err error
c.Values, err = decodeCiscoDiscoveryTLVs(data[4:])
if err != nil {
return err
}
c.Contents = data[0:4]
c.Payload = data[4:]
p.AddLayer(c)
return p.NextDecoder(gopacket.DecodeFunc(decodeCiscoDiscoveryInfo))
}
开发者ID:CNDonny,项目名称:scope,代码行数:19,代码来源:cdp.go
示例14: decodeSCTPSack
func decodeSCTPSack(data []byte, p gopacket.PacketBuilder) error {
chunk, err := decodeSCTPChunk(data)
if err != nil {
return err
}
sc := &SCTPSack{
SCTPChunk: chunk,
CumulativeTSNAck: binary.BigEndian.Uint32(data[4:8]),
AdvertisedReceiverWindowCredit: binary.BigEndian.Uint32(data[8:12]),
NumGapACKs: binary.BigEndian.Uint16(data[12:14]),
NumDuplicateTSNs: binary.BigEndian.Uint16(data[14:16]),
}
// We maximize gapAcks and dupTSNs here so we're not allocating tons
// of memory based on a user-controlable field. Our maximums are not exact,
// but should give us sane defaults... we'll still hit slice boundaries and
// fail if the user-supplied values are too high (in the for loops below), but
// the amount of memory we'll have allocated because of that should be small
// (< sc.ActualLength)
gapAcks := sc.SCTPChunk.ActualLength / 2
dupTSNs := (sc.SCTPChunk.ActualLength - gapAcks*2) / 4
if gapAcks > int(sc.NumGapACKs) {
gapAcks = int(sc.NumGapACKs)
}
if dupTSNs > int(sc.NumDuplicateTSNs) {
dupTSNs = int(sc.NumDuplicateTSNs)
}
sc.GapACKs = make([]uint16, 0, gapAcks)
sc.DuplicateTSNs = make([]uint32, 0, dupTSNs)
bytesRemaining := data[16:]
for i := 0; i < int(sc.NumGapACKs); i++ {
sc.GapACKs = append(sc.GapACKs, binary.BigEndian.Uint16(bytesRemaining[:2]))
bytesRemaining = bytesRemaining[2:]
}
for i := 0; i < int(sc.NumDuplicateTSNs); i++ {
sc.DuplicateTSNs = append(sc.DuplicateTSNs, binary.BigEndian.Uint32(bytesRemaining[:4]))
bytesRemaining = bytesRemaining[4:]
}
p.AddLayer(sc)
return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:cdshann,项目名称:minimega,代码行数:40,代码来源:sctp.go
示例15: decodeEthernetCTPFromFunctionType
// decodeEthernetCTPFromFunctionType reads in the first 2 bytes to determine the EthernetCTP
// layer type to decode next, then decodes based on that.
func decodeEthernetCTPFromFunctionType(data []byte, p gopacket.PacketBuilder) error {
function := EthernetCTPFunction(binary.LittleEndian.Uint16(data[:2]))
switch function {
case EthernetCTPFunctionReply:
reply := &EthernetCTPReply{
Function: function,
ReceiptNumber: binary.LittleEndian.Uint16(data[2:4]),
Data: data[4:],
BaseLayer: BaseLayer{data, nil},
}
p.AddLayer(reply)
p.SetApplicationLayer(reply)
return nil
case EthernetCTPFunctionForwardData:
forward := &EthernetCTPForwardData{
Function: function,
ForwardAddress: data[2:8],
BaseLayer: BaseLayer{data[:8], data[8:]},
}
p.AddLayer(forward)
return p.NextDecoder(gopacket.DecodeFunc(decodeEthernetCTPFromFunctionType))
}
return fmt.Errorf("Unknown EthernetCTP function type %v", function)
}
开发者ID:nplanel,项目名称:gopacket,代码行数:26,代码来源:ctp.go
示例16: init
func init() {
LayerTypeMoldUDP64MessageBlock = gopacket.RegisterLayerType(10001, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlock", gopacket.DecodeFunc(decodeMoldUDP64MessageBlock)})
LayerTypeMoldUDP64MessageBlockChained = gopacket.RegisterLayerType(10003, gopacket.LayerTypeMetadata{"MoldUDP64MessageBlockChained", gopacket.DecodeFunc(decodeMoldUDP64MessageBlockChained)})
MoldUDP64LayerFactory = packet.NewSingleDecodingLayerFactory(
LayerTypeMoldUDP64,
func() gopacket.DecodingLayer { return &MoldUDP64{} },
)
MoldUDP64MessageBlockLayerFactory = packet.NewSingleDecodingLayerFactory(
LayerTypeMoldUDP64MessageBlock,
func() gopacket.DecodingLayer { return &MoldUDP64MessageBlock{} },
)
}
开发者ID:ikravets,项目名称:ev,代码行数:15,代码来源:moldudp64.go
示例17: decodeTom
// Copyright (c) Ilia Kravets, 2015. All rights reserved. PROVIDED "AS IS"
// WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. See LICENSE file for details.
package miax
import (
"encoding/binary"
"time"
"github.com/google/gopacket"
"github.com/ikravets/errs"
"my/ev/packet"
)
var LayerTypeTom = gopacket.RegisterLayerType(11002, gopacket.LayerTypeMetadata{"Tom", gopacket.DecodeFunc(decodeTom)})
func decodeTom(data []byte, p gopacket.PacketBuilder) error {
tomMessageType := TomMessageType(data[0])
return tomMessageType.Decode(data, p)
}
/************************************************************************/
type TomSide struct {
Price packet.Price
Size int
PriorityCustomerSize int
Condition byte
Side packet.MarketSide // inferred from message type
}
开发者ID:ikravets,项目名称:ev,代码行数:31,代码来源:tom.go
示例18: init
func init() {
LayerTypeMachTop = gopacket.RegisterLayerType(11000, gopacket.LayerTypeMetadata{"MachTop", gopacket.DecodeFunc(decodeMach)})
LayerTypeMach = gopacket.RegisterLayerType(11001, gopacket.LayerTypeMetadata{"Mach", gopacket.DecodeFunc(decodeMach)})
MachTopLayerFactory = packet.NewSingleDecodingLayerFactory(
LayerTypeMachTop,
func() gopacket.DecodingLayer { return &MachTop{} },
)
MachLayerFactory = packet.NewSingleDecodingLayerFactory(
LayerTypeMach,
func() gopacket.DecodingLayer { return &Mach{} },
)
}
开发者ID:ikravets,项目名称:ev,代码行数:13,代码来源:mach.go
示例19: LayerType
// LayerType returns gopacket.LayerTypeSCTP
func (s *SCTP) LayerType() gopacket.LayerType { return LayerTypeSCTP }
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)
}
var sctpChunkTypePrefixDecoder = gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix)
// TransportFlow returns a flow based on the source and destination SCTP port.
func (s *SCTP) TransportFlow() gopacket.Flow {
return gopacket.NewFlow(EndpointSCTPPort, s.sPort, s.dPort)
}
func decodeWithSCTPChunkTypePrefix(data []byte, p gopacket.PacketBuilder) error {
chunkType := SCTPChunkType(data[0])
return chunkType.Decode(data, p)
}
// SerializeTo is for gopacket.SerializableLayer.
func (s SCTP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
bytes, err := b.PrependBytes(12)
if err != nil {
开发者ID:cdshann,项目名称:minimega,代码行数:30,代码来源:sctp.go
示例20: decodePitch
package bats
import (
"encoding/binary"
"errors"
"github.com/google/gopacket"
"github.com/ikravets/errs"
"my/ev/packet"
)
/************************************************************************/
var LayerTypePitch = gopacket.RegisterLayerType(12001, gopacket.LayerTypeMetadata{"Pitch", gopacket.DecodeFunc(decodePitch)})
func decodePitch(data []byte, p gopacket.PacketBuilder) error {
if len(data) < 2 {
return errors.New("message to short")
}
pitchMessageType := PitchMessageType(data[1])
return pitchMessageType.Decode(data, p)
}
/************************************************************************/
type PitchMessageType uint8
func (a PitchMessageType) Decode(data []byte, p gopacket.PacketBuilder) error {
layer := PitchMessageTypeMetadata[a].CreateLayer()
if err := layer.DecodeFromBytes(data, p); err != nil {
开发者ID:ikravets,项目名称:ev,代码行数:30,代码来源:pitch.go
注:本文中的github.com/google/gopacket.DecodeFunc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论