All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pcap4j.sample.PcapFileMerger Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha.6
Show newest version
package org.pcap4j.sample;

import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PcapDumper;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.PcapNativeException;
import org.pcap4j.core.Pcaps;
import org.pcap4j.packet.Packet;

@SuppressWarnings("javadoc")
public class PcapFileMerger {

  private PcapFileMerger() {}

  public static void main(String[] args) throws PcapNativeException, NotOpenException {
    // args: pcap file list

    PcapDumper dumper = null;
    for (String pcapFile: args) {
      PcapHandle handle = Pcaps.openOffline(pcapFile);

      if (dumper == null) {
        dumper = handle.dumpOpen(PcapFileMerger.class.getSimpleName() + ".pcap");
      }

      Packet packet;
      while ((packet = handle.getNextPacket()) != null) {
        dumper.dump(packet, handle.getTimestamp());
      }

      handle.close();
    }

    if (dumper != null) {
      dumper.close();
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy