1

I want to create a packet and send to over network(2nd layer of network) in android application I use android studio.I download jnetpcap-1.3.0 file , this file include some file such as jnetPcap.jar , I add this jar file to my android project,Is it right or not? at this step I can call some classes in the jar file(jnetpcap.jar) but when I want run this android application I have an error and I don't know how I can solve this problem. I asign some permission to android appliaton, such as permission is :

<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" />

My code is:

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();
}

and I have this error that shows on logcat on androis studio :

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)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:107 at
how can I solve this problem?

jack
  • 51
  • 7

1 Answers1

1

Check your Gradle files to see if you have included all required dependencies. For packet manipulation, you may want to check on mvn repo details.

Lunodzo
  • 11
  • 5