Package org.jnetpcap.protocol.network

Examples of org.jnetpcap.protocol.network.Ip4$ExperimentalFlowControl


   *           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

    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

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

    Ip4 ip = new Ip4();
    if (packet.hasHeader(ip)) {
      // System.out.println(ip);
      // 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)) {
View Full Code Here

    if (packet.hasHeader(eth)) {
      assertFalse(eth.isFragmented());
    }

    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

    // }
    // FormatUtils.createPcapFile(TEMP_CAP, data);

    // System.out.println(packet);
    System.out.println(packet.getHeader(new Ethernet()));
    System.out.println(packet.getHeader(new Ip4()));
    System.out.println(packet.getHeader(new Udp()));
    System.out.println(packet.getState().toDebugString());

  }
View Full Code Here

    PcapPacket packet = TestUtils.getPcapPacket("tests/test-afs.pcap", 29 - 1);

    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

   *
   * @throws IOException
   *           Signals that an I/O exception has occurred.
   */
  public void testSubHeaderAccess() throws IOException {
    Ip4 ip = new Ip4();
    Ip4.Timestamp ts = new Ip4.Timestamp();
    Ip4.LooseSourceRoute lsroute = new Ip4.LooseSourceRoute();
    Ip4.StrictSourceRoute ssroute = new Ip4.StrictSourceRoute();
    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));
    assertFalse(ip.hasSubHeader(ssroute));
    assertFalse(ip.hasSubHeader(ts));
   
    assertTrue(ip.hasSubHeader(record));
    assertEquals(9, record.addressCount());
   
    byte[] b = record.address(0);
    assertNotNull(b);
    assertEquals(4, b.length);
    assertEquals(-64, b[0]); // 192 in unsinged int
    assertEquals(-88, b[1]); // 168 in unsigned int
    assertEquals(1, b[2]);   // 1
    assertEquals(13, b[3])// 13
   
    assertNotNull(packet);
    assertTrue(packet.hasHeader(ip));
    assertTrue(ip.hasSubHeaders());
    assertFalse(ip.hasSubHeader(lsroute));
    assertFalse(ip.hasSubHeader(ssroute));
    assertFalse(ip.hasSubHeader(ts));
   
    assertTrue(ip.hasSubHeader(record));
    assertEquals(9, record.addressCount());
   
    /*
     * Now do it a second time without resetting the packet
     */
 
View Full Code Here

  /**
   * Test syntax text.
   */
  public void testSyntaxText() {
    Ip4 ip = new Ip4();
    Ip4.Timestamp ts = new Ip4.Timestamp();
    Ip4.LooseSourceRoute lsroute = new Ip4.LooseSourceRoute();
    Ip4.StrictSourceRoute ssroute = new Ip4.StrictSourceRoute();
    Ip4.RecordRoute record = new Ip4.RecordRoute();

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

    if (packet.hasHeader(ip) && ip.hasSubHeaders()) {

      if (ip.hasSubHeader(lsroute)) {
        System.out.println("LooseSource");
      }

      if (ip.hasSubHeader(ssroute)) {
        System.out.println("StrictSource");
      }

      if (ip.hasSubHeader(ts)) {
        System.out.println("Timestamp");
      }
     
      if (ip.hasSubHeader(record)) {
        System.out.println("RecordRoute");
      }

    }
  }
View Full Code Here

    for (JField field : fields) {
      System.out.printf("field=%s\n", field.toString());
    }

    Ip4 ip = new Ip4();

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

    if (packet.hasHeader(JProtocol.IP4_ID)) {
      ip = packet.getHeader(ip);
View Full Code Here

TOP

Related Classes of org.jnetpcap.protocol.network.Ip4$ExperimentalFlowControl

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.