while(1) { int maxfd = 0; FD_ZERO(&fds); tmp = skinnylist_head; while(tmp) { FD_SET(tmp->fd, &fds); if(tmp->fd > maxfd) maxfd = tmp->fd; tmp = tmp->next; } res = ast_select(maxfd + 1, &fds, NULL, NULL, NULL); if(res > 0) { tmp = skinnylist_head; while(tmp) { if(FD_ISSET(tmp->fd, &fds)) { handle_incoming_packet_on(tmp); } } } }