0

In JPCap i obtain the header length of the IP packet by the following code

   IPPacket IP_pac = (IPPacket) packet;
   System.out.println(IP_pac.len); // header length

i obtain the data length of the IP packet by

    System.out.println(IP_pac.data.length);

Now the problem is that the IP packet(IPV4) length should b 20 bytes when the data length of the IP packet is 0.but the results display the header length of the IP packet as 60 and 54. Secondly, do i consider these lengths of IP_pac.data.length as bytes by default?

Xara
  • 8,748
  • 16
  • 52
  • 82

1 Answers1

0

According to the API, the length is a short:

public short length

packet.data gives you a byte[], so calling .length on this returns a int (like on all other arrays).

Thor
  • 6,607
  • 13
  • 62
  • 96
  • So i have to convert it into bytes from int? (inorder to say that 20,30 etc bytes of the payload). – Xara May 28 '12 at 06:10
  • if you want the payload length, `packet.data.length` is fine. You also get this info in _Total Length_ of the IP packet header (as well as the _Internet Header Length_). See http://en.wikipedia.org/wiki/IPv4 for more info. – Thor May 28 '12 at 06:29