Package org.jnetpcap.protocol.network

Examples of org.jnetpcap.protocol.network.Ip4$Timestamp$Entry


    System.out.println(packet.toHexdump());
    packet.setUByte(14 + 9, 0x11); //UDP
    System.out.println(packet.toHexdump());
    packet.scan(JProtocol.ETHERNET_ID);
    Ethernet eth = packet.getHeader(new Ethernet());
    Ip4 ip = packet.getHeader(new Ip4());
    Udp udp = packet.getHeader(new Udp());
//    udp.transferFrom(getFakeData(1460)); //Generate Random bytes
    eth.destination(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 33});
    eth.source(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 34});
    ip.flags(0);
    ip.tos(0);
    ip.source(new byte[] {(byte) 192, (byte) 168, 18, (byte) 218});
    ip.setByteArray(16, new byte[] {(byte) 192,(byte) 168, 18, (byte) 219});
   
    ip.checksum(0);
    System.out.printf("crc=0x%X ip.len=%d\n", Checksum.inChecksum(ip, 0, ip.size()), ip.size());
    ip.checksum(Checksum.inChecksum(ip, 0, ip.size()));
    System.out.println(packet.getState().toDebugString());
   
    System.out.printf("crc=0x%X\n", Checksum.inChecksum(ip, 0, ip.size()));
   
    JBuffer b = new JBuffer(4);
   
    b.order(ByteOrder.LITTLE_ENDIAN);
    b.setUInt(0, 0x14010100)
View Full Code Here


   * Test ip4 cr c16 pkt1.
   */
  public void testIp4CRC16Pkt1() {

    JPacket packet = super.getPcapPacket(TestUtils.L2TP, 0);
    Ip4 ip = packet.getHeader(new Ip4());

    int computed = Checksum.inChecksum(ip, 0, ip.size());

    System.out.printf("1chunk=%x\n", computed);
    System.out.printf("shoudbe=%x checksum=%x\n", Checksum.inChecksumShouldBe(
        ip.checksum(), computed), ip.checksum());

    assertTrue(ip.isChecksumValid());
  }
View Full Code Here

   * Test ip4 cr c16 pkt2.
   */
  public void testIp4CRC16Pkt2() {

    JPacket packet = super.getPcapPacket(TestUtils.L2TP, 1);
    Ip4 ip = packet.getHeader(new Ip4());

    assertEquals(ip.calculateChecksum(), ip.checksum());
  }
View Full Code Here

   * Test ip4 cr c16 pkt50.
   */
  public void testIp4CRC16Pkt50() {

    JPacket packet = super.getPcapPacket(TestUtils.L2TP, 46 - 1);
    Ip4 ip = packet.getHeader(new Ip4());

    int crc;
    assertEquals(ip.checksum(), ip.calculateChecksum());

    // System.out.printf("ip.crc=%x computed=%x\n", ip.checksum(), crc);
  }
View Full Code Here

   *
   * @throws InterruptedException
   *           the interrupted exception
   */
  public void testIp4CRC16EntireFile() throws InterruptedException {
    Ip4 ip = new Ip4();
    for (JPacket packet : super.getIterable(TestUtils.L2TP)) {
      Thread.sleep(10);
      long f = packet.getFrameNumber() + 1;
      assertTrue(packet.hasHeader(ip));

      assertEquals(20, ip.size());
      final int crc = ip.calculateChecksum();

      if (ip.checksum() != crc) {
        try {
          System.out.println(packet.getState().toDebugString());
          System.out.println(packet);
        } catch (Exception e) {
          System.out.println(packet.getState().toDebugString());
          e.printStackTrace();
        }
        System.out
            .printf("#%d: ip.crc=%x computed=%x\n", f, ip.checksum(), crc);
        System.out.println(ip.toHexdump());
      }

      assertEquals("Frame #" + f, ip.checksum(), crc);
    }
  }
View Full Code Here

    assertNotNull(pcap);

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

          int i = 0, j = 0;

          // public void nextPacket(PcapHeader header, JBuffer buffer, String
          // user)
          // {
          public void nextPacket(PcapPacket packet, Pcap pcap) {

            // if (i++ % 1 == 0) {
//            packet = new PcapPacket(packet);
            j++;
            // }

            long f = packet.getFrameNumber();
            assertTrue("#" + f, packet.hasHeader(ip));
            System.out.println(packet.getState().toDebugString());

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

        }, null);
  }
View Full Code Here

    List<PcapPacket> l1 = getPacketList(L2TP);
    List<PcapPacket> l2 = getPacketList(L2TP);

    assertEquals(l1.size(), l2.size());

    Ip4 ip1 = new Ip4();
    Ip4 ip2 = new Ip4();

    for (int i = 0; i < l1.size(); i++) {
      PcapPacket p1 = l1.get(i);
      PcapPacket p2 = l2.get(i);

      int c1 = p1.getHeader(ip1).calculateChecksum();
      int c2 = p2.getHeader(ip2).calculateChecksum();

      System.out.println(ip1);
      System.out.println(ip2);

      assertEquals(c1, ip1.checksum());
      assertEquals(c2, ip2.checksum());

      assertEquals(c1, c2);
    }

  }
View Full Code Here

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

   *           Signals that an I/O exception has occurred.
   */
  public void testCompare2SetsOfPackets2() throws IOException {
    List<PcapPacket> l1 = getPacketList(L2TP);
    List<PcapPacket> l2 = getPacketList(L2TP);
    Ip4 ip1 = new Ip4();
    Ip4 ip2 = new Ip4();

    assertEquals(l1.size(), l2.size());

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

    for (int i = 0; i < l1.size(); i++) {
      PcapPacket p1 = l1.get(i);
      PcapPacket p2 = l2.get(i);
      p1.getHeader(ip1);
      p2.getHeader(ip2);

      assertTrue("ip1.size() == p2.size()", p1.size() == p2.size());

      assertTrue(ip1.toString(), ip1.isChecksumValid());
      assertTrue(ip2.toString(), ip2.isChecksumValid());
      assertTrue(compareJBuffer(p1, p2));

    }

  }
View Full Code Here

    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)
      // {
      public void nextPacket(PcapPacket packet, String user) {

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

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

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

        final int crc =
            Checksum.pseudoTcp(packet, ip.getOffset(), tcp.getOffset());

        if (crc != 0 && tcp.checksum() != crc) {
          System.out.println(tcp);
          System.out.printf("#%d: tcp.crc=%x computed=%x\n", f, tcp.checksum(),
              crc);
View Full Code Here

TOP

Related Classes of org.jnetpcap.protocol.network.Ip4$Timestamp$Entry

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.