Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Marschall-dev/DhcpDotNet in…
Browse files Browse the repository at this point in the history
…to main
  • Loading branch information
maxlluky committed Nov 5, 2020
2 parents 6196b29 + 20c69ca commit 0e55833
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,26 @@ See the <a href="/DhcpDotNet/Examples/">Examples</a> 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(),
};

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
Expand Down

0 comments on commit 0e55833

Please sign in to comment.