tools/llvm: Do not build with symbols
[minix3.git] / minix / commands / telnetd / term.c
blob90638e53d7dfa773be95aee6576ed69c47ff7f72
1 /*
2 * TNET A server program for MINIX which implements the TCP/IP
3 * suite of networking protocols. It is based on the
4 * TCP/IP code written by Phil Karn et al, as found in
5 * his NET package for Packet Radio communications.
7 * Handle the TERMINAL module.
9 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * Michael Temari, <temari@temari.ae.ge.com>
12 * 07/29/92 MT Telnet options hack which seems to work okay
13 * 01/12/93 MT Better telnet options processing instead of hack
15 #include <sys/types.h>
16 #include <errno.h>
17 #if 0
18 #include <fcntl.h>
19 #endif
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include <signal.h>
25 #include "telnet.h"
26 #include "telnetd.h"
28 void sig_done(int sig);
30 static char buff[4096];
32 void term_init()
34 tel_init();
36 telopt(1, WILL, TELOPT_SGA);
37 telopt(1, DO, TELOPT_SGA);
38 telopt(1, WILL, TELOPT_BINARY);
39 telopt(1, DO, TELOPT_BINARY);
40 telopt(1, WILL, TELOPT_ECHO);
41 telopt(1, DO, TELOPT_WINCH);
44 static int io_done = 0;
46 void term_inout(pty_fd)
47 int pty_fd;
49 register int i;
50 pid_t pid;
51 struct sigaction sa;
53 sigemptyset(&sa.sa_mask);
54 sa.sa_flags = 0;
55 sa.sa_handler = sig_done;
56 sigaction(SIGALRM, &sa, (struct sigaction *) NULL);
58 if ((pid = fork()) == -1) {
59 sprintf(buff, "telnetd: fork() failed: %s\r\n", strerror(errno));
60 (void) write(1, buff, strlen(buff));
63 if (pid != 0) {
64 /* network -> login process */
65 while (!io_done && (i = read(0, buff, sizeof(buff))) > 0) {
66 tel_in(pty_fd, 1, buff, i);
68 /* EOF, kill opposite number and exit. */
69 (void) kill(pid, SIGKILL);
70 } else {
71 /* login process -> network */
72 while ((i = read(pty_fd, buff, sizeof(buff))) > 0) {
73 tel_out(1, buff, i);
75 /* EOF, alert opposite number and exit. */
76 (void) kill(getppid(), SIGALRM);
78 /* EOF. */
81 void sig_done(sig)
82 int sig;
84 io_done = 1;
85 alarm(1); /* there is always a chance... */