Package org.jnetpcap.protocol.network

Examples of org.jnetpcap.protocol.network.Icmp


    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) {

        if (packet.hasHeader(icmp) == false) {
          return;
        }

        // PcapPacket packet = new PcapPacket(header, buffer);

        long f = packet.getFrameNumber();
        assertTrue("#" + f, packet.hasHeader(ip));

        if (icmp.isChecksumValid() == false) {
          System.out.printf("#%d shouldbe=%x checksum=%x\n", f, icmp
              .calculateChecksum(), icmp.checksum());
        }

        assertTrue("#" + f, icmp.isChecksumValid());
      }

    }, null);
  }
View Full Code Here


      // System.out.printf("flags=%x\n", ip.getState().getFlags());
      assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (ip.getState()
          .getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
    }

    Icmp icmp = new Icmp();
    if (packet.hasHeader(icmp)) {
      // System.out.println(icmp);
      // System.out.printf("flags=%x\n", icmp.getState().getFlags());
      assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (icmp.getState()
          .getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
    }

  }
View Full Code Here

    Ip4 ip = new Ip4();
    if (packet.hasHeader(ip)) {
      assertTrue(ip.isFragmented());
    }

    Icmp icmp = new Icmp();
    if (packet.hasHeader(icmp)) {
      assertTrue(ip.isFragmented());
    }

  }
View Full Code Here

    System.out.println(packet.toHexdump(128, false, false, true));
    System.out.println(packet.getState().toDebugString());

    Ip4 ip = new Ip4();
    Icmp icmp = new Icmp(); // Need an instance so we can check on sub header
    Icmp.DestinationUnreachable unreach = new Icmp.DestinationUnreachable();

    assertTrue(packet.hasHeader(Ethernet.ID));
    assertTrue(packet.hasHeader(JProtocol.IP4_ID, 0));
    assertTrue(packet.hasHeader(icmp));
    assertTrue(icmp.hasSubHeader(IcmpType.DESTINATION_UNREACHABLE.getId()));
    assertTrue(icmp.hasSubHeader(unreach));
    assertTrue(packet.hasHeader(ip, 1));
    assertTrue(packet.hasHeader(Udp.ID));
    assertTrue(packet.hasHeader(Payload.ID));

    // Check specific values
    assertEquals(3, icmp.type());
    assertEquals(3, icmp.code());
    assertEquals(0x2731, icmp.checksum());
    assertEquals(0, unreach.reserved());

    assertEquals(0x8724, ip.checksum());
    assertEquals(440, ip.length());

    // Devil's advocate
    assertFalse(icmp.hasSubHeader(IcmpType.ECHO_REPLY.getId()));
    assertFalse(icmp.hasSubHeader(IcmpType.PARAM_PROBLEM.getId()));

  }
View Full Code Here

    // Wireshark packet # 58 (1-based)
    PcapPacket packet = TestUtils.getPcapPacket("tests/test-vlan.pcap", 58 - 1);

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

    Icmp icmp = new Icmp(); // Need an instance so we can check on sub header
    Icmp.EchoRequest echo = new Icmp.EchoRequest();

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

    assertEquals(8, icmp.type());
    assertEquals(0, icmp.code());
    assertEquals(0x10FD, icmp.checksum());

    assertEquals(0xd001, echo.id());
    assertEquals(0x811e, echo.sequence());

    // Devil's advocate
    assertFalse(icmp.hasSubHeader(IcmpType.ECHO_REPLY.id));
    assertFalse(icmp.hasSubHeader(IcmpType.PARAM_PROBLEM.id));

  }
View Full Code Here

    // Wireshark packet # 59 (1-based)
    PcapPacket packet = TestUtils.getPcapPacket("tests/test-vlan.pcap", 59 - 1);

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

    Icmp icmp = new Icmp(); // Need an instance so we can check on sub header
    Icmp.EchoReply echo = new Icmp.EchoReply();

    assertTrue(packet.hasHeader(Ethernet.ID));
    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());

    assertEquals(0xd001, echo.id());
    assertEquals(0x811e, echo.sequence());

    // Devil's advocate
    assertTrue(icmp.hasSubHeader(IcmpType.ECHO_REPLY.id));
    assertFalse(icmp.hasSubHeader(IcmpType.ECHO_REQUEST.id));
    assertFalse(icmp.hasSubHeader(IcmpType.PARAM_PROBLEM.id));

  }
View Full Code Here

TOP

Related Classes of org.jnetpcap.protocol.network.Icmp

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.