我编写了一个 ping 程序,将 syn 数据包发送到目标 IP 地址 1.1.1.1 端口 0。我使用wireshark,看到返回的数据包带有 RST/ACK 标志。但问题是当我使用 select() 尝试读取套接字时,select() 总是返回 0。所以我不知道如何调试程序。我确信我每次都会重置 fd_set 读取集。有什么我刚刚错过的吗?
我使用wireshark发现了来自1.1.1.1的回复在0.0003秒内返回
我设置的超时是1秒(1000毫秒)
这是代码
void readloop() {
....
while(nsent < 4) {
send_v4();
wait_for_reply(1000); // wait for 1 second;
}
}
int wait_for_reply(long wait_time) {
....
result = recving_time(...);
if(result < 0) // because time out
return 0;
....
}
int recving_time(...) {
......
fd_set readset;
select_again:
set timeout value to structure *to*
FD_ZERO(&readset);
FD_SET(sockfd, &readset);
readable = select(sockfd+1, &readset, NULL, NULL, &to);
#ifdef DEBUG
fprintf(stderr, "readable is %d\n",readable); // **Why readable always be 0 although packets returned.**
#endif
if(readable < 0) {
if(errno == EINTR)
goto select_again;
else {
perror("select() error");
exit(1);
}
if(readable == 0) {
return -1;
}
......
}
我不确定这里有足够的代码来理解我想说的内容。如果您能帮助我,我将非常感激
如果超过时间限制,select()返回0。您的超时(您没有显示其设置)似乎已经过去。