我正在创建一个程序来创建一个RAW套接字,以便读取所有流量.在socket()和recvfrom()的调用之间(最后一个是循环以从缓冲区中取出所有数据包)我等待5s.
当我运行程序时,我用"快速模式"(快速填充缓冲区)中的hping3命令向我的程序发送大约200个数据包.一旦经过5秒,我的程序就会从缓冲区中提取大约150个数据包.
我尝试更改接收缓冲区的大小以获得更好的结果:
int a = 65535;
if ( (setsockopt(sockfd, 0, SO_RCVBUF, &a ,sizeof(int)) ) < 0 )
{
fprintf(stderr, "Error setting sock opts..\n");
}
Run Code Online (Sandbox Code Playgroud)
但是,无论是"a",1还是10000000的值,它似乎都没有变化,我仍然可以从缓冲区获得~150个数据包.
有什么问题?
编辑:通过getsockopt呼叫验证«a»的值.
这是一个使用pthread_kill()调用的小C源代码:
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
pthread_t th = NULL;
pthread_kill(th, 0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Gcc编译根据-std参数值产生各种结果(见下文).我不明白这些不同的行为.除了pthread_kill()符合POSIX.1-2008之外,我没有在手册页中获得有趣的信息.
环境:Linux 3.2 64位.GCC 4.7.2.
gcc main.c -std=c11 -pthread
Run Code Online (Sandbox Code Playgroud)
我得到一个隐含的声明:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
gcc main.c -std=c99 -pthread
Run Code Online (Sandbox Code Playgroud)
与-std = c11相同的结果:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
gcc main.c -std=c90 -pthread
Run Code Online (Sandbox Code Playgroud)
它只是没有任何错误/警告.
感谢您的反馈.