source: trunk/minix/commands/telnetd/term.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.9 KB
Line 
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.
6 *
7 * Handle the TERMINAL module.
8 *
9 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * Michael Temari, <temari@temari.ae.ge.com>
11 *
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
14 */
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"
27
28_PROTOTYPE(void sig_done, (int sig));
29
30static char buff[4096];
31
32void term_init()
33{
34 tel_init();
35
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);
42}
43
44static int io_done = 0;
45
46void term_inout(pty_fd)
47int pty_fd;
48{
49register int i;
50pid_t pid;
51struct sigaction sa;
52
53 sigemptyset(&sa.sa_mask);
54 sa.sa_flags = 0;
55 sa.sa_handler = sig_done;
56 sigaction(SIGALRM, &sa, (struct sigaction *) NULL);
57
58 if ((pid = fork()) == -1) {
59 sprintf(buff, "telnetd: fork() failed: %s\r\n", strerror(errno));
60 (void) write(1, buff, strlen(buff));
61 }
62
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);
67 }
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);
74 }
75 /* EOF, alert opposite number and exit. */
76 (void) kill(getppid(), SIGALRM);
77 }
78 /* EOF. */
79}
80
81void sig_done(sig)
82int sig;
83{
84 io_done = 1;
85 alarm(1); /* there is always a chance... */
86}
Note: See TracBrowser for help on using the repository browser.