使用驱动程序挂钩网络功能,高级概述?
我刚刚成功编写了我的第一个 Windows 驱动程序(尚未注册 - 但我设法创建了这些东西!)。
我想知道是否有人可以给我一个关于如何实现以下目标的高度概述:
我想编写一个驱动程序,当计算机接收到网络数据包时,在 Windows 对数据包执行操作之前,该驱动程序将实现一些行为,我想获取这些数据并将其输出到 C 或 C++ 程序的控制台。
假设我编写了一个带有控制台的 C/C++ 程序。 C/C++ 程序如何与我编写的挂钩网络活动的驱动程序交互?是否只是一些调用我的驱动程序的 C 代码,该函数将数据作为对象返回,然后我可以使用该对象在控制台中显示?
预先感谢您的任何可能的答复
I have just managed to write my first windows driver (havent registered it yet- but i managed to get the things created!).
I wondered if someone can give me a high overview of how I could achieve the following:
I would like to write a driver which will implement some behaviour when a network packet is received by the computer, before windows does what it does with the packet, i'd like to take this data and output it to the console of a C or C++ program.
Lets assume I have a C/C++ program written, which has a console. How does the C/C++ program interact with the driver I wrote which is hooking the network activity? Is it simply some C code which calls my drivers, the function returns the data as an object and then I can use that object to display in the console?
Thank you in advance for any possible replies
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要驱动程序来执行此任务。使用数据包嗅探器库,如 PCap (实际上你需要 WinPCap)。捕获数据包并将其打印到控制台非常简单。
另一种方法是原始套接字。但桌面 Windows(与 Windows Server 相反)限制原始套接字功能。
You don't need a driver for this task. Use packet sniffer library like PCap (actually you'll need WinPCap). It's really simple to capture packets and print them to console.
Alternative way is raw socket. But desktop Windows (as opposite to Windows Server) limits raw socket functionality.
如果您确实需要驱动程序,或者需要在数据包到达 Windows 网络堆栈之前对其进行操作或过滤,则需要研究过滤器驱动程序。
然后,该过滤器驱动程序可以公开一个设备文件,用户空间应用程序可以在该文件上读/写。 Windows DDK 包含示例。
If you really want a driver, or have a requirement to manipulate or filter packets before they hit the windows network stack you need to look into filter drivers.
This filter driver can then expose a device file on which your user space application can then read/write. The windows DDK contains examples.