为什么要改变SO_RCVBUF的值不起作用? [英] Why changing value of SO_RCVBUF doesn't work?
问题描述
我在做这才能阅读所有流量创建一个原始套接字的程序。插座()和recvfrom()的调用之间(最后一个是在一个循环中摆脱来自缓冲区中的所有数据包)我等待5秒。
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.
当我运行程序时,我送大约200包用hping3在«更快的模式»命令(填写速度快缓冲),以我的程序。只要5秒的流逝,我的程序从缓冲区中提取约150包。
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..\n");
}
不过,无论是A的值,1或为10000000,似乎没有什么变化,我还是从缓冲区获取〜150包。
However, whatever is the value of « a », 1 or 10000000, it seems nothing changes, I still get ~150 packets from the buffer.
这是什么问题?
编辑:的A值验证了的getsockopt
呼叫
Value of « a » is verified with a getsockopt
call.
推荐答案
的级别
参数的setsockopt
应 SOL_SOCKET
,而不是 0
:
int a = 65535;
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &a, sizeof(int)) == -1) {
fprintf(stderr, "Error setting socket opts: %s\n", strerror(errno));
}
这篇关于为什么要改变SO_RCVBUF的值不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!