In ssh daemon, select() always returns correctly but after executing following nmap script,
nmap -sV -O -A --script ssh2-enum-algos
select() always returns 1 even though no connection is made to ssh server.
There are several other threads like this but I couldn't find problem with my code.
My code looks like this,
while (1)
{
memcpy(tmp_read_set, read_set, sizeof(fd_set));
retValSS = select(FD_SETSIZE, tmp_read_set, NULL, NULL, NULL);
switch (retValSS)
{
case -1:
LOG1(CRIT, "select() failed, errno=%d", ipcom_errno);
goto cleanup;
case 0: // Timeout....
break;
default:
for(i=0; i<MAX_LISTEN_PORTS; i++)
{
if(lst_sock[i] == INVALID_SOCKET)
break;
if(FD_ISSET(lst_sock[i], tmp_read_set))
{
clt_sock = accept(lst_sock[i], NULL, NULL);
if (INVALID_SOCKET == clt_sock) /*INVALID_SOCKET is -1*/
{
LOG1(ERR, "accept() failed, errno=%d", errno);
continue;
}
if(srv_ctx->no_clients >= srv_ctx->max_clients)
{
LOG0(INFO, "max no of connected clients reached, disconnecting client");
close(clt_sock);
continue;
}
else
{
//some work is being done
}
}
}
}
}
I am getting following error log continuously,
accept() failed, errno = 0
And the strange thing is that errno is 0 which indicates no error. If there is no error, I think then accept() should not fail. Could someone explain in what scenarios accept() can fail.
I would be very thankful if someone could help.