The EAGAIN error (creating the string "Resource temporarily unavailable;") can be increased by the timeout of the receiving socket.
Since you set only 10,000 microseconds as read timeout (this is really a short IMHO) with this line ...
struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 10000; setsockopt(recv_sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
... it is possible that the longer (I mean the number of routers you have to go through), the more likely you will be in this situation.
Try increasing the timeout value and let us know if it gets better.
EDIT
I tried the source code under linux, and I noticed two problems.
- As mentioned above: Timeouts
- Problem with port 80
I just raised the timeout and used a port other than 80 (in my case, I sent an udp message to port 40000) and I returned all the haps as a traceroute command.
I am not sure why this behavior occurs. Perhaps some kind of “possible malicious burst” is triggered by a router that discards it
FURTHER IMAGE
Take a look at this link: man traceroute
In the List of Available Methods section , you can find many ways to achieve what you need. Your method is similar to the default default:
Probe packets are udp datagrams with so-called "unlikely" destination ports. The "wrong" port of the first probe is 33434, then for each next probe it increases by one. Since it is assumed that the ports are not used, the destination host usually returns "icmp unreach port" as the final answer. ( No one knows what happens when some application listens on such ports, though ).
So, if you need to fully emulate the behavior of the general Linux trace, you should increase by 1 destination port every time the TTL is incremented (or every time you cannot get an IMHO response)
MAYBE, sometimes your command doesn’t work on certain ports, because the router listens on the latter (as the Linux manual suggests and boldly emphasized by me).