Examples of Pcap


Examples of org.jnetpcap.Pcap

  public void close() throws IOException {

//    System.out.println("jNetPcapCapture:close()");

    for (int i = 0; i < pcaps.length; i++) {
      Pcap pcap = pcaps[i];
      if (pcap == null) {
        continue;
      }

      pcap.breakloop();
    }

    super.close();
  }
View Full Code Here

Examples of org.jnetpcap.Pcap

  private jNetPcapDevice(PcapIf device) throws IOException {
    this.device = device;
    StringBuilder errbuf = new StringBuilder();

    Pcap pcap = Pcap.openLive(device.getName(), 1024, 0, 0, errbuf);
    if (pcap == null) {
      throw new IOException(errbuf.toString());
    }

    this.dlt = pcap.datalink();

    pcap.close();

    id =
        ProtocolRegistry.getProtocolEntry(ProtocolRegistry.translate(
            PcapFile.class, dlt));
  }
View Full Code Here

Examples of org.jnetpcap.Pcap

  /**
   * Test ip4 cr c16 using handler.
   */
  public void testIp4CRC16UsingHandler() {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(TestUtils.L2TP, errbuf);

    assertNotNull(pcap);

    pcap.dispatch(Pcap.DISPATCH_BUFFER_FULL, JProtocol.ETHERNET_ID,
        new PcapPacketHandler<Pcap>() {
          Ip4 ip = new Ip4();

          int i = 0, j = 0;

View Full Code Here

Examples of org.jnetpcap.Pcap

   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  private List<PcapPacket> getPacketList(String file) throws IOException {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(file, errbuf);
    if (pcap == null) {
      throw new IOException(errbuf.toString());
    }

    final PcapPacketArrayList list =
        new PcapPacketArrayList((int) new File(file).length() / 100);

    pcap.loop(Pcap.LOOP_INFINATE, list, null);

    pcap.close();

    return list;
  }
View Full Code Here

Examples of org.jnetpcap.Pcap

   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  public void testIpChecksum() throws IOException {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(L2TP, errbuf);
    if (pcap == null) {
      throw new IOException(errbuf.toString());
    }

    assertTrue(pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<Pcap>() {
      Ip4 ip1 = new Ip4();

      Ip4 ip2 = new Ip4();

      int i = 0;

      public void nextPacket(PcapPacket p1, Pcap user) {
        i++;
        p1.getHeader(ip1);
        int c1 = ip1.calculateChecksum();

        PcapPacket p2 = new PcapPacket(p1);
        p2.getHeader(ip2);

        int c2 = ip2.calculateChecksum();

        if (c1 != c2) {
          System.out.printf("#%d crc_before=%x crc_after=%x\n", i, c1, c2);
          System.out.printf(
              "P1: %s\nheader1=%s\n\nstate1=%s\npacket1=%s\n\nip1=%s\n", p1
                  .toHexdump(), p1.getCaptureHeader().toDebugString(), p1
                  .getState().toDebugString(), p1.toDebugString(), ip1
                  .toDebugString());

          System.out.println("---------------------------");

          System.out.printf(
              "P2: %s\nheader2=%s\n\nstate2=%s\npacket2=%s\n\nip2=%s\n\n", p2
                  .toHexdump(), p2.getCaptureHeader().toDebugString(), p2
                  .getState().toDebugString(), p2.toDebugString(), ip2
                  .toDebugString());

          System.out.println("p1-p2.memory.diff=\n"
              + FormatUtils.hexdump(DataUtils.diff(p1, p2)));

          System.out.println("ip1-ip2.memory.diff=\n"
              + FormatUtils.hexdump(DataUtils.diff(ip1, ip2)));

          user.breakloop();
        }

        i++;
      }

    }, pcap) != -2);

    pcap.close();
  }
View Full Code Here

Examples of org.jnetpcap.Pcap

  /**
   * Test tcp ip4 cr c16 using handler.
   */
  public void testTcpIp4CRC16UsingHandler() {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(TestUtils.HTTP, errbuf);

    assertNotNull(errbuf.toString(), pcap);

    pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
      Ip4 ip = new Ip4();

      Tcp tcp = new Tcp();

      // public void nextPacket(PcapHeader header, JBuffer buffer, String user)
View Full Code Here

Examples of org.jnetpcap.Pcap

  /**
   * Test tcp ip6 cr c16 using handler.
   */
  public void testTcpIp6CRC16UsingHandler() {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(HTTP_IP6, errbuf);

    assertNotNull(errbuf.toString(), pcap);

    pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
      Ip6 ip = new Ip6();

      Tcp tcp = new Tcp();

      public void nextPacket(PcapPacket packet, String user) {
View Full Code Here

Examples of org.jnetpcap.Pcap

  /**
   * Test udp ip6 cr c16 using handler.
   */
  public void testUdpIp6CRC16UsingHandler() {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(HTTP_IP6, errbuf);

    assertNotNull(errbuf.toString(), pcap);

    pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
      Ip6 ip = new Ip6();

      Udp udp = new Udp();

      public void nextPacket(PcapPacket packet, String user) {
View Full Code Here

Examples of org.jnetpcap.Pcap

   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  public void _testScanFileBBHandler() throws IOException {
    StringBuilder errbuf = new StringBuilder();
    final Pcap pcap = Pcap.openOffline("tests/test-l2tp.pcap", errbuf);

    final JPacket packet = new PcapPacket(Type.POINTER);
    final JScanner scanner = new JScanner();

    long start = System.currentTimeMillis();
    final TextFormatter out = new TextFormatter();

    pcap.loop(Pcap.LOOP_INFINATE, new ByteBufferHandler<String>() {
      int i = 0;

      public void nextPacket(PcapHeader header, ByteBuffer buffer, String user) {

        if (i == 200) {
          pcap.breakloop();
          return;
        }

        System.out.println("\nPacket #" + i);

        try {
          packet.peer(buffer);
        } catch (PeeringException e) {
          e.printStackTrace();
        }

        scanner.scan(packet, JProtocol.ETHERNET_ID);
        // try {
        out.setFrameIndex(i++);
        // out.format(packet);
        // System.out.println(packet.toString());
        // } catch (IOException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }
      }

    }, "");

    long end = System.currentTimeMillis();

    System.out.printf("time=%d ms\n", (end - start));

    pcap.close();
  }
View Full Code Here

Examples of org.jnetpcap.Pcap

  /**
   * Test icmp cr c16 using handler.
   */
  public void testIcmpCRC16UsingHandler() {
    StringBuilder errbuf = new StringBuilder();
    Pcap pcap = Pcap.openOffline(TestTcpIp.VLAN, errbuf);

    assertNotNull(errbuf.toString(), pcap);

    pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
      Ip4 ip = new Ip4();

      Icmp icmp = new Icmp();

      public void nextPacket(PcapPacket packet, String user) {
View Full Code Here
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.