Determining PPP Frame Length – Layer 2 Protocol Guide

layer2ppp

How does the receiver determine the length of a PPP frame (not PPPoE or PPPoA)? Structure of a PPP frame shows no length field. Sure, at the end of the frame there is a 2-byte checksum followed by a magic byte, but that is hardly collision-proof.

Best Answer

The PPP header starts with a 16-bit protocol id. You need to look at that first in order to know how to interpret the rest.

If the protocol id is LCP/IPCP/IPv6CP then the header structure typically looks like this:

struct PPP {
    uint16_t protocolId;
    uint8_t code;
    uint8_t identifier;
    uint16_t length; // <= network-encoded length field
};

If the protocol id is IPv4 or IPv6 then the IP header comes immediately after the protocol id. Both IPv4 and IPv6 have a length field in their headers.

I'm not familiar with HDLC frames, but I assume you are receiving them from a socket. The socket read/receive function would provide you with the size of each incoming frame. So you can use that for validation purposes as well.