• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gopacket.PacketBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/packetbeat/gopacket.PacketBuilder的典型用法代码示例。如果您正苦于以下问题:Golang PacketBuilder类的具体用法?Golang PacketBuilder怎么用?Golang PacketBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PacketBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: decodeSCTPEmptyLayer

func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPEmptyLayer{
		SCTPChunk: decodeSCTPChunk(data),
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
开发者ID:donckers,项目名称:gopacket,代码行数:7,代码来源:sctp.go


示例2: 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:donckers,项目名称:gopacket,代码行数:8,代码来源:sctp.go


示例3: 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:donckers,项目名称:gopacket,代码行数:8,代码来源:sctp.go


示例4: 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)
}
开发者ID:donckers,项目名称:gopacket,代码行数:9,代码来源:ip6.go


示例5: 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)
}
开发者ID:donckers,项目名称:gopacket,代码行数:9,代码来源:icmp4.go


示例6: 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
}
开发者ID:donckers,项目名称:gopacket,代码行数:10,代码来源:ipsec.go


示例7: 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
}
开发者ID:donckers,项目名称:gopacket,代码行数:12,代码来源:dns.go


示例8: decodeIPSecAH

func decodeIPSecAH(data []byte, p gopacket.PacketBuilder) error {
	i := &IPSecAH{
		ipv6ExtensionBase: decodeIPv6ExtensionBase(data),
		Reserved:          binary.BigEndian.Uint16(data[2:4]),
		SPI:               binary.BigEndian.Uint32(data[4:8]),
		Seq:               binary.BigEndian.Uint32(data[8:12]),
	}
	i.AuthenticationData = i.Contents[12:]
	p.AddLayer(i)
	return p.NextDecoder(i.NextHeader)
}
开发者ID:donckers,项目名称:gopacket,代码行数:11,代码来源:ipsec.go


示例9: 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:donckers,项目名称:gopacket,代码行数:11,代码来源:ctp.go


示例10: decodingLayerDecoder

func decodingLayerDecoder(d layerDecodingLayer, data []byte, p gopacket.PacketBuilder) error {
	err := d.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(d)
	next := d.NextLayerType()
	if next == gopacket.LayerTypeZero {
		return nil
	}
	return p.NextDecoder(next)
}
开发者ID:donckers,项目名称:gopacket,代码行数:12,代码来源:base.go


示例11: decodeSNAP

func decodeSNAP(data []byte, p gopacket.PacketBuilder) error {
	s := &SNAP{
		OrganizationalCode: data[:3],
		Type:               EthernetType(binary.BigEndian.Uint16(data[3:5])),
		BaseLayer:          BaseLayer{data[:5], data[5:]},
	}
	p.AddLayer(s)
	// BUG(gconnell):  When decoding SNAP, we treat the SNAP type as an Ethernet
	// type.  This may not actually be an ethernet type in all cases,
	// depending on the organizational code.  Right now, we don't check.
	return p.NextDecoder(s.Type)
}
开发者ID:donckers,项目名称:gopacket,代码行数:12,代码来源:llc.go


示例12: decodePPPoE

// decodePPPoE decodes the PPPoE header (see http://tools.ietf.org/html/rfc2516).
func decodePPPoE(data []byte, p gopacket.PacketBuilder) error {
	pppoe := &PPPoE{
		Version:   data[0] >> 4,
		Type:      data[0] & 0x0F,
		Code:      PPPoECode(data[1]),
		SessionId: binary.BigEndian.Uint16(data[2:4]),
		Length:    binary.BigEndian.Uint16(data[4:6]),
	}
	pppoe.BaseLayer = BaseLayer{data[:6], data[6 : 6+pppoe.Length]}
	p.AddLayer(pppoe)
	return p.NextDecoder(pppoe.Code)
}
开发者ID:donckers,项目名称:gopacket,代码行数:13,代码来源:pppoe.go


示例13: 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:donckers,项目名称:gopacket,代码行数:13,代码来源:sctp.go


示例14: decodeIPv6Fragment

func decodeIPv6Fragment(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6Fragment{
		BaseLayer:      BaseLayer{data[:8], data[8:]},
		NextHeader:     IPProtocol(data[0]),
		Reserved1:      data[1],
		FragmentOffset: binary.BigEndian.Uint16(data[2:4]) >> 3,
		Reserved2:      data[3] & 0x6 >> 1,
		MoreFragments:  data[3]&0x1 != 0,
		Identification: binary.BigEndian.Uint32(data[4:8]),
	}
	p.AddLayer(i)
	return p.NextDecoder(gopacket.DecodeFragment)
}
开发者ID:donckers,项目名称:gopacket,代码行数:13,代码来源:ip6.go


示例15: decodeNortelDiscovery

func decodeNortelDiscovery(data []byte, p gopacket.PacketBuilder) error {
	c := &NortelDiscovery{}
	if len(data) < 11 {
		return fmt.Errorf("Invalid NortelDiscovery packet length %d", len(data))
	}
	c.IPAddress = data[0:4]
	c.SegmentID = data[4:7]
	c.Chassis = NDPChassisType(data[7])
	c.Backplane = NDPBackplaneType(data[8])
	c.State = NDPState(data[9])
	c.NumLinks = uint8(data[10])
	p.AddLayer(c)
	return nil
}
开发者ID:donckers,项目名称:gopacket,代码行数:14,代码来源:ndp.go


示例16: decodeIPv6Destination

func decodeIPv6Destination(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6Destination{
		ipv6ExtensionBase: decodeIPv6ExtensionBase(data),
		// We guess we'll 1-2 options, one regular option at least, then maybe one
		// padding option.
		Options: make([]IPv6DestinationOption, 0, 2),
	}
	var opt *IPv6DestinationOption
	for d := i.Contents[2:]; len(d) > 0; d = d[opt.ActualLength:] {
		i.Options = append(i.Options, IPv6DestinationOption(decodeIPv6HeaderTLVOption(d)))
		opt = &i.Options[len(i.Options)-1]
	}
	p.AddLayer(i)
	return p.NextDecoder(i.NextHeader)
}
开发者ID:donckers,项目名称:gopacket,代码行数:15,代码来源:ip6.go


示例17: 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:donckers,项目名称:gopacket,代码行数:18,代码来源:sctp.go


示例18: 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:donckers,项目名称:gopacket,代码行数:19,代码来源:cdp.go


示例19: decodeIPv6Routing

func decodeIPv6Routing(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6Routing{
		ipv6ExtensionBase: decodeIPv6ExtensionBase(data),
		RoutingType:       data[2],
		SegmentsLeft:      data[3],
		Reserved:          data[4:8],
	}
	switch i.RoutingType {
	case 0: // Source routing
		if (len(data)-8)%16 != 0 {
			return fmt.Errorf("Invalid IPv6 source routing, length of type 0 packet %d", len(data))
		}
		for d := i.Contents[8:]; len(d) >= 16; d = d[16:] {
			i.SourceRoutingIPs = append(i.SourceRoutingIPs, net.IP(d[:16]))
		}
	}
	p.AddLayer(i)
	return p.NextDecoder(i.NextHeader)
}
开发者ID:donckers,项目名称:gopacket,代码行数:19,代码来源:ip6.go


示例20: decodeIPv6

func decodeIPv6(data []byte, p gopacket.PacketBuilder) error {
	ip6 := &IPv6{}
	err := ip6.DecodeFromBytes(data, p)
	p.AddLayer(ip6)
	p.SetNetworkLayer(ip6)
	if ip6.HopByHop != nil {
		// TODO(gconnell):  Since HopByHop is now an integral part of the IPv6
		// layer, should it actually be added as its own layer?  I'm leaning towards
		// no.
		p.AddLayer(ip6.HopByHop)
	}
	if err != nil {
		return err
	}
	if ip6.HopByHop != nil {
		return p.NextDecoder(ip6.HopByHop.NextHeader)
	}
	return p.NextDecoder(ip6.NextHeader)
}
开发者ID:donckers,项目名称:gopacket,代码行数:19,代码来源:ip6.go



注:本文中的github.com/packetbeat/gopacket.PacketBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gopacket.SerializeBuffer类代码示例发布时间:2022-05-28
下一篇:
Golang persist.JobInfo类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap