/* * C Implementation: pptpd * * Description: * * * Author: , (C) 2009 * * Copyright: See COPYING file that comes with this distribution * */ #include #include #include #include #include #include #include #include #include #include #include #include "list.h" #include "pptp_prot.h" #include "triton/triton.h" #include "pptpd.h" #include "log.h" static struct ctrl_thread_t *threads=NULL; static int threads_count=0; int start_server(void) { int sock,c_sock; int r,min_thr,min_cnt; struct pollfd pfd; struct sockaddr_in addr; socklen_t size; sock=socket (PF_INET, SOCK_STREAM, 0); if (sock<0) { log_error("failed to create socket\n"); return -1; } addr.sin_family = AF_INET; addr.sin_port = htons (PPTP_PORT); addr.sin_addr.s_addr = htonl (INADDR_ANY); setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &sock, sizeof(sock)); if (bind (sock, (struct sockaddr *) &addr, sizeof (addr)) < 0) { perror("bind"); log_error("failed to bind socket\n"); return -1; } if (listen (sock, 1000)<0) { log_error("failed to listen socket\n"); return -1; } pfd.fd=sock; pfd.events=POLLIN; while(1) { r=poll(&pfd,1,-1); if (r<0 && errno!=EINTR) { log_error("poll failed\n"); return -2; } if (r<=0) continue; if (!(pfd.revents&POLLIN)) continue; size=sizeof(addr); c_sock=accept(sock,(struct sockaddr *)&addr,&size); if (c_sock<0) { log_error("client accept failed\n"); continue; } min_thr=0; min_cnt=65536; for(r=0; r