コード例 #1
0
ファイル: TestPcapBetaJNI.java プロジェクト: basxeon/oins-11
  /** SKI ptest dumper. */
  public void SKIPtestDumper() {

    gen.start(); // Generate network traffic - async method

    System.out.printf("tmpFile=%s\n", tmpFile.getAbsoluteFile());

    Pcap pcap = Pcap.openLive(device, snaplen, promisc, oneSecond, errbuf);
    assertNotNull(errbuf.toString(), pcap);

    PcapDumper dumper = pcap.dumpOpen(tmpFile.getAbsolutePath());
    assertNotNull(pcap.getErr(), dumper);

    PcapHandler<PcapDumper> dumpHandler =
        new PcapHandler<PcapDumper>() {

          public void nextPacket(
              PcapDumper dumper,
              long seconds,
              int useconds,
              int caplen,
              int len,
              ByteBuffer buffer) {

            dumper.dump(seconds, useconds, caplen, len, buffer);
          }
        };

    pcap.loop(10, dumpHandler, dumper);

    assertTrue("Empty dump file " + tmpFile.getAbsolutePath(), tmpFile.length() > 0);

    // System.out.printf("Temp dumpfile size=%s\n", tmpFile.length());
    pcap.close();
  }
コード例 #2
0
ファイル: TestPcapBetaJNI.java プロジェクト: basxeon/oins-11
  /** Test pcap dumper using dispatch. */
  public void testPcapDumperUsingDispatch() {

    Pcap pcap = Pcap.openOffline(fname, errbuf);
    assertNotNull(errbuf.toString(), pcap);

    PcapDumper dumper = pcap.dumpOpen(tmpFile.getPath());
    assertNotNull(pcap.getErr(), dumper);

    PcapHandler<PcapDumper> handler =
        new PcapHandler<PcapDumper>() {

          public void nextPacket(
              PcapDumper dumper,
              long seconds,
              int useconds,
              int caplen,
              int len,
              ByteBuffer buffer) {

            dumper.dump(seconds, useconds, caplen, len, buffer);
          }
        };

    /*
     * Our test file is small, about 24K bytes in size, should fit inside a
     * buffer full.
     */
    int r = pcap.dispatch(Pcap.DISPATCH_BUFFER_FULL, handler, dumper);
    assertTrue("Something happened in dispatch", r == Pcap.OK);

    dumper.close();
    pcap.close();

    // System.out.printf("%s: tmp=%d, source=%d\n", tmpFile.getName(), tmpFile
    // .length(), new File(fname).length());
    //
    assertEquals(
        "dumped file and source file lengths don't match",
        tmpFile.length(),
        new File(fname).length());
  }
コード例 #3
0
ファイル: TestPcapBetaJNI.java プロジェクト: basxeon/oins-11
  /** Test pcap dumper using loop. */
  public void testPcapDumperUsingLoop() {

    Pcap pcap = Pcap.openOffline(fname, errbuf);
    assertNotNull(errbuf.toString(), pcap);

    PcapDumper dumper = pcap.dumpOpen(tmpFile.getPath());
    assertNotNull(pcap.getErr(), dumper);

    PcapHandler<PcapDumper> handler =
        new PcapHandler<PcapDumper>() {

          public void nextPacket(
              PcapDumper dumper,
              long seconds,
              int useconds,
              int caplen,
              int len,
              ByteBuffer buffer) {

            dumper.dump(seconds, useconds, caplen, len, buffer);
          }
        };

    int r = pcap.loop(Pcap.LOOP_INFINATE, handler, dumper);
    assertTrue("Something happened in the loop", r == Pcap.OK);

    dumper.close();
    pcap.close();

    // System.out.printf("%s: tmp=%d, source=%d\n", tmpFile.getName(), tmpFile
    // .length(), new File(fname).length());
    //
    assertEquals(
        "dumped file and source file lengths don't match",
        tmpFile.length(),
        new File(fname).length());
  }