如何在没有TCP/IP堆栈的情况下用Java发送以太网帧

use*_*889 8 java ethernet raw-ethernet

我的Java应用程序应该控制直接连接到我的计算机网络接口(Ubuntu和Windows)的外部设备(EtherCAT总线技术).没有连接其他网络设备.通信已在标准IEEE 802.3以太网帧上完成,没有IP堆栈.

发送数据的示例:

int etherType =  0x88A4;  // the EtherType registered by IEEE
byte[] macBroadcast = new byte[] {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
byte[] macSource = new byte[] ... ;  // MAC Address of my network interface card
byte[] buffer = ... // the data to send

device.write(macSource, macBroadcast, etherType, buffer);
Run Code Online (Sandbox Code Playgroud)

我尝试了使用pcap本机库的JNetPcap.给定的API很好,但是在重载时存在多线程问题,这迫使我放弃.

netty.io也是候选人.我不确定,但TCP/IP堆栈是强制性的.我对吗?

是否有其他想法与低级别以太网帧通信?我更喜欢像netty.io这样的纯java库,如果存在的话.

当然JNA/JNI也是一种选择.但我不想写C代码.

其他选择?

Ste*_*n C 3

这些是我能够找到的选项:

我还看到过一些评论,大意是 jNetPcap 应该是线程安全的,但实际上并非如此;即,当与多个线程一起使用时,它是有问题的。