小编use*_*889的帖子

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

我的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代码.

其他选择?

java ethernet raw-ethernet

8
推荐指数
1
解决办法
7620
查看次数

标签 统计

ethernet ×1

java ×1

raw-ethernet ×1