Package org.pcap4j.sample

Source Code of org.pcap4j.sample.PcapFileMerger

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 {

  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.getTimestampInts(), handle.getTimestampMicros()
        );
      }

      handle.close();
    }

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

  }

}
TOP

Related Classes of org.pcap4j.sample.PcapFileMerger

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.