You can answer this yourself!
Packet encapsulates what??
Packet = IP header + TCP/UDP segment;
TCP/UDP segment encapsulates what??
Segment = TCP Header/UDP header + Application layer data;
So, IP header + first 8 bytes of data inside a packet = IP header + portion of TCP/UDP header.
Here's a task for you:
a) See what's stored inside the first 8 bytes of TCP as well as UDP header.
b) Think how this information is beneficial.