MCPcopy Create free account
hub / github.com/Edgio/vflow / decodeIPv4Header

Method decodeIPv4Header

packet/network.go:161–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

159}
160
161func (p *Packet) decodeIPv4Header() error {
162 if len(p.data) < IPv4HLen {
163 return errShortIPv4HeaderLength
164 }
165
166 var (
167 src net.IP = p.data[12:16]
168 dst net.IP = p.data[16:20]
169 )
170
171 p.L3 = IPv4Header{
172 Version: int(p.data[0] & 0xf0 >> 4),
173 TOS: int(p.data[1]),
174 TotalLen: int(p.data[2])<<8 | int(p.data[3]),
175 ID: int(p.data[4])<<8 | int(p.data[5]),
176 Flags: int(p.data[6] & 0x07),
177 TTL: int(p.data[8]),
178 Protocol: int(p.data[9]),
179 Checksum: int(p.data[10])<<8 | int(p.data[11]),
180 Src: src.String(),
181 Dst: dst.String(),
182 }
183
184 p.data = p.data[IPv4HLen:]
185
186 return nil
187}

Callers 3

TestDecodeIPv4HeaderFunction · 0.95
DecoderMethod · 0.95
decodeEthernetHeaderMethod · 0.95

Calls 1

StringMethod · 0.80

Tested by 1

TestDecodeIPv4HeaderFunction · 0.76