當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PacketBuilder.SetTransportLayer方法代碼示例

本文整理匯總了Golang中code/google/com/p/gopacket.PacketBuilder.SetTransportLayer方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketBuilder.SetTransportLayer方法的具體用法?Golang PacketBuilder.SetTransportLayer怎麽用?Golang PacketBuilder.SetTransportLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在code/google/com/p/gopacket.PacketBuilder的用法示例。


在下文中一共展示了PacketBuilder.SetTransportLayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: decodeUDP

func decodeUDP(data []byte, p gopacket.PacketBuilder) error {
	udp := &UDP{}
	err := udp.DecodeFromBytes(data, p)
	p.AddLayer(udp)
	p.SetTransportLayer(udp)
	if err != nil {
		return err
	}
	return p.NextDecoder(gopacket.LayerTypePayload)
}
開發者ID:jcantrill,項目名稱:geard,代碼行數:10,代碼來源:udp.go

示例2: decodeSCTP

func decodeSCTP(data []byte, p gopacket.PacketBuilder) error {
	sctp := &SCTP{
		SrcPort:         SCTPPort(binary.BigEndian.Uint16(data[:2])),
		sPort:           data[:2],
		DstPort:         SCTPPort(binary.BigEndian.Uint16(data[2:4])),
		dPort:           data[2:4],
		VerificationTag: binary.BigEndian.Uint32(data[4:8]),
		Checksum:        binary.BigEndian.Uint32(data[8:12]),
		BaseLayer:       BaseLayer{data[:12], data[12:]},
	}
	p.AddLayer(sctp)
	p.SetTransportLayer(sctp)
	return p.NextDecoder(sctpChunkTypePrefixDecoder)
}
開發者ID:pombredanne,項目名稱:geard,代碼行數:14,代碼來源:sctp.go

示例3: decodeRUDP

func decodeRUDP(data []byte, p gopacket.PacketBuilder) error {
	r := &RUDP{
		SYN:          data[0]&0x80 != 0,
		ACK:          data[0]&0x40 != 0,
		EACK:         data[0]&0x20 != 0,
		RST:          data[0]&0x10 != 0,
		NUL:          data[0]&0x08 != 0,
		Version:      data[0] & 0x3,
		HeaderLength: data[1],
		SrcPort:      RUDPPort(data[2]),
		DstPort:      RUDPPort(data[3]),
		DataLength:   binary.BigEndian.Uint16(data[4:6]),
		Seq:          binary.BigEndian.Uint32(data[6:10]),
		Ack:          binary.BigEndian.Uint32(data[10:14]),
		Checksum:     binary.BigEndian.Uint32(data[14:18]),
	}
	if r.HeaderLength < 9 {
		return fmt.Errorf("RUDP packet with too-short header length %d", r.HeaderLength)
	}
	hlen := int(r.HeaderLength) * 2
	r.Contents = data[:hlen]
	r.Payload = data[hlen : hlen+int(r.DataLength)]
	r.VariableHeaderArea = data[18:hlen]
	headerData := r.VariableHeaderArea
	switch {
	case r.SYN:
		if len(headerData) != 6 {
			return fmt.Errorf("RUDP packet invalid SYN header length: %d", len(headerData))
		}
		r.RUDPHeaderSYN = &RUDPHeaderSYN{
			MaxOutstandingSegments: binary.BigEndian.Uint16(headerData[:2]),
			MaxSegmentSize:         binary.BigEndian.Uint16(headerData[2:4]),
			OptionFlags:            binary.BigEndian.Uint16(headerData[4:6]),
		}
	case r.EACK:
		if len(headerData)%4 != 0 {
			return fmt.Errorf("RUDP packet invalid EACK header length: %d", len(headerData))
		}
		r.RUDPHeaderEACK = &RUDPHeaderEACK{make([]uint32, len(headerData)/4)}
		for i := 0; i < len(headerData); i += 4 {
			r.SeqsReceivedOK[i/4] = binary.BigEndian.Uint32(headerData[i : i+4])
		}
	}
	p.AddLayer(r)
	p.SetTransportLayer(r)
	return p.NextDecoder(gopacket.LayerTypePayload)
}
開發者ID:dazer-chen,項目名稱:gopacket,代碼行數:47,代碼來源:rudp.go


注:本文中的code/google/com/p/gopacket.PacketBuilder.SetTransportLayer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。