dotpcap / packetnet

Official repository - High performance .Net assembly for dissecting and constructing network packets such as ethernet, ip, tcp, udp etc.
Mozilla Public License 2.0
469 stars 105 forks source link

Udp checksum missing & UDP length calculated incorrectly #156

Closed maxlluky closed 2 years ago

maxlluky commented 2 years ago

Hello. I am programming a DHCP server with SharpPcap and PacketNet.

Therefore I create the UdpPacket with the following code. UdpPacket udpPacket = new UdpPacket(68, 67);

As the next step I create the DhcpV4Packet. The ParentPacket is the UdpPacket. DhcpV4Packet dhcpv4Packet = new DhcpV4Packet(new ByteArraySegment(new byte[300]), udpPacket)

The next step defines the DhcpV4Options and adds them via a list to the DhcpV4Packet. dhcpOptionList.Add(new ServerIdOption(dhcpIp)); dhcpv4Packet.SetOptions(dhcpOptionList);

Finally, I add the DhcpV4Packet as UdpPaylod. udpPacket.PayloadPacket= dhcpv4Packet;

The problem: The length in the Udp datagram is calculated incorrectly and the Udp checksum is missing. If I use the following code the length is calculated correctly (Udp checksum is still missing though): udpPacket.PayloadData = dhcpv4Packet.Bytes;

Did I miss something or is there a bug? Thank you :)

PhyxionNL commented 2 years ago

You're better of making a DHCP server with a UdpClient :)

If you insist on going this route, you'll need to create a UdpPacket from a ByteArraySegment and set the corresponding fields and payloads. There's no "magic glue" that automatically sets everything (almost everything is based on the underlying data).

maxlluky commented 2 years ago

Thanks for the quick reply. Issue can be closed :)