I am coding asynchronous scanner ports, that can scan a lot of ports. However, when I am making a lot of sockets, function socket() return -1.
That's simple code, that's giving error:
#define ASYNC_SIZE 5000
int*scks = (int*)malloc(sizeof(int)*ASYNC_SIZE);
for(int i = 0; i < ASYNC_SIZE; i++){
if((scks[i] = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
printf("socket error\n");
exit(0);
}
}
I am getting EMFILE, from errno-base.h:
#define EMFILE 24 /* Too many open files */
Can i create a lot of sockets without error? Or should I use something another for this? Should I handle sockets by myself(without Linux) like a masscan?