You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm struggling to understand the principles of how to correctly create multi-layer packets (such as ICMP->IPv4->Ethernet) with libpnet - in particular, how to correctly define packet/buffer/payload sizes between the layers. I seem to be getting inconsistent behaviour between the various layers - and so I am probably misunderstanding how this is supposed to work.
I am working from the 'outside-in' so (for example) creating an ICMP message, then wrapping that in IPv4, then wrapping that in Ethernet. This is already requiring me to make three allocations/copies - but more fundamentally, I can't see how to manage the payload extents consistently.
My example code is below.
The EchoReplyPacket.packet_size() reports 8 - so this is just the header (excludes the payload). EchoReplyPacket.payload().len() reports 32. (total 40 bytes).
Ipv4Packet.packet_size() reports 60 - so this includes both the header (20 bytes) and the ICMP payload (40) (total 60 bytes). Ipv4Packet.payload().size reports 40.
Ethernet.packet_size() reports 14 - so this is just the header. Ethernet.payload().len() reports 60. (total 74 bytes).
This seems inconsistent. Why does the IPv4 packet_size include the payload - but Ethernet and ICMP do not?
Also, even though I have created the Ipv4Packet with the appropriately sized buffer, I also have to call set_total_length before I can set the payload (otherwise panic) - is this correct? I don't seem to have to do this for Ethernet or ICMP layers.
Ideally, I would just create a single generously-sized buffer at the outset, and the write Ethernet, IPv4, ICMP layers in sequence - then patch-up the lengths and checksums. Then, send the appropriate slice of this buffer to the network. If anyone has an examples of this approach, it would be helpful/appreciated.
I'm struggling to understand the principles of how to correctly create multi-layer packets (such as ICMP->IPv4->Ethernet) with libpnet - in particular, how to correctly define packet/buffer/payload sizes between the layers. I seem to be getting inconsistent behaviour between the various layers - and so I am probably misunderstanding how this is supposed to work.
I am working from the 'outside-in' so (for example) creating an ICMP message, then wrapping that in IPv4, then wrapping that in Ethernet. This is already requiring me to make three allocations/copies - but more fundamentally, I can't see how to manage the payload extents consistently.
My example code is below.
The EchoReplyPacket.packet_size() reports 8 - so this is just the header (excludes the payload). EchoReplyPacket.payload().len() reports 32. (total 40 bytes).
Ipv4Packet.packet_size() reports 60 - so this includes both the header (20 bytes) and the ICMP payload (40) (total 60 bytes). Ipv4Packet.payload().size reports 40.
Ethernet.packet_size() reports 14 - so this is just the header. Ethernet.payload().len() reports 60. (total 74 bytes).
This seems inconsistent. Why does the IPv4 packet_size include the payload - but Ethernet and ICMP do not?
Also, even though I have created the Ipv4Packet with the appropriately sized buffer, I also have to call set_total_length before I can set the payload (otherwise panic) - is this correct? I don't seem to have to do this for Ethernet or ICMP layers.
Ideally, I would just create a single generously-sized buffer at the outset, and the write Ethernet, IPv4, ICMP layers in sequence - then patch-up the lengths and checksums. Then, send the appropriate slice of this buffer to the network. If anyone has an examples of this approach, it would be helpful/appreciated.
Thanks,
The text was updated successfully, but these errors were encountered: