ags
ags

Reputation: 21

How to overcome JpCap issue?

I have a program to capture network ip address using jpcap. But I getting this error

// Exception in thread "main" java.lang.UnsatisfiedLinkError: jpcap.JpcapCaptor.getDeviceList()[Ljpcap/NetworkInterface; at jpcap.JpcapCaptor.getDeviceList(Native Method) at example.Main.main(Main.java:25)//

My program

        package example;

        /**
         *
      * @author Administrator
      */
      import java.net.Inet4Address;
    import java.net.InetAddress;
   import java.util.Arrays;
  import java.io.IOException;
  import java.io.*;
  import java.util.Scanner;
 import jpcap.*;
 import jpcap.packet.*;

 public class Main{
public static void main(String[] args) throws IOException{

  //Obtain the list of network interfaces
 NetworkInterface[] devices = JpcapCaptor.getDeviceList();

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

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

   //NetworkInterface[] devices = JpcapCaptor.getDeviceList();
   int index =1; // set index of the interface that you want to open.

    //Open an interface with openDevice(NetworkInterface intrface, int snaplen,           boolean promics, int to_ms)
    final JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 65535, false, 20);









  //JpcapCaptor captor=JpcapCaptor.openDevice(device[1], 65535, false, 20);

  //call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture.
   //captor.processPacket(10,new PacketPrinter());
  //System.out.println(packet);
//captor.close();

      }
      }

Upvotes: 2

Views: 3173

Answers (2)

Andrew
Andrew

Reputation: 11

First you need to use the Java 32-bit version. Install it and then copy the jpcap dll into the bin folder. And copy the jpcap jar into the lib/ext folder.

If using Eclipse, make sure you define the settings for the installed JREs to point to the 32bit version and that your java project is using the workspace default. It should pick everything up automagically then.

Upvotes: 1

Jan Krakora
Jan Krakora

Reputation: 2610

As the javadoc says

Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

I would guess it can't find its native libraries. Do you have the jpcap.dll file available in one of specified by the PATH environment variable?

Upvotes: 0

Related Questions