"Missing" in the sense of couldn't capture or nowhere to be found.
I am writing a program that sends parallel ICMP ping requests then reads and processes the replies. But I stumbled across a missing reply problem as the parallel requests increase in number. 5 writer threads seems okay, 10 writer threads starts to make some replies disappear. But I wanted to handle thousands (modestly).
Currently I have parallel writers (sendto()
) which waits 3 seconds between every request.
I have single thread for reading, it waits until recvfrom()
gets data.
Here is my program's log:
At first I thought I couldn't process replies fast enough, so I seperated the receive and process mechanisms in a queue. But turns out the reply is not coming in the first place (If I am interpreting the wireshark log properly).
Here is the WireShark log:
Turns out wireshark is smart enough to correlate the ICMP requests and replies. It also confirms 3 replies are missing.
What I am doing:
Creating socket such as,
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
Not setting anything with
setsockopt()
, which maybe the problem and the solution. I don't know what to do here.I am using a single socket for all the parallel read/write operations, because I am told the kernel manages the concurrency.
sendto(sockfd, &pkt, sizeof(pkt), 0, (sockaddr*) &addr, sizeof(addr))
recvfrom(recv_sockfd, &recv_pkt, sizeof(recv_pkt), 0, (sockaddr*)&r_addr, &addr_len)
What I tried:
- Make the receiving thread faster by separating some logic, turns out it being slow wasn't the issue.
- Use different sockets for write (still single for parallel) and read.
What I know:
- The replies may not be arriving because the request is never sent. All I know is
sendto()
returns greater than zero. And wireshark says the request exists.
Is there some detail about raw sockets that I am missing ?