2
Error is :Exception in thread "main" java.lang.UnsatisfiedLinkError: 
  jpcap.JpcapCaptor.getDeviceList()[Ljpcap/NetworkInterface;  at  
  jpcap.JpcapCaptor.getDeviceList(Native Method)  at 
  jcap.network.main(network.java:63)

import jpcap.*;
import jpcap.packet.*;
import java.io.*;
import jpcap.packet.TCPPacket.*;
import java.io.*;
import jpcap.JpcapCaptor.*;


class Network implements PacketReceiver {
    System.out.println(System.getProperty("java.library.path"));
    String sp=null;
    String dp=null;
    String window=null;
    String sequence=null;
    String acknowledge=null;
    FileWriter ff=null;
    String da=null;

    public void receivePacket(Packet pt) {
        try {
            if(pt instanceof TCPPacket) {
                TCPPacket tp=(TCPPacket)pt;
                ff=new FileWriter("da.txt",true);
                sp=new Integer(tp.src_port).toString();
                dp=new Integer(tp.dst_port).toString();
                window=new Integer(tp.window).toString();
                sequence=new Long(tp.sequence).toString();
                acknowledge=new Long(tp.ack_num).toString();
                byte[]dat=tp.data;
                da=new String(dat);
                ff.write("\r\n Source port is :-"+sp);    
                ff.write("\r\n Desination port is:-"+dp);
                ff.write("\r\n Sequence no is:-"+sequence);
                ff.write("\r\n Acknowledgement no  is:-"+acknowledge);
                ff.write("\r\n Status of rsv1 flag is:-"+tp.rsv1);
                ff.write("\r\n Status of rsv2 flag is:-"+tp.rsv2);
                ff.write("\r\n Status of Syn flag is:-"+tp.syn);
                ff.write("\r\n Status of Urg flag is:-"+tp.urg);
                ff.write("\r\n Status of Fin flag is:-"+tp.fin);
                ff.write("\r\n Data :-"+da);
                ff.write("\r\n");
                ff.write("\r\n");
                ff.close();
            }                 
        } catch(Exception e) {
            System.out.println(e.getMessage());
        }
   }  

   public static void main(String args[])throws IOException {
        int i;        
        try {
            NetworkInterface[] devices = JpcapCaptor.getDeviceList();

            //for each network interface
            for (i = 0; i < devices.length; i++) {
                //print out its name and description
                System.out.println(i+": "+devices[i].name + "(" +    
                        devices[i].description+")"+devices[i].loopback);
                //print out its datalink name and description
                System.out.println(" datalink: "+devices[i].datalink_name + "(" 
                        + devices[i].datalink_description+")");

                //print out its MAC address
                System.out.print(" MAC address:");
                for (byte b : devices[i].mac_address)
                    System.out.print(Integer.toHexString(b&0xff) + ":");
                System.out.println();

                //print out its IP address, subnet mask and broadcast address
                for (NetworkInterfaceAddress a : devices[i].addresses)
                    System.out.println(" address:"+a.address + " " + a.subnet + " "+ 
                            a.broadcast);
            }
            JpcapCaptor captor=JpcapCaptor.openDevice(devices[0], 65535, true, 20);
            captor.loopPacket(-1,new Network());
            captor.close();
        }
        catch(Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
5
  • 1
    Must be because your code isn't quite well indented.
    – Francis P
    Feb 22, 2013 at 16:25
  • 1
    Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. Feb 22, 2013 at 16:25
  • also, try to catch more specific exceptions, never catch (Exception e)
    – El Hocko
    Feb 22, 2013 at 16:26
  • 2
    I don't feel like counting which line is the 63rd. Maybe you could help Ram Sharma?
    – Francis P
    Feb 22, 2013 at 16:26
  • @FrancisP Oddly, according to TextPad, the 63rd line is //print out its datalink name and description. Go figure. Feb 22, 2013 at 16:28

4 Answers 4

4

UnsatisfiedLinkError means that the 'JpcapCaptor' native lib have not been loaded,

static{
      System.loadLibrary("JpcapCaptor.dll");
}
1
  • Francis P 63rd line is 'NetworkInterface[] devices = JpcapCaptor.getDeviceList(); '
    – Ram Sharma
    Feb 22, 2013 at 16:42
1

The javadocs for the UnsatisfiedLinkError are pretty straightforward. you are missing some required lib for jcap.

In the future, the javadocs are a great place to start when you get an exception you don't understand.

0
0

Install jpcap in your machine and then try to run your code. you can download jpcap.exe file from here http://jpcap.software.informer.com/0.7/

0

I had the same problem after full compilation and linking of Jpcap (using eclipse on a Mac OS X computer). Turns out there are two versions of Jpcap: https://github.com/jpcap/jpcap (no JpCaptor), and a version with JpCaptor: https://github.com/mgodave/Jpcap. Maybe this helps.

2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Zizouz212
    Nov 15, 2015 at 16:29
  • @Zizouz212 - this is not a link-only answer. It offers an explanation for teh problem, with the links as supporting evidence.
    – APC
    Nov 15, 2015 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.