Package org.jnetpcap.packet.format

Examples of org.jnetpcap.packet.format.TextFormatter


        (byte) 0x08, });

    JScanner scanner = new JScanner();
    scanner.scan(packet, Ethernet.ID);

    TextFormatter out = new TextFormatter();
    out.format(packet);
  }
View Full Code Here


    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();
View Full Code Here

    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 JBufferHandler<String>() {
      int i = 0;

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

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

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

        packet.peer(buffer);

        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();
View Full Code Here

  public void testScanFileJPHandler() throws IOException {
    StringBuilder errbuf = new StringBuilder();
    final Pcap pcap = Pcap.openOffline("tests/test-vlan.pcap", errbuf);

    // long start = System.currentTimeMillis();
    @SuppressWarnings("unused")
    final TextFormatter out = new TextFormatter();
    @SuppressWarnings("unused")
    final JScanner scanner = new JScanner();

    pcap.loop(Pcap.LOOP_INFINATE, JProtocol.ETHERNET_ID,
        new JPacketHandler<String>() {
View Full Code Here

    assertTrue(packet.hasHeader(IEEE802dot1q.ID, 0));
    assertTrue(packet.hasHeader(Ip4.ID));
    assertTrue(packet.hasHeader(icmp));
    assertTrue(icmp.hasSubHeader(echo));

    @SuppressWarnings("unused")
    TextFormatter out = new TextFormatter();
//    out.format(echo, Detail.MULTI_LINE_FULL_DETAIL);

    assertEquals(0, icmp.type());
    assertEquals(0, icmp.code());
    assertEquals(0x18FD, icmp.checksum());
View Full Code Here

    Ip4.RecordRoute record = new Ip4.RecordRoute();

    JPacket packet =
        TestUtils.getPcapPacket("tests/test-icmp-recordroute-opt.pcap", 0);

    JFormatter out = new TextFormatter();
    out.format(packet);
   
    assertNotNull(packet);
    assertTrue(packet.hasHeader(ip));
    assertTrue(ip.hasSubHeaders());
    assertFalse(ip.hasSubHeader(lsroute));
View Full Code Here

  public void test1() throws IOException {
    JPacket packet =
        TestUtils.getPcapPacket("tests/test-icmp-recordroute-opt.pcap", 0);
    assertNotNull(packet);

    TextFormatter out = new TextFormatter(System.out);
    out.format(packet);

    System.out.println(packet.toString());

    System.out.println(packet.getState().toHexdump());
    System.out.println(packet.getState().toDebugString());
View Full Code Here

    JPacket packet = TestUtils.getPcapPacket("tests/test-afs.pcap", 0);

    if (packet.hasHeader(JProtocol.IP4_ID)) {
      ip = packet.getHeader(ip);
      JFormatter out = new TextFormatter(System.out);
      out.format(ip, Detail.MULTI_LINE_FULL_DETAIL);
    }

  }
View Full Code Here

   *
   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  public void testScanIpv6File() throws IOException {
    TextFormatter out = new TextFormatter(OUT);
    out.setResolveAddresses(false);

    int i = 0;
    Ethernet eth = new Ethernet();
    for (PcapPacket packet : TestUtils.getIterable("tests/test-ipv6.pcap")) {

      System.out.println(packet.toDebugString());
      if (packet.hasHeader(eth)) {
        out.format(eth);
      }

      out.setFrameIndex(i++);
      out.format(packet);
    }
  }
View Full Code Here

   *
   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  public void testHttpFormattingWithResolveAddressDisabled() throws IOException {
    JFormatter out = new TextFormatter(OUT);
    out.setResolveAddresses(false);

    PcapPacket packet = TestUtils.getPcapPacket("tests/test-http-jpeg.pcap", 5);

    Ip4 ip = new Ip4();
    Ethernet eth = new Ethernet();
    if (packet.hasHeader(eth)) {
      out.format(eth);
    }
    if (packet.hasHeader(ip)) {
      out.format(ip);
      out.format(ip);
    }

    out.format(packet);

    Html html = new Html();
    assertTrue("html header not found", packet.hasHeader(html));
    System.out.printf("link related tags=%s\n", Arrays.asList(html.links())
        .toString());
View Full Code Here

TOP

Related Classes of org.jnetpcap.packet.format.TextFormatter

Copyright © 2018 www.massapicom. 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.