在 Winsock 中实现原始以太网

发布于 2024-07-18 07:32:17 字数 457 浏览 1 评论 0原文

我正在做一个项目,我必须制作自定义数据包。 也就是说,我必须控制每个数据包头。 我正在尝试使用套接字来做到这一点。 基本上,我需要做的是:

SOCKET s = socket(PF_UNSPEC, SOCK_RAW, ethernet_type);

ethernet_type 是定制的、非标准的,比如 0xAAAA。 我正在使用 htons()。 另外,我最好不要使用 winPcap。

现在,我收到错误 10043,协议不受支持。

该错误消息似乎建议我可以将协议配置到我的系统中,但我不知道该怎么做。

它说:

不支持协议。 所请求的协议尚未配置到系统中,或者不存在其实现。 例如,套接字调用请求 SOCK_DGRAM 套接字,但指定流协议。

这里有一些不同的问题,所以如果有人有任何意见,我将非常感激。

I am doing a project where I must craft custom packets. That is, I have to have control of each packet header. I am trying to do this using sockets. Basically, what I need to do is this:

SOCKET s = socket(PF_UNSPEC, SOCK_RAW, ethernet_type);

The ethernet_type is something that is customized, non-standard, like 0xAAAA. I am using htons(). Also, it is very preferable for me not to use winPcap.

Right now, I am getting error 10043, protocol not supported.

The error message seems to suggest that I can configure the protocol into my system, but I have no idea how to do that.

It says:

Protocol not supported. The requested protocol has not been configured into the system, or no implementation for it exists. For example, a socket call requests a SOCK_DGRAM socket, but specifies a stream protocol.

There are a few different issues here, so if anyone has any input at all I'd really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有你我更好 2024-07-25 07:32:17

根据 这些 文章,Microsoft 在不可删除的修补程序中从 Windows 中删除了原始套接字支持。 因此,除非您想切换到另一个操作系统,否则您可能会运气不好。

According to these articles, Microsoft removed raw socket support from Windows in a non-removable hotfix. So you may be out of luck unless you want to switch to another OS.

淡写薰衣草的香 2024-07-25 07:32:17

我认为向套接字调用添加新协议将是一件相当困难的事情。 您必须确保套接字支持该调用。 我认为你必须重新编译套接字函数,并且我认为这在 Windows 下不容易实现。

制作自定义数据包不需要您创建新协议

我认为指定原始套接字的正确方法是这样的

SOCKET s;
s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);

如果您真的想像变量名称所建议的那样使用原始以太网,那么您可以使用 winpcap 驱动程序或编写你自己的驱动程序

我不认为还有另一个“简单”原始以太网的解决方案。 winpcap 相当简单,所以你可能想检查一下

I think that adding new protocols to the socket call would be something quite difficult. You'd have to make sure that socket supports that call. I think you would have to recompile the socket function and I dont think it's easily possible under windows.

Crafting custom packets does not require you to create a new protocol

I think that the correct way of specifying a RAW socket is like this

SOCKET s;
s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);

If you're really trying to play with raw ethernet like your variable names suggest, then either you use winpcap driver or write your own driver

I don't think there is another "easy" solution to raw ethernet. winpcap is rather easy so you might want to check it out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文