When receiving on an ICMP socket, (SOCK_RAW with IPPROTO_ICMP), since there is no concept of "port" in the ICMP protocol, how can an application determine that a received packet is not part of some other TCP/UDP/whatever socket transmission that is also happening at the same time?
For example, suppose you have an application with 2 threads. Thread 1 sets up a TCP server socket, and continuously receives data from a connected client. Thread 2 continuously sends echo request packets (ping) to the same client using an ICMP socket, and then receives echo replys. What is to prevent Thread 2 from receiving one of the TCP packets instead?