I'm making a program which create a RAW socket in order to read all traffic. Between the call of socket() and recvfrom() (last one is in a loop to get out all packets from buffer) I wait 5s.
When I run the program, I send about 200 packets with hping3 command in ? faster mode ? (to fill in the buffer fastly) to my program. As soon as 5s are elapsed, my program extract about 150 packets from the buffer.
I try to change the size of the receive buffer to get better result:
int a = 65535;
if ( (setsockopt(sockfd, 0, SO_RCVBUF, &a ,sizeof(int)) ) < 0 )
{
fprintf(stderr, "Error setting sock opts..
");
}
However, whatever is the value of ? a ?, 1 or 10000000, it seems nothing changes, I still get ~150 packets from the buffer.
What's the problem?
Edit: Value of ? a ? is verified with a getsockopt
call.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…