Perseus
(Anirudh Singh)
March 24, 2017, 2:20pm
1
Hi
I was working on some packet inspection and I am unable to figure out how to find out the length of an ipv4 packet’s payload.
The IPv4 struct has a property Length but that seems to contain the length of the full header.
Could someone point me in the right direction with this?
Thank you!
calmh
(Jakob Borg)
March 24, 2017, 2:35pm
2
It’s Total Length
minus the header length indicated by the IHL
field, unless whatever you’re using to parse the packet does something else with those values.
An IP packet consists of a header section and a data section. An IP packet has no data checksum or any other footer after the data section. Typically the link layer encapsulates IP packets in frames with a CRC footer that detects most errors, and typically the end-to-end TCP layer checksum detects most other errors.
Perseus
(Anirudh Singh)
March 24, 2017, 3:26pm
3
The size values I’m getting are quite large, the payloads have nowhere close to that many indices in them.
Am I doing anything wrong?
func getTotalLength(packet gopacket.Packet) uint16 {
var (
eth layers.Ethernet
ipv4 layers.IPv4
ipv6 layers.IPv6
tcp layers.TCP
err error
)
parser := gopacket.NewDecodingLayerParser(
layers.LayerTypeEthernet,
ð,
&ipv4,
&ipv6,
&tcp)
var layersInPacket []gopacket.LayerType
err = parser.DecodeLayers(packet.Data(), &layersInPacket)
var total_len uint16
total_len = 0
if err == nil {
total_len = ipv4.Length - uint16(ipv4.IHL * 4)
}
return total_len
}
calmh
(Jakob Borg)
March 24, 2017, 6:14pm
4
Doesn’t look entirely unreasonable, but I guess compare to what you see in wireshark or so for the same packets?
system
(system)
Closed
June 22, 2017, 6:14pm
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.