求解select函数为啥一直返回值为0
int CConnectScan::scan(const char *IP,int start,int stop){
WORD wVersion;
WSADATA WsaData;
int time;
struct timeval timeout;
struct fd_set fdset;
wVersion = MAKEWORD(2, 2);
if (WSAStartup(wVersion, &WsaData) != 0) //初始化Winsock DLL
{
printf("未找到可用winsock.dll! \n");
return -1;
}
SOCKET PortScanSock = socket(AF_INET, SOCK_STREAM, 0);
unsigned long ul = 1;
if (ioctlsocket(PortScanSock, FIONBIO, (unsigned long*)&ul) == SOCKET_ERROR)
return 0;
SOCKADDR_IN ADDR;
ADDR.sin_family = AF_INET;
ADDR.sin_addr.S_un.S_addr = inet_addr(IP);
for (int Port = start; Port <= stop; Port++)
{
if (PortScanSock == NULL)
PortScanSock = socket(AF_INET, SOCK_STREAM, 0);
ADDR.sin_port = (Port);
connect(PortScanSock, (sockaddr*)&ADDR, sizeof(ADDR));
FD_ZERO(&fdset);
FD_SET(PortScanSock, &fdset);
timeout.tv_sec = 0;
timeout.tv_usec = 500 * 1000;
time = select(PortScanSock + 1, 0, &fdset, 0, &timeout);
PortDetil result;
result.PortNum = Port;
if (time <= 0)
{
result.OpenFlag = 0;
list.push_back(result);
}
else
{
result.OpenFlag = 1;
list.push_back(result);
closesocket(PortScanSock);
PortScanSock = NULL;
}
}
}
刚学网络编程不是很懂,select返回值一直为0,百度了一下没改过来==!好悲剧 刚学得有必要学的那么深吗?99乘法表那些算法懂了没? 昊情· 发表于 2016-1-27 11:20
刚学得有必要学的那么深吗?99乘法表那些算法懂了没?
初学网络编程,不是初学编程,动态规划,贪婪这些算法也都学过了,虽然不精通懂得少,但至少会用可以做OJ的算法题。我问的不够谦虚?有必要提算法么? 学习学习技术,加油! 学习学习技术,加油! 还是不错的哦,顶了 学习学习技术,加油! 感谢楼主的分享~ 还是不错的哦,顶了 还是不错的哦,顶了
页:
[1]