I am writing a C / C ++ application for Linux that reads data from a raw socket (for ICMP packets). Question: Is there a way to discard all data that is still queued on the socket?
The problem is that after sleep for a while there is data queuing for a socket that is not interesting to me; so it would be best to tell the socket to "forget all the data that you have buffered right now," so if I go into the select () / recvfrom () loop, I only get the data that I’ve received recently.
Is there a better way than the first poll () / recvfrom () loop? Maybe some kind of API socket? Portable, even ?:-)
source
share