Parse binary data for C # bootp server?

I need one of my C # .NET applications to work as a bootp server. The protocol is pretty simple, but I don't know an easy way to create / analyze binary data.

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

+4
source share
2 answers

There are several ways to do this. You may be able to play with marshaling attributes such as StructLayout to pack the structure into an array of bytes, but this is probably complicated and not worth the effort.

You can use a specialized structure such as Protobuf to assign a class so that it is serialized according to the structure you need.

But, in my experience, the easiest, fastest, and most flexible way to create such a binary structure is to use the MemoryStream class to store the fraction buffer, and then use the BinaryWriter around it to actually write the binary data to the stream.

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

+1
source

You can create a simple structure, for example:

[Serializable] [StructLayout(LayoutKind.Sequential, Pack=1)] public struct MyData { public byte OpCode; public byte HardwareType; public byte HardwareAddressType; public byte Hops; public int TransactionId; public short Seconds; public short Flags; public int ClientIPAddress; public int CurrentIP; // all other fields in the required sequence } 

and use the code this blogpost to serialize / deserialize packages. But there may be a problem with ServerName and BootFilename due to differences in coding and probably you need to specify the exact field field for each of the fields (see this section in msdn for more information).
Hope this helps :)

+2
source

Source: https://habr.com/ru/post/1300892/


All Articles