Closed maxlluky closed 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).
Thanks for the quick reply. Issue can be closed :)
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 :)