Skip to main content

Jxnet: Capturing The Packets Without Callback



package com.ardikars.test.jxnet;

import java.nio.ByteBuffer;

import com.ardikars.jxnet.Jxnet;
import com.ardikars.jxnet.Pcap;
import com.ardikars.jxnet.PcapPktHdr;

public class CapturingThePacketsWithoutCallback {

 public static void main(String[] args) {
  
  StringBuilder errbuf = new StringBuilder();
  String source = Jxnet.pcapLookupdev(errbuf);
  if(source == null) {
   System.err.println(errbuf.toString());
   return;
  }
  Pcap pcap = Jxnet.pcapOpenLive(source, 65535, 1, 2000, errbuf);
  if(pcap == null) {
   System.err.println(errbuf.toString());
   return;
  }
  
  ByteBuffer b = null;
  PcapPktHdr h = new PcapPktHdr();
  for(int i=0; i<10; i++) {
   b = Jxnet.pcapNext(pcap, h);
   System.out.println(h);
   System.out.println(b);
  }
  Jxnet.pcapClose(pcap);
 }

}


Comments