gpt4 book ai didi

java - jpcap 在熟模式下发送数据包时出错

转载 作者:行者123 更新时间:2023-11-30 16:38:48 27 4
gpt4 key购买 nike

我想使用 jpcap 发送 UDP 数据包。

我的代码是:

    PcapNetworkInterface nif = Pcaps.getDevByName(args[0]); 
int snapLen = 65536;
PromiscuousMode mode = PromiscuousMode.NONPROMISCUOUS;
int timeout = 10000;
PcapHandle handle = nif.openLive(snapLen, mode, timeout);

UdpPort srcPort = new UdpPort((short)1002,"");
UdpPort dstPort = new UdpPort((short)2001, "");;
short length = (short)12;
short checksum = (short)0xABCD;



UnknownPacket.Builder unknownb = new UnknownPacket.Builder();
unknownb.rawData(new byte[] { (byte)0, (byte)1, (byte)2, (byte)3 });

UdpPacket.Builder b = new UdpPacket.Builder();
b.dstPort(dstPort)
.srcPort(srcPort)
.length(length)
.checksum(checksum)
.correctChecksumAtBuild(false)
.correctLengthAtBuild(false)
.payloadBuilder(unknownb);

EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
etherBuilder.dstAddr(MacAddress.getByName("FF:FF:FF:FF:FF:FF"))
.srcAddr(MacAddress.getByName("FF:FF:FF:FF:FF:FF"))
.type( EtherType.IPV4) //
.payloadBuilder(b)
.paddingAtBuild(true);


Packet p = etherBuilder.build();


int i=1;
while(true) {

handle.sendPacket(p);
System.out.println("send "+i);i++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {

}
}

执行后,我得到:

org.pcap4j.core.PcapNativeException:pcap_sendpacket() 中发生错误:Cook 模式不支持发送数据包 在 org.pcap4j.core.PcapHandle.sendPacket(PcapHandle.java:1242) 在 org.pcap4j.core.PcapHandle.sendPacket(PcapHandle.java:1212)

这是 C 实现的链接:

https://github.com/frgtn/rpcapd-linux/blob/master/libpcap/pcap-linux.c#L1091

最佳答案

我用过https://gist.github.com/austinmarton/1922600

或其他与 jpcap 一起工作的接口(interface)

关于java - jpcap 在熟模式下发送数据包时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47349371/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com