user1131997
user1131997

Reputation:

Building DHCP packet ( DHCPDISCOVER ) , packet structure

I'm trying to build DHCP packet in then send it via UDP ( "0xff.0xff.0xff.0xff", 67 port ).

I have sucessfully connected to my DHCP server, but I have problems with first packet structure ( DHCPDISCOVER ) as I see, but I have built it from RFC && Wiki, and have checked all fields/size in bytes of these fields.

Here is the code in C# ( don't argue , this code is only for testing purpose to check the work of DHCP protocal and structures of packet ): http://pastebin.com/9NXuHyrw

I have initialized the body of discover dhcp-packet in class and you can check the struct of it ( size, right fields ).

So, what's wrong?

Thanks, Best Regards

Upvotes: 1

Views: 1795

Answers (1)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234654

Using a BinaryFormatter will not give you what you are expecting. It will produce a sequence of bytes in an unspecified format. The only guarantee you have about that sequence of bytes is that you can deserialize it into an object that resembles the original. It is highly likely it doesn't look at all like a DHCP packet.

To get an array of bytes with the correct packet structure you will have to use a BinaryWriter over a MemoryStream and write each field manually.

Upvotes: 1

Related Questions