无法在 WiFi 网络中使用 jpcap 接收数据包

Unable to receive packet using jpcap in WiFi network

我想在 WiFi 网络中发送和接收数据包。 使用以下代码

发送数据包。

int id = Integer.parseInt(text_device.getText().trim());
JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[id], 65535, true, 20);
JpcapSender sender = jpcap.getJpcapSenderInstance();
TCPPacket packet = new TCPPacket(210, 210, 0l, 12l, true, true, true, true, true, true, true, true, 1, 2);
packet.setIPv4Parameter(0, true, true, true, 0, true, true, true, 0, 1010101, 100, IPPacket.IPPROTO_TCP, InetAddress.getLocalHost(), InetAddress.getByName(text_ip.getText().trim()));
packet.data = "Sample Data".getBytes();
Date date = new Date();
packet.usec = date.getTime();
packet.sec = date.getTime();
EthernetPacket ether = new EthernetPacket();
ether.src_mac = new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1};
ether.dst_mac = new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255};
ether.frametype = EthernetPacket.ETHERTYPE_IP;
packet.datalink = ether;
sender.sendPacket(packet);

为了接收数据包,我将这段代码写在public void receivePacket(Packet packet)

TCPPacket tcp = (TCPPacket) packet;
String src = tcp.src_ip.getHostAddress();
int src_port = tcp.src_port;
String dst = tcp.dst_ip.getHostAddress();
int dst_port = tcp.dst_port;
String data = new String(tcp.data);
System.out.println("" + data + "");

当我用LAN连接两台机器时可以,但是当我用WiFi连接时无法接收数据包。

谁能告诉我,怎么了??

我怀疑答案与 JPCAP FAQ 中的这句话有关:

Q: Can I capture packets from a WiFi (802.11) network interface?

The answer depends on what Operating System you are running and which WiFi devices your system has. On Windows, you may not be able to capture packets from some WiFi devices. Linux or BSD may have higher probability of supporting packet capturing using WiFi devices.

如果您分享您准确的适配器类型和 windows 版本详细信息,您可能会在 Google discussion group for JPcap 上取得更好的成功。