Using jnetPcap on android studio or eclipse step by step

1 reply [Last post]
parp
Offline
Joined: 11/15/2016

Hi dear friends ,I am a biginer at jnetPcap on android , I have a big chalange to use jnetPcat in android application.
First of all I have a question,Can I use jnetPcap for making a packet and send to over of network(2nd layer)?
If I can , How do I careate packet with jnetpcap on android? My IDE is android studio.
I downloaded jnetpcap-1.3.0-1.win64.zip on this site after extarcted this file , I add jnetpcap.jar to my android application after that I can call all the classes,but when I want run my app I faced to an error.
My sample code is :

public class PcapAndroidActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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 some permissions on manifest.xml file on my project :

"android.permission.INTERNET"
"android.permission.ACCESS_NETWORK_STATE"
"android.permission.ACCESS_WIFI_STATE"
"android.permission.ACCESS_COARSE_LOCATION"
"android.permission.CHANGE_NETWORK_STATE"
"android.permission.CHANGE_WIFI_MULTICAST_STATE"
"android.permission.CHANGE_WIFI_STATE"

after run this code I face with this error and I don't know how I can fix this problem.
error opening trace file: No such file or directory (2)
java.lang.ExceptionInInitializerError
FATAL EXCEPTION: main
at com.example.parp.PcapAndroidActivity.onCreate(PcapAndroidActivity.java:31)
the 31st lines is:==>JPacket wPacket = new JMemoryPacket(size);

and I don't have any idea that how i can fix this problem.
Is there any video about this?

parp
Offline
Joined: 11/15/2016
fix problem

Is there any one here that can help me? Sad
please help me , this if very important for me.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.