#include #include #include #include #include #include #include #include int wait_for_connect(u_short port) { int sock = 0; int read_fd = 0; struct sockaddr_in localaddr, caller_addr; u_int addr_len = 0; sock = socket(AF_INET, SOCK_DGRAM, 0); if(sock < 0) { perror("socket (sock)"); exit(1); } memset(&localaddr, 0, sizeof(localaddr)); localaddr.sin_family = AF_INET; localaddr.sin_addr.s_addr = htonl(INADDR_ANY); localaddr.sin_port = htons(port); if( bind(sock, (sockaddr *) &localaddr, sizeof(localaddr)) < 0) { perror("bind "); exit(1); } return sock; }