⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckucon.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
	    if (dohangup > 1)		/* User asked for it */	      if (mdmhup() < 1)		/* Maybe hang up via modem */#endif /* NODIAL */	      tthang();			/* And make sure we don't hang up */	    dohangup = 0;		/* again unless requested again. */	}#ifdef SUNX25	if (dox25clr) {			/* If X.25 clear requested */	    x25clear();			/* do that. */	    initpad();	    dox25clr = 0;		/* But only once. */	}#endif /* SUNX25 */	if (!quiet)	  printf("(Back at %s)", *myhost ? myhost : "local UNIX system");	printf("\n");	what = W_NOTHING;		/* So console modes set right. */#ifndef NOCSETS	language = langsv;		/* Restore language */#endif /* NOCSETS */	parent_id = (PID_T) 0;#ifdef DYNAMIC	if (temp) free(temp);		/* Free allocated memory */	if (ibuf) free(ibuf);	if (obuf) free(obuf);#endif /* DYNAMIC */	return(1);    } else {				/* Inferior reads, prints port input */#ifndef OXOS	if (priv_can()) {		/* Cancel all privs */	    printf("?setuid error - fatal\n");	    doexit(BAD_EXIT,-1);	}#endif /* OXOS */	signal(SIGINT, SIG_IGN);	/* In case these haven't been */	signal(SIGQUIT, SIG_IGN);	/* inherited from above... */	inshift = outshift = 0;		/* Initial SO/SI shift state. */	sleep(1);			/* Wait for parent's handler setup.  */	ibp = ibuf;			/* Initialize input buffering */	ibc = 0;			/* And output buffering. */	obp = obuf;	obc = 0;	debug(F100,"CONNECT starting port fork","",0);	while (1) {			/* Fresh read, wait for a character. */#ifdef SUNX25	    if (network && (nettype == NET_SX25)) {		bzero(x25ibuf,sizeof(x25ibuf)) ;		if ((ibufl = ttxin(MAXIX25,x25ibuf)) < 0) {		    if (ibufl == -2) {  /* PAD parms changes */			write(padpipe[1],padparms,MAXPADPARMS);			kill(parent_id,SIGUSR2);		    } else {			if (!quiet)			  printf("\r\nCommunications disconnect ");			kill(parent_id,SIGUSR1);		    }		    pause();		}		if (debses) {		/* Debugging output */		    p = x25ibuf ;                        while (ibufl--) { c = *p++; conol(dbchr(c)); }		} else {		    if (sosi#ifndef NOCSETS			|| tcsl != tcsr#endif /* NOCSETS */			) { /* Character at a time */			for (i = 1; i < ibufl; i++) {			    c = x25ibuf[i] & cmask;			    if (sosi) { /* Handle SI/SO */				if (c == SO) {				    inshift = 1;				    continue;				} else if (c == SI) {				    inshift = 0;				    continue;				}				if (inshift)				  c |= 0200;			    }#ifndef NOCSETS#ifndef SKIPESC		    /* Translate character sets */		    if (sxo) c = (*sxo)(c); /* From local to intermediate. */		    if (rxo) c = (*rxo)(c); /* From intermediate to remote. */#else /* Skipping escape sequences... */		    if (inesc == ES_NORMAL) { /* If not inside escape seq.. */			/* Translate character sets */			if (sxo) c = (*sxo)(c); /* Local to intermediate. */			if (rxo) c = (*rxo)(c); /* Intermediate to remote. */		    }		    if (skipesc) chkaes(c); /* Check escape sequence status */#endif /* SKIPESC */#endif /* NOCSETS */			    c &= cmdmsk; /* Apply command mask. */			    conoc(c);    /* Output to screen */			    logchar(c);  /* and session log */			}		    } else {		 /* All at once */			for (i = 1; i < ibufl; i++)			  x25ibuf[i] &= (cmask & cmdmsk);			conxo(ibufl,x25ibuf);			if (seslog) zsoutx(ZSFILE,x25ibuf,ibufl);		    }		}		continue;	    } else {			/* Not X.25... */#endif /* SUNX25 *//*  Get the next communication line character from our internal buffer.  If the buffer is empty, refill it.*/		c = ckcgetc(0);		/* Get next character */		/* debug(F101,"CONNECT c","",c); */		if (c < 0) {		    if (!quiet) {	/* Failed... */			printf("\r\nCommunications disconnect ");			if ( c == -3#ifdef UTEK/* This happens on UTEK if there's no carrier */			    && errno != EWOULDBLOCK#endif /* UTEK */			    )			  perror("\r\nCan't read character");		    }		    tthang();		/* Hang up the connection */		    kill(parent_id,SIGUSR1); /* Notify parent */		    for (;;) pause();	/* and wait to be killed */		}		debug(F111,"** PORT",dbchr(c),c);#ifdef TNCODE		/* Handle TELNET negotiations here */			if (c == IAC && network && ttnproto == NP_TELNET) {		    ckcputf();		/* Dump output buffer */		    if ((tx = tn_doop((CHAR)(c & 0xff),duplex,ckcgetc)) == 0) {			continue;		    } else if (tx == -1) { /* I/O error */			if (!quiet)			  printf("\r\nCommunications disconnect ");			kill(parent_id,SIGUSR1); /* Notify parent. */			for (;;) pause(); /* Wait to be killed. */		    } else if ((tx == 1) && (!duplex)) { /* ECHO change */			kill(parent_id,SIGUSR2); /* Tell the parent fork */			duplex = 1;		    } else if ((tx == 2) && (duplex)) { /* ECHO change */			kill(parent_id,SIGUSR2); 			duplex = 0;		    } else if (tx == 3) { /* Quoted IAC */			c = 255;		    } else continue;	/* Negotiation OK, get next char. */		}#endif /* TNCODE */		if (debses) {		/* Output character to screen */		    char *s;		/* Debugging display... */		    s = dbchr(c);		    while (*s)		      ckcputc(*s++);		} else {		/* Regular display ... */		    c &= cmask;		/* Apply Kermit-to-remote mask */		    if (sosi) {		/* Handle SI/SO */			if (c == SO) {	/* Shift Out */			    inshift = 1;			    continue;			} else if (c == SI) { /* Shift In */			    inshift = 0;			    continue;			}			if (inshift) c |= 0200; 		    }#ifndef NOCSETS#ifndef SKIPESC		    /* Translate character sets */		    if (sxi) c = (*sxi)((CHAR)c);		    if (rxi) c = (*rxi)((CHAR)c);#else		    if (inesc == ES_NORMAL) {			/* Translate character sets */			if (sxi) c = (*sxi)((CHAR)c);			if (rxi) c = (*rxi)((CHAR)c);		    }		    /* Adjust escape sequence status */		    if (skipesc) chkaes((char)c);#endif /* SKIPESC */#endif /* NOCSETS */		    c &= cmdmsk;	/* Apply command mask. */		    if (c == CR && tt_crd) { /* SET TERM CR-DISPLAY CRLF ? */			ckcputc(c);	     /* Yes, output CR */			if (seslog) logchar((char)c);			c = LF;		     /* and insert a linefeed */		    }		    ckcputc(c);		/* Output character to screen */		    if (seslog) logchar((char)c); /* Do session log */		}#ifdef SUNX25	    }   #endif /* SUNX25 */		}    }}/*  H C O N N E  --  Give help message for connect.  */inthconne() {    int c;    static char *hlpmsg[] = {"\r\n  ? for this message","\r\n  0 (zero) to send a null","\r\n  B to send a BREAK",#ifdef CK_LBRK"\r\n  L to send a Long BREAK",#endif /* CK_LBRK */#ifdef NETCONN"\r\n  I to send a network interrupt packet",#ifdef TCPSOCKET"\r\n  A to send Are You There?",#endif /* TCPSOCKET */#ifdef SUNX25"\r\n  R to reset X.25 virtual circuit",#endif /* SUNX25 */#endif /* NETCONN */"\r\n  H to hangup and close the connection","\r\n  Q to hangup and quit Kermit","\r\n  S for status","\r\n  ! to push to local shell","\r\n  Z to suspend","\r\n  \\ backslash code:","\r\n    \\nnn  decimal character code","\r\n    \\Onnn octal character code","\r\n    \\Xhh  hexadecimal character code","\r\n    terminate with carriage return.","\r\n Type the escape character again to send the escape character, or","\r\n press the space-bar to resume the CONNECT command.\r\n\r\n","" };    conol("\r\nPress C to return to ");    conol(*myhost ? myhost : "the C-Kermit prompt");    conol(", or:");    conola(hlpmsg);			/* Print the help message. */    conol("Command>");			/* Prompt for command. */    c = congks(0) & 0177;		/* Get character, strip any parity. */    /* No key mapping or translation here */    if (c != CMDQ)      conoll("");    return(c);				/* Return it. */}/*  D O E S C  --  Process an escape character argument  */VOID#ifdef CK_ANSICdoesc(char c)#elsedoesc(c) char c;#endif /* CK_ANSIC *//* doesc */ {    CHAR d;      while (1) {	if (c == escape) {		/* Send escape character */	    d = dopar((CHAR) c); ttoc((char) d); return;    	} else				/* Or else look it up below. */	    if (isupper(c)) c = tolower(c);	switch(c) {	case 'c':			/* Escape back to prompt */	case '\03':	    active = 0; conol("\r\n"); return;	case 'b':			/* Send a BREAK signal */	case '\02':	    ttsndb(); return;#ifdef NETCONN	case 'i':			/* Send Interrupt */	case '\011':#ifdef TCPSOCKET#ifndef IP#define IP 244#endif /* IP */	    if (network && ttnproto == NP_TELNET) { /* TELNET */		temp[0] = IAC;		/* I Am a Command */		temp[1] = IP;		/* Interrupt Process */		temp[2] = NUL;		ttol((CHAR *)temp,2);	    } else #endif /* TCPSOCKET */#ifdef SUNX25            if (network && (nettype == NET_SX25)) { /* X.25 */		(VOID) x25intr(0);	            /* X.25 interrupt packet */		conol("\r\n");	    } else#endif /* SUNX25 */	      conoc(BEL);	    return;#ifdef TCPSOCKET	case 'a':			/* "Are You There?" */	case '\01':#ifndef AYT#define AYT 246#endif /* AYT */	    if (network && ttnproto == NP_TELNET) {		temp[0] = IAC;		/* I Am a Command */		temp[1] = AYT;		/* Are You There? */		temp[2] = NUL;		ttol((CHAR *)temp,2);	    } else conoc(BEL);	    return;#endif /* TCPSOCKET */#endif /* NETCONN */#ifdef CK_LBRK	case 'l':			/* Send a Long BREAK signal */	    ttsndlb(); return;#endif /* CK_LBRK */	case 'h':			/* Hangup */	case '\010':#ifdef SUNX25            if (network && (nettype == NET_SX25)) dox25clr = 1;            else#endif /* SUNX25 */	    dohangup = 2; active = 0; conol("\r\nHanging up "); return;#ifdef SUNX25        case 'r':                       /* Reset the X.25 virtual circuit */        case '\022':            if (network && (nettype == NET_SX25)) (VOID) x25reset();            conol("\r\n"); return;#endif /* SUNX25 */ 	case 'q':			/* Quit */	    quitnow = 1; active = 0; conol("\r\n"); return;	case 's':			/* Status */	    sprintf(temp,		    "\r\nConnected %s %s", network ? "to" : "through", ttname);	    conol(temp);#ifdef SUNX25            if (network && (nettype == NET_SX25)) {                sprintf(temp,", Link ID %d, LCN %d",linkid,lcn); conol(temp);	    }#endif /* SUNX25 */	    if (speed >= 0L) {		sprintf(temp,", speed %ld", speed);		conoll(temp);	    } else conoll("");	    sprintf(temp,		    "Terminal bytesize: %d, Command bytesize: %d, Parity: ",		    (cmask  == 0177) ? 7 : 8,		    (cmdmsk == 0177) ? 7 : 8 );	    conol(temp);	    switch (parity) {	      case  0:  conoll("none");  break;	      case 'e': conoll("even");  break;	      case 'o': conoll("odd");   break;	      case 's': conoll("space"); break;	      case 'm': conoll("mark");  break;	    }	    sprintf(temp,"Terminal echo: %s", duplex ? "local" : "remote");	    conoll(temp);	    if (seslog) {		conol("Logging to: "); conoll(sesfil);            }	    if (!network) shomdm();	    return;	case '?':			/* Help */	    c = hconne(); continue;	case '0':			/* Send a null */	    c = '\0'; d = dopar((CHAR) c); ttoc((char) d); return;#ifndef NOPUSH	case 'z': case '\032':		/* Suspend */	    stptrap(0); return;	case '@':			/* Start inferior command processor */	case '!':	    conres();			/* Put console back to normal */	    zshcmd("");			/* Fork a shell. */	    if (conbin((char)escape) < 0) {		printf("Error resuming CONNECT session\n");		active = 0;	    }	    return;#endif /* NOPUSH */	case SP:			/* Space, ignore */	    return;	default:			/* Other */	    if (c == CMDQ) {		/* Backslash escape */		int x;		kbp = kbuf;		*kbp++ = c;		while (((c = (congks(0) & cmdmsk)) != '\r') && (c != '\n'))		  *kbp++ = c;		*kbp = NUL; kbp = kbuf;		x = xxesc(&kbp);	/* Interpret it */		if (x >= 0) {		/* No key mapping here */		    c = dopar((CHAR) x);		    ttoc((char) c);		    return;		} else {		/* Invalid backslash code. */		    conoc(BEL);		    return;		}	    }	    conoc(BEL); return; 	/* Invalid esc arg, beep */    	}    }}VOID#ifdef CK_ANSIClogchar(char c)#elselogchar(c) char c;#endif /* CK_ANSIC *//* logchar */ {			/* Log character c to session log */    if (seslog)       if ((sessft != 0) ||	  (c != '\r' &&	   c != '\0' &&	   c != XON &&	   c != XOFF))	if (zchout(ZSFILE,c) < 0) {	    conoll("");	    conoll("ERROR WRITING SESSION LOG, LOG CLOSED!");	    seslog = 0;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -