Ejemplo n.º 1
0
  /**
   * Test sub header access.
   *
   * @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
     */
    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
  }