Server socket - accept connections only from IP addresses in the whitelist
I have a socket server that listens and accepts connections from client, which works as follow: ... do some pre-processing (socket, binds, etc) //listen to client if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } printf("server: waiting for connections...\n"); while(1) { // main accept() loop sin_size = sizeof client_addr; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); if (new_fd == -1) { perror("accept"); continue; } //do something ..... ..... } How can I restrict the server so it only accepts connection from specific IP addresses? For instance, I can