I'm working on a TCP/IP stack for a networks course, and am currently working on implementing a rudimentary TCP system. With IP and UDP you get fields in the header that allow you to know the number of bytes in the payload, but as far as I can see, there is nothing like this in TCP. The client will send a value in the "window size" field during the opening handshake to indicate the maximum number of bytes it will accept, but there is no field that actually says how many bytes of data come after the header in a given packet.
Sequence and acknowledgment numbers are used to give the offset of bytes being sent and the next expected offset, but they cannot tell you how many bytes have come in the current packet.
I'm assuming I can just pass the length from the IP header down to the TCP handler, but I'd just like to verify that that's the proper way to do it.
The length of the TCP payload is given by the length field of the IP packet less the IP header (8 bytes) less the TCP header (given by the TCP header length field times 4).