用 C++ 编写 Magic Packet
我想发送魔术包来唤醒通过 LAN 连接到 mbed 的特定 PC(特定 MAC 地址)。我在代码项目中找到了以下代码。
我的 MAC 地址:00-C0-9F-BD-E4-3A(示例).....我如何声明它并将其填充到数组中。* 我对编程知之甚少。所以请忽略任何错误或错过的解释。
字节magicP[102];
...
//Fill in magic packet with 102 Bytes of data
//Header
//fill 6 Bytes with 0xFF
for (int i=0;i<6;i++)
magicP[i] = 0xff;
//First 6 bytes (these must be repeated!!)
//fill bytes 6-12
for (i=0;i<6;i++) {
//Get 2 charachters from mac address and convert it to int to fill
//magic packet
magicP[i+6] = HexStrToInt(macAddr.Mid(i*2,2));
}
//fill remaining 90 bytes (15 time repeat)
for (i=0;i<15;i++) memcpy(&magicP[(i+2)*6],&magicP[6],6);
...
就像我找到这段代码的地方一样: http://www.codeproject.com/KB/IP/WOL.aspx
I want to send magic packet to wake up a specific PC(specific MAC address) connected to an mbed through LAN . I have found the following code in code project.
My MAC Address : 00-C0-9F-BD-E4-3A (sample).....how can i declare this and fill this in the array.* I have little knowledge in Programming. so please ignore any mistake or miss interpretation.
BYTE magicP[102];
...
//Fill in magic packet with 102 Bytes of data
//Header
//fill 6 Bytes with 0xFF
for (int i=0;i<6;i++)
magicP[i] = 0xff;
//First 6 bytes (these must be repeated!!)
//fill bytes 6-12
for (i=0;i<6;i++) {
//Get 2 charachters from mac address and convert it to int to fill
//magic packet
magicP[i+6] = HexStrToInt(macAddr.Mid(i*2,2));
}
//fill remaining 90 bytes (15 time repeat)
for (i=0;i<15;i++) memcpy(&magicP[(i+2)*6],&magicP[6],6);
...
here is the like where i have found this code:
http://www.codeproject.com/KB/IP/WOL.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕您没有提供足够的代码来给出明确的答案(链接可能有帮助),但我认为您不必填写
magicP[]
你自己 - 这就是代码为你做的事情。看来您必须提供十六进制 MAC 地址作为macAddr
变量中的输入,作为 12 个十六进制数字的字符串(例如“023FDCA889FA”)。编辑:阅读链接后,我认为我的预感得到了证实。该代码片段显示了如何根据提供的 macAddr 构造
magicP[]
数组(最终保存数据包有效负载),以说明其前面的理论解释。因此,需要有一个定义std::string macAddr;
,您可以在其中输入 MAC 地址,然后将其传递给计算方法。我建议您从链接的项目(或其他一些开放的 WOL 程序)下载完整的源代码,因为这样可以更好地理解各个部分如何组合在一起。
I'm afraid to you are not providing enough of the code to give an unambiguous answer (a link might help), but I think that you don't have to fill in
magicP[]
yourself - this is what the code is doing for you. It appears that you have to provide your hexadecimal MAC address as input in themacAddr
variable, as a string of 12 hexadecimal digits (e.g. "023FDCA889FA").Edit: After reading the link, I consider my hunch confirmed. The code snippet shows how the
magicP[]
array (which eventually holds the packet payload) is constructed based on the providedmacAddr
, in order to illustrate a theoretical explanation preceding it. So somewhere there needs to be a definitionstd::string macAddr;
into which you enter your MAC address, and which is then passed to the calculation method.I suggest that you download the full source from the linked project (or some other open WOL program), as that will give a better understanding on how the pieces fit together.