我想创建一个数据包并发送到网络(第二层网络)在android应用程序中我使用android studio.I下载jnetpcap-1.3.0文件,这个文件包含一些文件,如jnetPcap.jar,我添加这个jar文件到我的android项目,是不是? 在这一步我可以调用jar文件中的一些类(jnetpcap.jar),但是当我想运行这个android应用程序时,我有一个错误,我不知道如何解决这个问题。 我对android appliaton有一些许可,比如权限是:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission zndroid:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
我的代码是:
int size=100;
Ethernet wEth;
byte[] sourceMac={};
byte[] destMac={};
Ip4 wIp4;
byte[] bytes={};
byte[] dIP={};
byte[] sIP={};
try {
Process p = Runtime.getRuntime().exec("su");
JPacket wPacket = new JMemoryPacket(size);
wPacket.order(ByteOrder.BIG_ENDIAN);
wPacket.setUShort(12, 0x0800);
wPacket.scan(JProtocol.ETHERNET_ID);
wEth = wPacket.getHeader(new Ethernet());
wEth.source(sourceMac);
wEth.destination(destMac);
wEth.checksum(wEth.calculateChecksum());
int headersize = 14;
wPacket.setUByte(14, 0x40 | 0x05);
wPacket.scan(JProtocol.ETHERNET_ID);
wIp4 = wPacket.getHeader(new Ip4());
wIp4.length(500 - wEth.size());
wIp4.source(dIP);
wIp4.destination(sIP);
wIp4.ttl(32);
wIp4.flags(0);
wIp4.offset(0);
wIp4.checksum(wIp4.calculateChecksum());
headersize += 20;
}catch (Exception ex)
{
ex.printStackTrace();
}
我在androis studio上的logcat上显示此错误:
1. 11-15 14:03:42.084 2996-2996/com.example.saeed.monoq E/Trace: error
opening trace file: No such file or directory (2) 11-15 14:03:42.814
2996-2996/com.example.saeed.monoq E/dalvikvm: Could not find class
'android.util.ArrayMap', referenced from method
com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
11-15 14:03:42.844 2996-2996/com.example.saeed.monoq E/dalvikvm:
Could not find class 'android.util.ArrayMap', referenced from method
com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache 11-15
14:03:44.884 2996-2996/com.example.saeed.monoq E/AndroidRuntime:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at
com.example.saeed.monoq.MainActivity.onCreate(MainActivity.java:69)
at android.app.Activity.performCreate(Activity.java:5008)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:107 at
我该如何解决这个问题?