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