构建DHCP数据包(DHCPDISCOVER),数据包结构
我正在尝试构建 DHCP 数据包,然后通过 UDP(“0xff.0xff.0xff.0xff”,67 端口)发送它。
我已成功连接到我的 DHCP 服务器,但我看到第一个数据包结构 ( DHCPDISCOVER ) 存在问题,但我是根据 RFC && 构建的。 Wiki,并检查了这些字段的所有字段/大小(以字节为单位)。
下面是 C# 代码(不要争论,该代码仅用于测试目的,检查 DHCP 协议和数据包结构的工作): http://pastebin.com/9NXuHyrw
我已经在类中初始化了 discovery dhcp-packet 的主体,您可以检查它的结构(大小、右侧字段)。
那么,出了什么问题呢?
谢谢, 此致
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
BinaryFormatter
不会给您带来您所期望的结果。它将产生未指定格式的字节序列。关于该字节序列的唯一保证是您可以将其反序列化为类似于原始对象的对象。它很可能看起来根本不像 DHCP 数据包。要获取具有正确数据包结构的字节数组,您必须使用
BinaryWriter
通过MemoryStream
并手动写入每个字段。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 aMemoryStream
and write each field manually.