Re: [jnetpcap-users] JBufferHandler and loopInBackground
A java PCAP and DPI library
Brought to you by:
voytechs
From: Kamran Y. <kam...@gm...> - 2013-04-08 04:13:41
|
Thanks Maor. I have actually implemented this use Thread itself but since it provides the facility I thought of using it but if I do not find any solution I will stick to my thread. On Sun, Apr 7, 2013 at 12:45 PM, Maor Bril <mao...@gm...> wrote: > Just a thought, why not use a daemon thread for that. Let it block, but > only that thread. > On Apr 7, 2013 10:10 AM, "Kamran Yadav" <kam...@gm...> wrote: > >> I am planning to use jnetpcap-1.3 to sniff packets on the machine. My >> requirement is to sniff all packets and store some meta-data about each >> packet in the database for further processing. >> >> I picked up the Classic example which works. I want to loop in background >> so using PcapUtils.loopInBackground and since it uses JBufferHandler, I >> provided one but it never enters the nextPacket method. >> >> My commented code works but since the pcap.loop() method is a blocking >> method it does not suit my requirement as I am listening on all the devices >> of the machine. >> >> public static void main(final String[] args) throws InterruptedException { >> List alldevs = new ArrayList(); >> StringBuilder errbuf = new StringBuilder(); >> >> int findStatus = Pcap.findAllDevs(alldevs, errbuf); >> for (PcapIf device : alldevs) { >> Pcap pcap = Pcap.openLive(device.getName(), 64 * 1024, Pcap.MODE_PROMISCUOUS, 10000, errbuf); >> >> /**PcapPacketHandler jpacketHandler = new PcapPacketHandler() { >> public void nextPacket(final PcapPacket packet, final String message) { >> System.out.println("reached here"); >> } >> }; >> pcap.loop(-1, jpacketHandler, null);*/ >> >> JBufferHandler jBufferHandler = new JBufferHandler() { >> public void nextPacket(final PcapHeader header, final JBuffer buffer, final String message) { >> System.out.println("reached here"); >> } >> }; >> >> PcapUtils.loopInBackground(pcap, -1, jBufferHandler, null); >> } >> } >> >> >> >> ------------------------------------------------------------------------------ >> Minimize network downtime and maximize team effectiveness. >> Reduce network management and security costs.Learn how to hire >> the most talented Cisco Certified professionals. Visit the >> Employer Resources Portal >> http://www.cisco.com/web/learning/employer_resources/index.html >> _______________________________________________ >> jnetpcap-users mailing list >> jne...@li... >> https://lists.sourceforge.net/lists/listinfo/jnetpcap-users >> >> |