There is big mistake in your port scanner function ,because of that only it doesn't work for the next attempt . I too missed to debug it in the previous code.

Actually you tried to establish socket connection 20000 times.Some got succeed . For some time you opened some number of socket descriptors ,that exceeds the system limits.So it got fail the later iteration .You need to close the socket descriptor after checking the connect ion.

Here is the debugger port scanner function , now the problems will not occur ,try this.

Code:
 void simple_port_scanner()
{
        char ip[17];

        int i,net,new;

        struct sockaddr_in sa;



        printf("Enter the ip : ");
        scanf("%s",ip);
        sa.sin_addr.s_addr=inet_addr(ip);
        for(i=1;i<20000;i++)
        {
                sa.sin_family=AF_INET;
                sa.sin_port=htons(i);
                net=socket(AF_INET,SOCK_STREAM,0);

                if((new=connect(net,(struct sockaddr *)&sa,sizeof(sa)))>=0)
                {
                        printf("%d is open:%d\n",i);
                }
                close(net); //Close the socket other wise it will exceed system limits
        }
        printf("now exit scanner\n");

}
Verify this output with your previous scanner outputs . You will see some big different .

cheers

Last edited by karthigayan; 10Mar2010 at 18:25..