Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlluky authored Nov 5, 2020
1 parent 9c4227c commit b3711c7
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().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
Expand Down

0 comments on commit b3711c7

Please sign in to comment.