SCCS-vsn: libexec/telnetd/telnetd.c 4.5
-static char sccsid[] = "@(#)telnetd.c 4.4 (Berkeley) %G%";
+#ifndef lint
+static char sccsid[] = "@(#)telnetd.c 4.5 82/03/23";
+#endif
+
/*
* Stripped-down telnet server.
*/
/*
* Stripped-down telnet server.
*/
#define INFINITY 10000000
#define BELL '\07'
#define INFINITY 10000000
#define BELL '\07'
-#define swab(x) ((((x) >> 8) | ((x) << 8)) & 0xffff)
char hisopts[256];
char myopts[256];
char hisopts[256];
char myopts[256];
extern int errno;
char line[] = "/dev/ptyp0";
extern int errno;
char line[] = "/dev/ptyp0";
-struct sockaddr_in sin = { AF_INET, swab(IPPORT_TELNET) };
+struct sockaddr_in sin = { AF_INET, IPPORT_TELNET };
int options = SO_ACCEPTCONN|SO_KEEPALIVE;
int options = SO_ACCEPTCONN|SO_KEEPALIVE;
-/*
- * Debugging hooks. Turned on with a SIGTERM.
- * Successive SIGTERM's toggle the switch.
- */
-int toggle();
-int debug;
-FILE *log;
-char logfile[80] = "/tmp/teldebugx";
-
main(argc, argv)
char *argv[];
{
main(argc, argv)
char *argv[];
{
argc--, argv++;
if (argc > 0 && !strcmp(argv[0], "-d"))
options |= SO_DEBUG;
argc--, argv++;
if (argc > 0 && !strcmp(argv[0], "-d"))
options |= SO_DEBUG;
+#if vax || pdp11
+ sin.sin_port = htons(sin.sin_port);
+#endif
for (;;) {
errno = 0;
if ((s = socket(SOCK_STREAM, 0, &sin, options)) < 0) {
for (;;) {
errno = 0;
if ((s = socket(SOCK_STREAM, 0, &sin, options)) < 0) {
printf("All network ports in use.\n");
exit(1);
gotpty:
printf("All network ports in use.\n");
exit(1);
gotpty:
- logfile[strlen("/tmp/teldebug")] = "0123456789abcdef"[i];
dup2(f, 0);
cp[strlen("/dev/")] = 't';
t = open("/dev/tty", 2);
dup2(f, 0);
cp[strlen("/dev/")] = 't';
t = open("/dev/tty", 2);
ioctl(p, FIONBIO, &on);
signal(SIGTSTP, SIG_IGN);
sigset(SIGCHLD, cleanup);
ioctl(p, FIONBIO, &on);
signal(SIGTSTP, SIG_IGN);
sigset(SIGCHLD, cleanup);
- sigset(SIGTERM, toggle);
for (;;) {
int ibits = 0, obits = 0;
for (;;) {
int ibits = 0, obits = 0;
ibits |= (1 << f);
if (ncc < 0 && pcc < 0)
break;
ibits |= (1 << f);
if (ncc < 0 && pcc < 0)
break;
- if (debug)
- fprintf(log, "select: ibits=%d, obits=%d\n",
- ibits, obits);
select(32, &ibits, &obits, INFINITY);
select(32, &ibits, &obits, INFINITY);
- if (debug)
- fprintf(log, "ibits=%d, obits=%d\n", ibits, obits);
if (ibits == 0 && obits == 0) {
sleep(5);
continue;
if (ibits == 0 && obits == 0) {
sleep(5);
continue;
*/
if (ibits & (1 << f)) {
ncc = read(f, netibuf, BUFSIZ);
*/
if (ibits & (1 << f)) {
ncc = read(f, netibuf, BUFSIZ);
- if (debug)
- fprintf(log, "read %d from net\n", ncc);
if (ncc < 0 && errno == EWOULDBLOCK)
ncc = 0;
else {
if (ncc < 0 && errno == EWOULDBLOCK)
ncc = 0;
else {
*/
if (ibits & (1 << p)) {
pcc = read(p, ptyibuf, BUFSIZ);
*/
if (ibits & (1 << p)) {
pcc = read(p, ptyibuf, BUFSIZ);
- if (debug)
- fprintf(log, "read %d from pty\n", pcc);
if (pcc < 0 && errno == EWOULDBLOCK)
pcc = 0;
else {
if (pcc < 0 && errno == EWOULDBLOCK)
pcc = 0;
else {
nbackp = nfrontp = netobuf;
}
nbackp = nfrontp = netobuf;
}
-toggle()
-{
- if (debug) {
- fprintf(log, "log stopped\n");
- if (log)
- fclose(log);
- } else {
- if ((log = fopen(logfile, "a")) != NULL) {
- setbuf(log, 0);
- fprintf(log, "log started on /dev/pty%c\n",
- logfile[strlen("/tmp/teldebug")]);
- fprintf(log, "net=%d, pty=%d\n", net, pty);
- }
- }
- debug = !debug;
-}
-