简体   繁体   English

有没有一种方法可以在Windows上使用Winsock在链接上直接发送以太网数据包?

[英]Is there a way send ethernet packet directly on link using winsock on windows?

Is there a way send ethernet packet directly on link using winsock on windows? 有没有一种方法可以在Windows上使用Winsock在链接上直接发送以太网数据包?

I need to broadcast an ethernet packet on a link (ie Destination Mac-Address: Broadcast (ff:ff:ff:ff:ff:ff)) 我需要在链接上广播以太网数据包(即目标Mac地址:广播​​(ff:ff:ff:ff:ff:ff:ff))

It is not possible to directly access ethernet links. 无法直接访问以太网链接。 That is a hardware layer that is protected by Windows. 那是Windows保护的硬件层。 To send data out on a specific ethernet adapter, you need to bind() a socket to that adapter's IP address, then you can send() or sendto() your data to a destination IP as needed. 要在特定的以太网适配器上发送数据,您需要bind()套接字bind()到该适配器的IP地址,然后可以根据需要将数据send()sendto()到目标IP。

To broadcast a packet, send the data to the bound adapter's subnet broadcast IP address, which you can calculate dynamically by using GetAdaptersInfo() or GetIpAddrTable() to retrieve the adapter's IP address and subnet mask and then OR/AND'ing them together: 要广播数据包,请将数据发送到绑定适配器的子网广播IP地址,您可以使用GetAdaptersInfo()GetIpAddrTable()来动态计算该数据,以检索适配器的IP地址和子网掩码,然后将它们进行OR / AND处理。

BroadcastIP = (IPAddress & SubnetMask) | ~SubnetMask;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM