MCPcopy
hub / github.com/cloudflare/cloudflared / EncodeLayers

Method EncodeLayers

packet/packet.go:116–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114}
115
116func (i *ICMP) EncodeLayers() ([]gopacket.SerializableLayer, error) {
117 ipLayers, err := i.IP.EncodeLayers()
118 if err != nil {
119 return nil, err
120 }
121
122 var serializedPsh []byte = nil
123 if i.Protocol == layers.IPProtocolICMPv6 {
124 psh := &PseudoHeader{
125 SrcIP: i.Src.As16(),
126 DstIP: i.Dst.As16(),
127 // i.Marshal re-calculates the UpperLayerPacketLength
128 UpperLayerPacketLength: 0,
129 NextHeader: uint8(i.Protocol),
130 }
131 serializedPsh = psh.Marshal()
132 }
133 msg, err := i.Marshal(serializedPsh)
134 if err != nil {
135 return nil, err
136 }
137 icmpLayer := gopacket.Payload(msg)
138 return append(ipLayers, icmpLayer), nil
139}
140
141// https://www.rfc-editor.org/rfc/rfc2460#section-8.1
142type PseudoHeader struct {

Callers

nothing calls this directly

Calls 3

MarshalMethod · 0.95
EncodeLayersMethod · 0.65
PayloadMethod · 0.65

Tested by

no test coverage detected