[英]jPcap - send packet to selected MAC (not the selected interface)
我正在尝试使用jPcap
将以太网数据包发送到 jPcap
目标MAC地址 :
public void sendPacket(Packet packet, byte[] srcMac, byte[] dstMac, Interface i) throws IOException
{
JpcapSender sender = JpcapSender.openDevice(i.netInterface);
EthernetPacket ether = new EthernetPacket();
ether.frametype = EthernetPacket.ETHERTYPE_IP;
ether.src_mac = srcMac; // MAC address of selected interface
ether.dst_mac = dstMac; // MAC addr. choosed somwhere on form
packet.datalink = ether;
sender.sendPacket(packet);
sender.close();
}
它可以工作,但是总是发送到选定的接口,而不是dst_mac
!
所以我不明白所选接口和scr_mac
之间的关系:
interface
和scr_mac
)? dst_mac
? 为什么我必须同时选择两者(接口和scr_mac)?
该接口是软件用于通信(发送或接收数据包)的接口。 这通常是您的以太网卡。 您需要指定它,以便Jpcap知道如何发送信息。 src_mac地址是数据包头的一部分。 它旨在动态使用,以便在发送数据包时以适当的信息对其进行更新。 src_mac不一定在数据包发送方式中起作用。
为什么即使不使用它也必须添加dst_mac?
使用。 确保具有通过直接以太网连接链接到源的具有指定mac地址的另一台设备,并确保已准备好接收数据。 现在,我怀疑正在发生的事情是您正在尝试通过主机上的相同界面进行回读。
Jpcap的网站上有一些我认为有用的教程和示例。 我已经在Jpcap库上做了很多工作,如果您还有其他问题,我很乐意为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.