- /* create socket */
- if ( (list_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("Socket creation error");
- exit(1);
- }
- /* initialize address and bind socket */
- memset((void *)&serv_add, 0, sizeof(serv_add)); /* clear server address */
- serv_add.sin_family = AF_INET; /* address type is INET */
- serv_add.sin_port = htons(7); /* echo port is 7 */
- serv_add.sin_addr.s_addr = htonl(INADDR_ANY); /* connect from anywhere */
- if (bind(list_fd, (struct sockaddr *)&serv_add, sizeof(serv_add)) < 0) {
- perror("bind error");
- exit(1);
- }
- /* give away privileges and go daemon */
- if (setgid(65534) !=0) { /* first give away group privileges */
- perror("cannot give away group privileges");
- exit(1);
- }
- if (setuid(65534) !=0) { /* and only after user ... */
- perror("cannot give away user privileges");
- exit(1);
- }
- if (demonize) { /* go daemon */
- openlog(argv[0], 0, LOG_DAEMON); /* open logging */
- if (daemon(0, 0) != 0) {
- perror("cannot start as daemon");
- exit(1);
- }
- }
- /* main body */
- if (listen(list_fd, BACKLOG) < 0 ) { /* listen on socket */
- PrintErr("listen error");
- exit(1);
- }
- while (1) { /* handle echo to client */
- while (((conn_fd = accept(list_fd, NULL, NULL)) < 0)
- && (errno == EINTR)); /* accept connection */
- if ( conn_fd < 0) {
+ ...
+ if (waiting) sleep(waiting);
+ /* handle echo to client */
+ while (1) {
+ /* accept connection */
+ while (((conn_fd = accept(list_fd, (struct sockaddr *)&cli_add, &len))
+ < 0) && (errno == EINTR));
+ if ( conn_fd < 0) {