Might be important to note that multiple packets can be send in one TCP packet, so the header will not always start at index 4.
You should check the length of the whole TCP packet and then read the first 4 bytes, which will tell you how long the real "packet" as we know it is, if this doesnt...