我正在尝试运行此代码,该代码仅将字节的 HexString 转换为字节数组,并尝试从该数组创建 PcapPacket:
import org.jnetpcap.packet.PcapPacket;
public class PcapTest {
public static void main(String[] args) {
PcapPacket packet= new PcapPacket(hexStringToByteArray("08002760f9b952540012350208004500008f6ee600004006ab16d5f87e650a00020f15b3d192006546b55996b53d5018fffffe0c00000dcd6405003156656e6420efbfbc206d7020766f73206f66667265206a65207661697320646f646f2064616e732032206d696e7574657354cf1d3400087a376b706d7338700059006500084968656273657468050cf0a100013fcc07000100467c3c99e2ac5401"));//tcp Packet from wireshark
}
//this function is jute for completeness of the example
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
//System.out.println(Integer.toHexString(data[i / 2]));
}
return data;
}
}
我收到以下错误:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Invalid [16,3696,3680) range.
at org.jnetpcap.nio.JMemory.peer(Unknown Source)
at org.jnetpcap.packet.JPacket$State.peerTo(Unknown Source)
at org.jnetpcap.packet.PcapPacket.peerStateAndData(Unknown Source)
at org.jnetpcap.packet.PcapPacket.transferStateAndDataFrom(Unknown Source)
at org.jnetpcap.packet.PcapPacket.<init>(Unknown Source)
at jNetPcapTest.JNetPcapTest.main(JNetPcapTest.java:12)
我检查了它似乎运行良好的功能,我也在使用具有root权限的eclipse(在ubuntu上)。
要在 Eclipse 中添加库,我在 Eclipse 上创建了一个新的用户库,添加了 jar 和本机库位置(.so/.dll 所在的文件夹)
我在linux(ubuntu)和windows上都有同样的问题。谢谢你的帮助欢呼