Jpcap: IP packet header length

936 Views Asked by At

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?

1

There are 1 best solutions below

2
On

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