I need to implement an 'ethernet-wannabe protocol' with a sender and a receiver.(only layers 1,2).
Assuming a sender\receiver model for an Ethernet frame with varying payload length. As for the sender- I have no issues. The frame consists of the MAC's of the sender and receiver, type and length of the payload and a payload, and a 4 byte CRC calculation afterwards.
Layer 1 merely sends the bits to the receiver.
The receiver's layer 1 reads those bits and adds them up to form a frame. How do I know when has the frame ended? I know I have the length field to know how many bytes are reserved for the payload and then the CRC bytes afterwards.
However, what if an error occurred and the length byte was changed? I can't rely on it no more. Another solution is to put an 'end of frame' character after the CRC so the receiver knows this marks the end of the frame(assuming it can't be in the payload\macs\etc). But the same problem arises, what if any other byte was mistakenly changed into this special character , or this byte has changed?