Packet Length via ip_len failed?

Home Forums Discussions General Discussion Packet Length via ip_len failed?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #5171

    hi, i’m try fetch the tcp/ip length by ip_len. Can some say me whats wrong? I get a size more than 1452 bytes!!

    DWORD dwDataLength = pIpHeader->ip_len - ( pIpHeader->ip_hl*4 + pTcpHeader->th_off*4);

    PS: right, the size could be fetched by using: (that code give me a perfect length, but the code above do not!!)

    DWORD dwDataLength = PacketBuffer.m_Length - (sizeof(ether_header) + pIpHeader->ip_hl*4 + pTcpHeader->th_off*4);

    but i want try it on an other way…please help..


    i found the answer!.

    unsigned short length = ntohs(pIpHeader->ip_len) - ( pIpHeader->ip_hl*4 + pTcpHeader->th_off*4);

    can someone say yes or no? 😀

    Vadim Smirnov

    pIpHeader->ip_len is in network byte order, so it should be:

    DWORD dwDataLength = ntohs(pIpHeader->ip_len) - ( pIpHeader->ip_hl*4 + pTcpHeader->th_off*4);
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.