本文整理匯總了Golang中code/google/com/p/gopacket.PacketBuilder.SetNetworkLayer方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketBuilder.SetNetworkLayer方法的具體用法?Golang PacketBuilder.SetNetworkLayer怎麽用?Golang PacketBuilder.SetNetworkLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/gopacket.PacketBuilder
的用法示例。
在下文中一共展示了PacketBuilder.SetNetworkLayer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: decodeIPv4
func decodeIPv4(data []byte, p gopacket.PacketBuilder) error {
ip := &IPv4{}
err := ip.DecodeFromBytes(data, p)
p.AddLayer(ip)
p.SetNetworkLayer(ip)
if err != nil {
return err
}
return p.NextDecoder(ip.NextLayerType())
}
示例2: 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)
}