+ sin.sin_port = htons((u_short)sin.sin_port);
+ }
+#ifndef DEBUG
+ if (fork())
+ exit(0);
+ for (s = 0; s < 10; s++)
+ (void) close(s);
+ (void) open("/", 0);
+ (void) dup2(0, 1);
+ (void) dup2(0, 2);
+ { int tt = open("/dev/tty", 2);
+ if (tt > 0) {
+ ioctl(tt, TIOCNOTTY, 0);
+ close(tt);
+ }
+ }
+#endif
+again:
+ s = socket(AF_INET, SOCK_STREAM, 0, 0);
+ if (s < 0) {
+ perror("telnetd: socket");;
+ sleep(5);
+ goto again;
+ }
+ if (options & SO_DEBUG)
+ if (setsockopt(s, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
+ perror("telnetd: setsockopt (SO_DEBUG)");
+ if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0) < 0)
+ perror("telnetd: setsockopt (SO_KEEPALIVE)");
+ while (bind(s, (caddr_t)&sin, sizeof (sin), 0) < 0) {
+ perror("telnetd: bind");
+ sleep(5);
+ }
+ signal(SIGCHLD, reapchild);
+ listen(s, 10);
+ for (;;) {
+ struct sockaddr_in from;
+ int s2, fromlen = sizeof (from);
+
+ s2 = accept(s, (caddr_t)&from, &fromlen);
+ if (s2 < 0) {
+ if (errno == EINTR)
+ continue;
+ perror("telnetd: accept");