#if 0
#ifndef lint
static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
#endif
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "telnetd.h"
#include "pathnames.h"
#include <sys/mman.h>
#include <err.h>
#include <libutil.h>
#include <paths.h>
#include <termcap.h>
#include <arpa/inet.h>
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
#include <libtelnet/misc.h>
char remote_hostname[MAXHOSTNAMELEN];
size_t utmp_len = sizeof(remote_hostname) - 1;
int registerd_host_only = 0;
char ptyibuf[BUFSIZ], *ptyip = ptyibuf;
char ptyibuf2[BUFSIZ];
int readstream(int, char *, int);
void doit(struct sockaddr *);
int terminaltypeok(char *);
int hostinfo = 1;
static int debug = 0;
int keepalive = 1;
const char *altlogin;
void doit(struct sockaddr *);
int terminaltypeok(char *);
void startslave(char *, int, char *);
extern void usage(void);
static void _gettermname(void);
char valid_opts[] = {
'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 'u', ':', 'U',
'4', '6',
#ifdef AUTHENTICATION
'a', ':', 'X', ':',
#endif
#ifdef BFTPDAEMON
'B',
#endif
#ifdef DIAGNOSTICS
'D', ':',
#endif
#ifdef ENCRYPTION
'e', ':',
#endif
#ifdef LINEMODE
'l',
#endif
'\0'
};
int family = AF_INET;
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
char *hostname;
char host_name[MAXHOSTNAMELEN];
extern void telnet(int, int, char *);
int level;
char user_name[256];
int
main(int argc, char *argv[])
{
u_long ultmp;
struct sockaddr_storage from;
int on = 1, fromlen;
int ch;
#if defined(IPPROTO_IP) && defined(IP_TOS)
int tos = -1;
#endif
char *ep;
pfrontp = pbackp = ptyobuf;
netip = netibuf;
nfrontp = nbackp = netobuf;
#ifdef ENCRYPTION
nclearto = 0;
#endif
linemode=1;
while ((ch = getopt(argc, argv, valid_opts)) != -1) {
switch(ch) {
#ifdef AUTHENTICATION
case 'a':
if (strcmp(optarg, "debug") == 0) {
extern int auth_debug_mode;
auth_debug_mode = 1;
} else if (strcasecmp(optarg, "none") == 0) {
auth_level = 0;
} else if (strcasecmp(optarg, "other") == 0) {
auth_level = AUTH_OTHER;
} else if (strcasecmp(optarg, "user") == 0) {
auth_level = AUTH_USER;
} else if (strcasecmp(optarg, "valid") == 0) {
auth_level = AUTH_VALID;
} else if (strcasecmp(optarg, "off") == 0) {
auth_level = -1;
} else {
warnx("unknown authorization level for -a");
}
break;
#endif
#ifdef BFTPDAEMON
case 'B':
bftpd++;
break;
#endif
case 'd':
if (strcmp(optarg, "ebug") == 0) {
debug++;
break;
}
usage();
break;
#ifdef DIAGNOSTICS
case 'D':
if (!strcmp(optarg, "report")) {
diagnostic |= TD_REPORT|TD_OPTIONS;
} else if (!strcmp(optarg, "exercise")) {
diagnostic |= TD_EXERCISE;
} else if (!strcmp(optarg, "netdata")) {
diagnostic |= TD_NETDATA;
} else if (!strcmp(optarg, "ptydata")) {
diagnostic |= TD_PTYDATA;
} else if (!strcmp(optarg, "options")) {
diagnostic |= TD_OPTIONS;
} else {
usage();
}
break;
#endif
#ifdef ENCRYPTION
case 'e':
if (strcmp(optarg, "debug") == 0) {
extern int encrypt_debug_mode;
encrypt_debug_mode = 1;
break;
}
usage();
break;
#endif
case 'h':
hostinfo = 0;
break;
#ifdef LINEMODE
case 'l':
alwayslinemode = 1;
break;
#endif
case 'k':
#if defined(LINEMODE) && defined(KLUDGELINEMODE)
lmodetype = NO_AUTOKLUDGE;
#else
#endif
break;
case 'n':
keepalive = 0;
break;
case 'p':
altlogin = optarg;
break;
case 'S':
#ifdef HAS_GETTOS
if ((tos = parsetos(optarg, "tcp")) < 0)
warnx("%s%s%s",
"bad TOS argument '", optarg,
"'; will try to use default TOS");
#else
#define MAXTOS 255
ultmp = strtoul(optarg, &ep, 0);
if (*ep || ep == optarg || ultmp > MAXTOS)
warnx("%s%s%s",
"bad TOS argument '", optarg,
"'; will try to use default TOS");
else
tos = ultmp;
#endif
break;
case 'u':
utmp_len = (size_t)atoi(optarg);
if (utmp_len >= sizeof(remote_hostname))
utmp_len = sizeof(remote_hostname) - 1;
break;
case 'U':
registerd_host_only = 1;
break;
#ifdef AUTHENTICATION
case 'X':
auth_disable_name(optarg);
break;
#endif
case '4':
family = AF_INET;
break;
#ifdef INET6
case '6':
family = AF_INET6;
break;
#endif
default:
warnx("%c: unknown option", ch);
case '?':
usage();
}
}
argc -= optind;
argv += optind;
if (debug) {
int s, ns, foo, error;
const char *service = "telnet";
struct addrinfo hints, *res;
if (argc > 1) {
usage();
} else if (argc == 1)
service = *argv;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
error = getaddrinfo(NULL, service, &hints, &res);
if (error) {
errx(1, "tcp/%s: %s\n", service, gai_strerror(error));
if (error == EAI_SYSTEM)
errx(1, "tcp/%s: %s\n", service, strerror(errno));
usage();
}
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s < 0)
err(1, "socket");
(void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on));
if (debug > 1)
(void) setsockopt(s, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on));
if (bind(s, res->ai_addr, res->ai_addrlen) < 0)
err(1, "bind");
if (listen(s, 1) < 0)
err(1, "listen");
foo = res->ai_addrlen;
ns = accept(s, res->ai_addr, &foo);
if (ns < 0)
err(1, "accept");
(void) setsockopt(ns, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on));
(void) dup2(ns, 0);
(void) close(ns);
(void) close(s);
#ifdef convex
} else if (argc == 1) {
;
#endif
} else if (argc > 0) {
usage();
}
openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
fromlen = sizeof (from);
if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
warn("getpeername");
_exit(1);
}
if (keepalive &&
setsockopt(0, SOL_SOCKET, SO_KEEPALIVE,
(char *)&on, sizeof (on)) < 0) {
syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
}
#if defined(IPPROTO_IP) && defined(IP_TOS)
if (from.ss_family == AF_INET) {
# if defined(HAS_GETTOS)
struct tosent *tp;
if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
tos = tp->t_tos;
# endif
if (tos < 0)
tos = 020;
if (tos
&& (setsockopt(0, IPPROTO_IP, IP_TOS,
(char *)&tos, sizeof(tos)) < 0)
&& (errno != ENOPROTOOPT) )
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
}
#endif
net = 0;
doit((struct sockaddr *)&from);
return(0);
}
void
usage()
{
fprintf(stderr, "usage: telnetd");
#ifdef AUTHENTICATION
fprintf(stderr,
" [-4] [-6] [-a (debug|other|user|valid|off|none)]\n\t");
#endif
#ifdef BFTPDAEMON
fprintf(stderr, " [-B]");
#endif
fprintf(stderr, " [-debug]");
#ifdef DIAGNOSTICS
fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
#endif
#ifdef AUTHENTICATION
fprintf(stderr, " [-edebug]");
#endif
fprintf(stderr, " [-h]");
#if defined(LINEMODE) && defined(KLUDGELINEMODE)
fprintf(stderr, " [-k]");
#endif
#ifdef LINEMODE
fprintf(stderr, " [-l]");
#endif
fprintf(stderr, " [-n]");
fprintf(stderr, "\n\t");
#ifdef HAS_GETTOS
fprintf(stderr, " [-S tos]");
#endif
#ifdef AUTHENTICATION
fprintf(stderr, " [-X auth-type]");
#endif
fprintf(stderr, " [-u utmp_hostname_length] [-U]");
fprintf(stderr, " [port]\n");
exit(1);
}
static unsigned char ttytype_sbbuf[] = {
IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE
};
#ifndef AUTHENTICATION
#define undef2 __unused
#else
#define undef2
#endif
static int
getterminaltype(char *name undef2)
{
int retval = -1;
settimer(baseline);
#ifdef AUTHENTICATION
if (auth_level >= 0) {
send_do(TELOPT_AUTHENTICATION, 1);
while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
ttloop();
if (his_state_is_will(TELOPT_AUTHENTICATION)) {
retval = auth_wait(name);
}
}
#endif
#ifdef ENCRYPTION
send_will(TELOPT_ENCRYPT, 1);
#endif
send_do(TELOPT_TTYPE, 1);
send_do(TELOPT_TSPEED, 1);
send_do(TELOPT_XDISPLOC, 1);
send_do(TELOPT_NEW_ENVIRON, 1);
send_do(TELOPT_OLD_ENVIRON, 1);
while (
#ifdef ENCRYPTION
his_do_dont_is_changing(TELOPT_ENCRYPT) ||
#endif
his_will_wont_is_changing(TELOPT_TTYPE) ||
his_will_wont_is_changing(TELOPT_TSPEED) ||
his_will_wont_is_changing(TELOPT_XDISPLOC) ||
his_will_wont_is_changing(TELOPT_NEW_ENVIRON) ||
his_will_wont_is_changing(TELOPT_OLD_ENVIRON)) {
ttloop();
}
#ifdef ENCRYPTION
if (his_state_is_will(TELOPT_ENCRYPT)) {
encrypt_wait();
}
#endif
if (his_state_is_will(TELOPT_TSPEED)) {
static unsigned char sb[] =
{ IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };
output_datalen(sb, sizeof sb);
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
}
if (his_state_is_will(TELOPT_XDISPLOC)) {
static unsigned char sb[] =
{ IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };
output_datalen(sb, sizeof sb);
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
}
if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
static unsigned char sb[] =
{ IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE };
output_datalen(sb, sizeof sb);
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
}
else if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
static unsigned char sb[] =
{ IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE };
output_datalen(sb, sizeof sb);
DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
}
if (his_state_is_will(TELOPT_TTYPE)) {
output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf);
DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
sizeof ttytype_sbbuf - 2););
}
if (his_state_is_will(TELOPT_TSPEED)) {
while (sequenceIs(tspeedsubopt, baseline))
ttloop();
}
if (his_state_is_will(TELOPT_XDISPLOC)) {
while (sequenceIs(xdisplocsubopt, baseline))
ttloop();
}
if (his_state_is_will(TELOPT_NEW_ENVIRON)) {
while (sequenceIs(environsubopt, baseline))
ttloop();
}
if (his_state_is_will(TELOPT_OLD_ENVIRON)) {
while (sequenceIs(oenvironsubopt, baseline))
ttloop();
}
if (his_state_is_will(TELOPT_TTYPE)) {
char first[256], last[256];
while (sequenceIs(ttypesubopt, baseline))
ttloop();
if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
(void) strncpy(first, terminaltype, sizeof(first)-1);
first[sizeof(first)-1] = '\0';
for(;;) {
(void) strncpy(last, terminaltype, sizeof(last)-1);
last[sizeof(last)-1] = '\0';
_gettermname();
if (terminaltypeok(terminaltype))
break;
if ((strncmp(last, terminaltype, sizeof(last)) == 0) ||
his_state_is_wont(TELOPT_TTYPE)) {
if (strncmp(first, terminaltype, sizeof(first)) == 0)
break;
_gettermname();
if (strncmp(first, terminaltype, sizeof(first)) != 0) {
(void) strncpy(terminaltype, first, sizeof(terminaltype)-1);
terminaltype[sizeof(terminaltype)-1] = '\0';
}
break;
}
}
}
}
return(retval);
}
static void
_gettermname(void)
{
if (his_state_is_wont(TELOPT_TTYPE))
return;
settimer(baseline);
output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf);
DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2,
sizeof ttytype_sbbuf - 2););
while (sequenceIs(ttypesubopt, baseline))
ttloop();
}
int
terminaltypeok(char *s)
{
char buf[1024];
if (terminaltype == NULL)
return(1);
if (tgetent(buf, s) == 0)
return(0);
return(1);
}
void
doit(struct sockaddr *who)
{
int err_;
int ptynum;
get_slc_defaults();
#ifndef convex
pty = getpty(&ptynum);
if (pty < 0)
fatal(net, "All network ports in use");
#else
for (;;) {
char *lp;
if ((lp = getpty()) == NULL)
fatal(net, "Out of ptys");
if ((pty = open(lp, 2)) >= 0) {
strlcpy(line,lp,sizeof(line));
line[5] = 't';
break;
}
}
#endif
if (realhostname_sa(remote_hostname, sizeof(remote_hostname) - 1,
who, who->sa_len) == HOSTNAME_INVALIDADDR && registerd_host_only)
fatal(net, "Couldn't resolve your address into a host name.\r\n\
Please contact your net administrator");
remote_hostname[sizeof(remote_hostname) - 1] = '\0';
if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len)
err_ = getnameinfo(who, who->sa_len, remote_hostname,
sizeof(remote_hostname), NULL, 0,
NI_NUMERICHOST);
(void) gethostname(host_name, sizeof(host_name) - 1);
host_name[sizeof(host_name) - 1] = '\0';
hostname = host_name;
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1);
#endif
#endif
init_env();
*user_name = 0;
level = getterminaltype(user_name);
setenv("TERM", terminaltype ? terminaltype : "network", 1);
telnet(net, pty, remote_hostname);
}
void
telnet(int f, int p, char *host)
{
int on = 1;
#define TABBUFSIZ 512
char defent[TABBUFSIZ];
char defstrs[TABBUFSIZ];
#undef TABBUFSIZ
char *HE;
char *HN;
char *IM;
char *IF;
char *if_buf;
int if_fd = -1;
struct stat statbuf;
int nfd;
if (my_state_is_wont(TELOPT_SGA))
send_will(TELOPT_SGA, 1);
send_do(TELOPT_ECHO, 1);
#ifdef LINEMODE
if (his_state_is_wont(TELOPT_LINEMODE)) {
linemode = 0;
editmode = 0;
send_do(TELOPT_LINEMODE, 1);
}
#endif
send_do(TELOPT_NAWS, 1);
send_will(TELOPT_STATUS, 1);
flowmode = 1;
restartany = -1;
send_do(TELOPT_LFLOW, 1);
while (his_will_wont_is_changing(TELOPT_NAWS))
ttloop();
if (his_want_state_is_will(TELOPT_ECHO) &&
his_state_is_will(TELOPT_NAWS)) {
while (his_will_wont_is_changing(TELOPT_ECHO))
ttloop();
}
if (his_want_state_is_will(TELOPT_ECHO)) {
DIAG(TD_OPTIONS, output_data("td: simulating recv\r\n"));
willoption(TELOPT_ECHO);
}
if (my_state_is_wont(TELOPT_ECHO))
send_will(TELOPT_ECHO, 1);
#if (!defined(__BEOS__) && !defined(__HAIKU__))
(void) ioctl(p, TIOCPKT, (char *)&on);
#endif
#if defined(LINEMODE) && defined(KLUDGELINEMODE)
if (lmodetype < REAL_LINEMODE)
send_do(TELOPT_TM, 1);
#endif
telrcv();
(void) ioctl(f, FIONBIO, (char *)&on);
(void) ioctl(p, FIONBIO, (char *)&on);
#if defined(SO_OOBINLINE)
(void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE,
(char *)&on, sizeof on);
#endif
#ifdef SIGTSTP
(void) signal(SIGTSTP, SIG_IGN);
#endif
#ifdef SIGTTOU
(void) signal(SIGTTOU, SIG_IGN);
#endif
(void) signal(SIGCHLD, cleanup);
#ifdef TIOCNOTTY
{
int t;
t = open(_PATH_TTY, O_RDWR);
if (t >= 0) {
(void) ioctl(t, TIOCNOTTY, (char *)0);
(void) close(t);
}
}
#endif
if (getent(defent, "default") == 1) {
char *cp=defstrs;
HE = Getstr("he", &cp);
HN = Getstr("hn", &cp);
IM = Getstr("im", &cp);
IF = Getstr("if", &cp);
if (HN && *HN)
(void) strlcpy(host_name, HN, sizeof(host_name));
if (IF) {
if_fd = open(IF, O_RDONLY, 000);
IM = 0;
}
if (IM == 0)
IM = strdup("");
} else {
IM = strdup(DEFAULT_IM);
HE = 0;
}
edithost(HE, host_name);
if (hostinfo && *IM)
putf(IM, ptyibuf2);
if (if_fd != -1) {
if (fstat(if_fd, &statbuf) != -1 && statbuf.st_size > 0) {
if_buf = (char *) mmap (0, statbuf.st_size,
PROT_READ, 0, if_fd, 0);
if (if_buf != MAP_FAILED) {
putf(if_buf, ptyibuf2);
munmap(if_buf, statbuf.st_size);
}
}
close (if_fd);
}
if (pcc)
(void) strncat(ptyibuf2, ptyip, pcc+1);
ptyip = ptyibuf2;
pcc = strlen(ptyip);
#ifdef LINEMODE
init_termbuf();
localstat();
#endif
DIAG(TD_REPORT, output_data("td: Entering processing loop\r\n"));
startslave(host, level, user_name);
nfd = ((f > p) ? f : p) + 1;
for (;;) {
fd_set ibits, obits, xbits;
int c;
if (ncc < 0 && pcc < 0)
break;
FD_ZERO(&ibits);
FD_ZERO(&obits);
FD_ZERO(&xbits);
if (nfrontp - nbackp || pcc > 0) {
FD_SET(f, &obits);
} else {
FD_SET(p, &ibits);
}
if (pfrontp - pbackp || ncc > 0) {
FD_SET(p, &obits);
} else {
FD_SET(f, &ibits);
}
if (!SYNCHing) {
FD_SET(f, &xbits);
}
if ((c = select(nfd, &ibits, &obits, &xbits,
(struct timeval *)0)) < 1) {
if (c == -1) {
if (errno == EINTR) {
continue;
}
}
sleep(5);
continue;
}
if (FD_ISSET(net, &xbits)) {
SYNCHing = 1;
}
if (FD_ISSET(net, &ibits)) {
#if !defined(SO_OOBINLINE)
if (SYNCHing) {
int atmark;
(void) ioctl(net, SIOCATMARK, (char *)&atmark);
if (atmark) {
ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
if ((ncc == -1) && (errno == EINVAL)) {
ncc = read(net, netibuf, sizeof (netibuf));
if (sequenceIs(didnetreceive, gotDM)) {
SYNCHing = stilloob(net);
}
}
} else {
ncc = read(net, netibuf, sizeof (netibuf));
}
} else {
ncc = read(net, netibuf, sizeof (netibuf));
}
settimer(didnetreceive);
#else
ncc = read(net, netibuf, sizeof (netibuf));
#endif
if (ncc < 0 && errno == EWOULDBLOCK)
ncc = 0;
else {
if (ncc <= 0) {
break;
}
netip = netibuf;
}
DIAG((TD_REPORT | TD_NETDATA),
output_data("td: netread %d chars\r\n", ncc));
DIAG(TD_NETDATA, printdata("nd", netip, ncc));
}
if (FD_ISSET(p, &ibits)) {
pcc = read(p, ptyibuf, BUFSIZ);
if (pcc < 0 && (errno == EWOULDBLOCK ||
#ifdef EAGAIN
errno == EAGAIN ||
#endif
errno == EIO)) {
pcc = 0;
} else {
if (pcc <= 0)
break;
#ifdef LINEMODE
if (ptyibuf[0] & TIOCPKT_IOCTL) {
copy_termbuf(ptyibuf+1, pcc-1);
localstat();
pcc = 1;
}
#endif
#if (!defined(__BEOS__) && !defined(__HAIKU__))
if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
netclear();
#ifndef NO_URGENT
output_data("%c%c", IAC, DM);
neturg = nfrontp-1;
DIAG(TD_OPTIONS,
printoption("td: send IAC", DM));
#endif
}
if (his_state_is_will(TELOPT_LFLOW) &&
(ptyibuf[0] &
(TIOCPKT_NOSTOP|TIOCPKT_DOSTOP))) {
int newflow =
ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0;
if (newflow != flowmode) {
flowmode = newflow;
output_data("%c%c%c%c%c%c",
IAC, SB, TELOPT_LFLOW,
flowmode ? LFLOW_ON
: LFLOW_OFF,
IAC, SE);
DIAG(TD_OPTIONS, printsub('>',
(unsigned char *)nfrontp-4,
4););
}
}
pcc--;
#endif
ptyip = ptyibuf;
}
}
while (pcc > 0) {
if ((&netobuf[BUFSIZ] - nfrontp) < 2)
break;
c = *ptyip++ & 0377, pcc--;
if (c == IAC)
output_data("%c", c);
output_data("%c", c);
if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) {
if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
output_data("%c", *ptyip++ & 0377);
pcc--;
} else
output_data("%c", '\0');
}
}
if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
netflush();
if (ncc > 0)
telrcv();
if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
ptyflush();
}
cleanup(0);
}
#ifndef TCSIG
# ifdef TIOCSIG
# define TCSIG TIOCSIG
# endif
#endif
void
interrupt(void)
{
ptyflush();
#ifdef TCSIG
(void) ioctl(pty, TCSIG, SIGINT);
#else
init_termbuf();
*pfrontp++ = slctab[SLC_IP].sptr ?
(unsigned char)*slctab[SLC_IP].sptr : '\177';
#endif
}
void
sendbrk(void)
{
ptyflush();
#ifdef TCSIG
(void) ioctl(pty, TCSIG, SIGQUIT);
#else
init_termbuf();
*pfrontp++ = slctab[SLC_ABORT].sptr ?
(unsigned char)*slctab[SLC_ABORT].sptr : '\034';
#endif
}
void
sendsusp(void)
{
#ifdef SIGTSTP
ptyflush();
# ifdef TCSIG
(void) ioctl(pty, TCSIG, SIGTSTP);
# else
*pfrontp++ = slctab[SLC_SUSP].sptr ?
(unsigned char)*slctab[SLC_SUSP].sptr : '\032';
# endif
#endif
}
void
recv_ayt(void)
{
#if defined(SIGINFO) && defined(TCSIG)
if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) {
(void) ioctl(pty, TCSIG, SIGINFO);
return;
}
#endif
output_data("\r\n[Yes]\r\n");
}
void
doeof(void)
{
init_termbuf();
#if defined(LINEMODE) && defined(USE_TERMIO) && (VEOF == VMIN)
if (!tty_isediting()) {
extern char oldeofc;
*pfrontp++ = oldeofc;
return;
}
#endif
*pfrontp++ = slctab[SLC_EOF].sptr ?
(unsigned char)*slctab[SLC_EOF].sptr : '\004';
}