1

so I have two Projects that run fine. But when I try to put them together I get the error at the bottom immediately.

Separate files (first two belong together): File1 :

package pkg2buttongui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 *
 * @author root
 */
public class TestJavaHttpsDecrypt{

    private JFrame frame;
    private JTextField input;
    private JButton startButton;
    private JButton stopButton;

    public void go(){
        final CaptureNetTraffic cnt = new CaptureNetTraffic();
        frame = new JFrame("CaptureControl");
        frame.setLayout(new GridLayout(3,1));

        input = new JTextField("enter NIC");
        startButton = new JButton("start");
        stopButton = new JButton("stop");

        startButton.addActionListener(
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    cnt.run(input.getText());
                }
            }
        );
        stopButton.addActionListener(
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    cnt.stopCap();
                }
            }
        );

        frame.add(input);
        frame.add(startButton);
        frame.add(stopButton);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(800,500,100,150);
        frame.setVisible(true);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        new TestJavaHttpsDecrypt().go();
    }

}

File2:

package pkg2buttongui;

import javax.swing.SwingWorker;

/**
 *
 * @author root
 */
public class CaptureNetTraffic extends Thread{

    int i = 0;

    private String text = null;
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            while(true){
                System.out.println(text);
                Thread.sleep(1);
                i++;
            }
        }
    };

    public void stopCap(){
        //Thread.interrupted();
        worker.cancel(true);
        System.out.println("stopping capture at " + i);
    }

    public void run(final String var){
        text = var;
        worker.execute();
    }
}

Second Project:

    import java.io.File;  
    import java.io.FileNotFoundException;
    import org.jnetpcap.Pcap;  
    import org.jnetpcap.PcapDumper;  


    public class PcapDumperExample {  
      public static void main(String[] args) throws FileNotFoundException {  
        StringBuilder errbuf = new StringBuilder();     // For any error msgs  

        /*************************************************************************** 
         * open up the selected device 
         **************************************************************************/  
        int snaplen = 64 * 1024;           // Capture all packets, no trucation  
        int flags = Pcap.MODE_PROMISCUOUS; // capture all packets  
        int timeout = 10;           // 10 seconds in millis  
        Pcap pcap = Pcap.openLive("eth1", snaplen, flags, timeout, errbuf);  
        if (pcap == null) {  
          System.err.printf("Error while opening device for capture: %s\n",   
            errbuf.toString());  
          return;  
        }  

        /*************************************************************************** 
         * create a PcapDumper and associate it with the pcap capture 
         ***************************************************************************/  
        String ofile = "mycap.cap";  
        PcapDumper dumper = pcap.dumpOpen(ofile); // output file  

        /*************************************************************************** 
         * enter the loop and tell it to capture 10 packets. We pass 
         * in the dumper created in step 3 
         **************************************************************************/  
        pcap.loop(100, dumper);  

        File file = new File(ofile);  
        System.out.printf("%s file has %d bytes in it!\n", ofile, file.length());


        /*************************************************************************** 
         * Last thing to do is close the dumper and pcap handles 
         **************************************************************************/  
        dumper.close(); 
        pcap.close();  
        }  
      }  
    }  

Now here I tried to put them together so I can control the duration of the capture. for that I'll put loop.infinite in the pcap.loop instead of the 100. And will use the following file with file1:

package testjavahttpsdecrypt;

import java.io.File;
import javax.swing.SwingWorker;

import static org.jnetpcap.Pcap.LOOP_INFINITE;

import org.jnetpcap.Pcap;  
import org.jnetpcap.PcapDumper;

/**
 *
 * @author root
 */
public class CaptureNetTraffic extends Thread {

    int i = 0;    
    private String text = null;
    Pcap pcap = new Pcap();
    PcapDumper dumper = new PcapDumper();
    String ofile = "meins.cap";  
    StringBuilder errbuf = new StringBuilder();
    int snaplen = 64 * 1024;           // Capture all packets, no trucation  
    int flags = Pcap.MODE_PROMISCUOUS; // capture all packets  
    int timeout = 10000;           // 10 seconds in millis  


    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            while(true){
                pcap = Pcap.openLive(text, snaplen, flags, timeout, errbuf);  
                if (pcap == null) {  
                  System.err.printf("Error while opening device for capture: %s\n",   
                    errbuf.toString());  
                  return null;  
                }
                dumper = pcap.dumpOpen(ofile);

                pcap.loop(100, dumper);                  
            }
        }
    };

    public void stopCap(){
        File file = new File(ofile);  
        System.out.printf("%s file has %d bytes in it!\n", ofile, file.length());
        dumper.close();
        pcap.close();
        //Thread.interrupted();
        worker.cancel(true);
        System.out.println("stopping capture at " + i);
    }

    public void run(final String var){
        text = var;
        worker.execute();
    }
}

Now when I run file1 i get this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J
    at com.slytechs.library.NativeLibrary.dlopen(Native Method)
    at com.slytechs.library.NativeLibrary.<init>(Unknown Source)
    at com.slytechs.library.JNILibrary.<init>(Unknown Source)
    at com.slytechs.library.JNILibrary.loadLibrary(Unknown Source)
    at com.slytechs.library.JNILibrary.register(Unknown Source)
    at com.slytechs.library.JNILibrary.register(Unknown Source)
    at com.slytechs.library.JNILibrary.register(Unknown Source)
    at org.jnetpcap.Pcap.<clinit>(Unknown Source)
    at testjavahttpsdecrypt.CaptureNetTraffic.<init>(CaptureNetTraffic.java:24)
    at testjavahttpsdecrypt.TestJavaHttpsDecrypt.go(TestJavaHttpsDecrypt.java:23)
    at testjavahttpsdecrypt.TestJavaHttpsDecrypt.main(TestJavaHttpsDecrypt.java:62)

since the second project runs correctly on its own, I believe that I have setup the library correctly (thats a hint from one post here at stackoverflow) I appreciate every hint/help with this matter.

0 Answers0