Search code examples
c#binarybinary-databootp

Parse binary data for c# bootp server?


I need one of my C# .NET applications to act as a bootp server. The protocol is pretty simple but I dont know an easy way to build/parse the binary data.

Any ideas: alt text
(source: tcpipguide.com)


Solution

  • There's a couple ways to do this. You might be able to play around with the marshaling attributes such as StructLayout to pack a structure into a byte array but this is probably tricky and not worth the effort.

    You could use a specialized framework such as Protobuf to attribute a class in such a way that it will be serialized to match the structure you need.

    But in my experience, the easiest, fastest, and most flexible method of creating a binary structure like this is to use a MemoryStream class to hold a buffer of byes, then use a BinaryWriter around it to actually write the binary data into the stream.

    In any case, it helps to have a working server to reference. Use a tool like Wireshark or Microsoft Network Monitor to capture the wire traffic so you can compare your wire format to an example that is known to work.