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.
2 Answers
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.
-
1As this answer states the inner protocol is identified and that can have a self contained length field. Further to this there is a Flag Sequence which signals the end of the outer PPP header itself: tools.ietf.org/html/rfc1662#section-4 May 17, 2017 at 11:06
Sure, there is a 2-byte checksum followed by a magic byte, but that is hardly collision-proof.
Occurrences of the magic byte are escaped. There are two types of escaping used, called "character stuffing" and "bit stuffing".