From b3711c735bcfb29315547f7e7381222b46ac277b Mon Sep 17 00:00:00 2001 From: Marschall TM <36601278+Marschall-dev@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:01:04 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7dd0f02..03df7ee 100644 --- a/README.md +++ b/README.md @@ -42,24 +42,26 @@ See the Examples folder for a range of examp ## Usage Example of a DHCP Discover package. The payload can be sent with a UdpClient or socket. ```csharp -private static byte[] buildDhcpPayload() +Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); +IPAddress serverAddr = IPAddress.Parse("192.168.2.1"); +IPEndPoint endPoint = new IPEndPoint(serverAddr, 67); + +DhcpOption dhcpServerIdentifierOption = new DhcpOption() { - DhcpOption dhcpServerIdentifierOption = new DhcpOption() - { - optionId = dhcpOptionIds.DhcpMessageType, - optionLength = new byte[] { 0x01 }, - optionValue = new byte[] { 0x01 }, - }; + optionId = dhcpOptionIds.DhcpMessageType, + optionLength = new byte[] { 0x01 }, + optionValue = new byte[] { 0x01 }, +}; +DhcpPacket dhcpDiscoveryPacket = new DhcpPacket() +{ + transactionID = new byte[] { 0x00, 0x00, 0x00, 0x00 }, + dhcpOptions = dhcpServerIdentifierOption.buildDhcpOption().ToArray(), +}; - DhcpPacket dhcpDiscoveryPacket = new DhcpPacket() - { - transactionID = new byte[] { 0x00, 0x00, 0x00, 0x00 }, - dhcpOptions = dhcpServerIdentifierOption.buildDhcpOption().ToArray(), - }; +byte[] send_buffer = dhcpDiscoveryPacket.buildPacket(); +sock.SendTo(send_buffer, endPoint); - return dhcpDiscoveryPacket.buildPacket(); -} ``` ## NuGet From 20c69ca2ea348de9421c4f8905c0df72f7c31fd2 Mon Sep 17 00:00:00 2001 From: Marschall TM <36601278+Marschall-dev@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:02:07 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03df7ee..cfddf83 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ DhcpOption dhcpServerIdentifierOption = new DhcpOption() DhcpPacket dhcpDiscoveryPacket = new DhcpPacket() { transactionID = new byte[] { 0x00, 0x00, 0x00, 0x00 }, - dhcpOptions = dhcpServerIdentifierOption.buildDhcpOption().ToArray(), + dhcpOptions = dhcpServerIdentifierOption.buildDhcpOption(), }; byte[] send_buffer = dhcpDiscoveryPacket.buildPacket();