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