Step 2 - setup the main class

We are going to setup the main class as the packet handler as well. All it needs to do is implement the PcapPacketHandler interface. We are also going to use a static main method that will setup the libpcap portion and register our application as listener to libpcap packets.

public class IpReassemblyExample implements PcapPacketHandler {

  public static void main(String[] args) {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline("tests/test-ipreassembly2.pcap", errbuf);
    if (pcap == null) {

      6, // Collect 6 packets
      new IpReassemblyExample(
        5 * 1000, // 5 second timeout for reassembly buffer
        new IpReassemblyBufferHandler() {/*Omitted for now */}),

Here we are using the static main method as a start for our application. We open up a capture file and enter a dispatch loop. We're only collecting 6 packets and we are registering out application as the PcapPacketHandler. Our constructor takes a IpReassemblyBufferHandler that will be notified with reassembled buffers. We create an anonymous class for that since we only do very minor work in its handler callback method.