I'm not the best programmer. This looks like C, or perl checking the Layer 3 information of the IP header.
You'll need to check the Layer 4 TCP header for the particular port.
I searched for "IPPROTO_TCP" and found this example: http://www.cs.princeton.edu/~mhw/raw/api_example.html
It has a part where it uses a layer 4 UDP pointer
There should be a TCP equivalent like tcp_header->dest
udp_header->source = htons(local_port);
udp_header->dest = htons(remote_port);
I hope this helps.