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


Golang packet.Packet類代碼示例

本文整理匯總了Golang中github.com/ghedo/go/pkt/packet.Packet的典型用法代碼示例。如果您正苦於以下問題:Golang Packet類的具體用法?Golang Packet怎麽用?Golang Packet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: SetPayload

func (p *Packet) SetPayload(pl packet.Packet) error {
	p.pkt_payload = pl
	p.Protocol = TypeToProtocol(pl.GetType())
	p.Length = p.GetLength()

	pl.InitChecksum(p.pseudo_checksum())

	return nil
}
開發者ID:kelixin,項目名稱:go.pkt,代碼行數:9,代碼來源:pkt.go

示例2: Answers

func (p *Packet) Answers(other packet.Packet) bool {
	if other == nil || other.GetType() != packet.ICMPv6 {
		return false
	}

	if other.(*Packet).Type == EchoRequest && p.Type == EchoReply {
		return true
	}

	return false
}
開發者ID:kelixin,項目名稱:go.pkt,代碼行數:11,代碼來源:pkt.go

示例3: FindLayer

// Return the first layer of the given type in the packet. If no suitable layer
// is found, return nil.
func FindLayer(p packet.Packet, layer packet.Type) packet.Packet {
	switch {
	case p == nil:
		return nil

	case p.GetType() == layer:
		return p

	default:
		return FindLayer(p.Payload(), layer)
	}
}
開發者ID:kelixin,項目名稱:go.pkt,代碼行數:14,代碼來源:layers.go

示例4: UnpackAll

// Recursively unpack the given byte slice into a packet. The link_type argument
// must specify the type of the first layer in the input data, successive layers
// will be detected automatically.
//
// Note that unpacking is done without copying the input slice, which means that
// if the slice is modifed, it may affect the packets that where unpacked from
// it. If you can't guarantee that the data slice won't change, you'll need to
// copy it and pass the copy to UnpackAll().
func UnpackAll(buf []byte, link_type packet.Type) (packet.Packet, error) {
	var b packet.Buffer
	b.Init(buf)

	first_pkt := packet.Packet(nil)
	prev_pkt := packet.Packet(nil)

	for link_type != packet.None {
		var p packet.Packet

		if b.Len() <= 0 {
			break
		}

		switch link_type {
		case packet.ARP:
			p = &arp.Packet{}
		case packet.Eth:
			p = &eth.Packet{}
		case packet.ICMPv4:
			p = &icmpv4.Packet{}
		case packet.ICMPv6:
			p = &icmpv6.Packet{}
		case packet.IPv4:
			p = &ipv4.Packet{}
		case packet.IPv6:
			p = &ipv6.Packet{}
		case packet.LLC:
			p = &llc.Packet{}
		case packet.RadioTap:
			p = &radiotap.Packet{}
		case packet.SLL:
			p = &sll.Packet{}
		case packet.SNAP:
			p = &snap.Packet{}
		case packet.TCP:
			p = &tcp.Packet{}
		case packet.UDP:
			p = &udp.Packet{}
		case packet.VLAN:
			p = &vlan.Packet{}
		default:
			p = &raw.Packet{}
		}

		if p == nil {
			break
		}

		b.NewLayer()

		err := p.Unpack(&b)
		if err != nil {
			return nil, err
		}

		if prev_pkt != nil {
			prev_pkt.SetPayload(p)
		} else {
			first_pkt = p
		}

		prev_pkt = p
		link_type = p.GuessPayloadType()
	}

	return first_pkt, nil
}
開發者ID:kelixin,項目名稱:go.pkt,代碼行數:76,代碼來源:layers.go


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