windows 使用 Winsock 的原始以太网帧
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/766912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Raw Ethernet Frames Using Winsock
提问by devin
I am porting a communications library from Linux to Windows. I know what my approach is for the most part. The library uses all raw ethernet level frames for all the communications.
我正在将一个通信库从 Linux 移植到 Windows。我知道我的方法在很大程度上是什么。该库使用所有原始以太网级帧进行所有通信。
The library I am porting from makes use of the PF_PACKET family and the struct sockaddr_ll. After browsing through the MSDN winsock site, I haven't found an equivalent family/struct. What should my approach be here?
我正在移植的库使用了 PF_PACKET 系列和 struct sockaddr_ll。浏览 MSDN winsock 站点后,我还没有找到等效的 family/struct。我的方法应该是什么?
I have a few ideas, but I am not sure if they are good ideas I could use PF_UNSPEC, for unspecified. I could just pass the number PF_PACKET represents (it's an unsigned short) I could also just make my own sockadddr_ll struct in Windows.
我有一些想法,但我不确定它们是否是好主意,我可以使用 PF_UNSPEC,用于未指定的。我可以只传递 PF_PACKET 代表的数字(它是一个无符号的短)我也可以在 Windows 中创建我自己的 sockadddr_ll 结构。
None of those ideas seem good to me, they just seem like hacks that aren't really likely to work.
这些想法对我来说都不是好事,它们只是看起来不太可能奏效的黑客。
If anyone has any suggestions, I would appreciate it.
如果有人有任何建议,我将不胜感激。
采纳答案by Aziz
I assume you're referring to Raw Sockets (where you have to write the network layer, transport layer, and application layer information). New Windows versions (XP SP2 and up) have very limited support for raw sockets with many restrictions.
我假设您指的是原始套接字(您必须在其中编写网络层、传输层和应用层信息)。新的 Windows 版本(XP SP2 及更高版本)对原始套接字的支持非常有限,有很多限制。
More info(scroll down to "Limitations on Raw Sockets")
更多信息(向下滚动到“原始套接字的限制”)
The solution, I believe, is to use WinPcap, which allows you to send raw packetson those systems.