📄 ckctel.c
字号:
printf("?Telnet waiting for SB %s MODEM_STATUS negotiation\r\n", TELOPT(TELOPT_COMPORT)); debug(F111,"tn_outst","ComPort SB MS in progress",TELOPT_COMPORT); outstanding = 1; } } }#endif /* TN_COMPORT */ return(outstanding);}intistncomport() {#ifdef TN_COMPORT if (!local) return(0); if (ttnet != NET_TCPB) return(0); if (ttnproto != NP_TELNET) return(0); if (TELOPT_ME(TELOPT_COMPORT)) return(1); else#endif /* TN_COMPORT */ return(0);}/* tn_wait() -- Wait for response to Telnet negotiation. *//* Wait for up to <timeout> seconds for the response to arrive. Place all non-telnet data into Telnet Wait Buffer. If response does arrive return 1, else return 0.*/#ifndef TN_WAIT_BUF_SZ#define TN_WAIT_BUF_SZ 4096#endif /* TN_WAIT_BUF_SZ */static char tn_wait_buf[TN_WAIT_BUF_SZ];static int tn_wait_idx = 0;#ifndef TN_TIMEOUT#define TN_TIMEOUT 120#endif /* TN_TIMEOUT */static int tn_wait_tmo = TN_TIMEOUT;#ifdef CKSPINNERVOIDprtwait(state) int state; { switch (state % 4) { case 0: printf("/"); break; case 1: printf("-"); break; case 2: printf("\\"); break; case 3: printf("|"); break; }}#endif /* CKSPINNER */static int nflag = 0;int#ifdef CK_ANSICtn_wait(char * where)#elsetn_wait(where) char * where;#endif /* CK_ANSIC *//* tn_wait */ { extern int ckxech, local; int ch = 0, count = 0;#ifndef NOHINTS int nohintgiven = 1; extern int hints;#endif /* NOHINTS */ int outstanding;#ifdef TN_COMPORT int savcarr; extern int ttcarr;#endif /* TN_COMPORT */ rtimer(); debug(F110,"tn_wait waiting for",where,0); tn_wait_tmo = TN_TIMEOUT; debug(F111,"tn_wait","timeout",tn_wait_tmo); outstanding = tn_outst(0); debug(F111,"tn_wait","outstanding",outstanding); debug(F111,"tn_wait","tn_wait_flg",tn_wait_flg); /* The following is meant to be !(||). We only want to return */ /* immediately if both the tn_wait_flg && tn_outst() are false */ if (!(outstanding || tn_wait_flg)) /* If no need to wait */ return(1); /* Don't. */ if (tn_deb || debses) tn_debug("<wait for outstanding negotiations>");#ifdef CKSPINNER if (!sstelnet && !quiet) prtwait(0);#endif /* CKSPINNER */ /* Wait up to TN_TIMEOUT sec for responses to outstanding telnet negs */ do {#ifdef NTSIG ck_ih();#endif /* NTSIG */ ch = ttinc(1); if (ch == -1) { /* Timed out */ if (!sstelnet && !quiet) { /* Let user know... */#ifdef CKSPINNER printf("\b"); prtwait(gtimer());#else if (nflag == 0) { printf(" Negotiations."); nflag++; } if (nflag > 0) { printf("."); nflag++; fflush(stdout); }#endif /* CKSPINNER */ } } else if (ch < -1) { printf("\r\n?Connection closed by peer.\r\n"); if (tn_deb || debses) tn_debug("<connection closed by peer>"); return(-1); } else switch (ch) { case IAC:#ifdef CKSPINNER if (!sstelnet && !quiet) printf("\b");#endif /* CKSPINNER */ ch = tn_doop((CHAR)(ch & 0xff),inserver?ckxech:duplex,ttinc);#ifdef CKSPINNER if (!sstelnet && !quiet) { prtwait(gtimer()); }#endif /* CKSPINNER */ debug(F101,"tn_wait tn_doop","",ch); switch (ch) { case 1: duplex = 1; /* Turn on echoing */ if (inserver) ckxech = 1; break; case 2: duplex = 0; /* Turn off echoing */ if (inserver) ckxech = 0; break; case 3: tn_wait_buf[tn_wait_idx++] = IAC; break; case 4: /* IKS event */ case 6: /* Logout */ break; case -1: if (!quiet) printf("?Telnet Option negotiation error.\n"); if (tn_deb || debses) tn_debug("<Telnet Option negotiation error>"); return(-1); case -2: printf("?Connection closed by peer.\n"); if (tn_deb || debses) tn_debug("<Connection closed by peer>"); ttclos(0); return(-2); default: if (ch < 0) { if (tn_deb || debses) tn_debug("<Unknown connection error>"); return(ch); } } /* switch */ break; default:#ifdef CKSPINNER if (!sstelnet && !quiet) { printf("\b"); prtwait(gtimer()); }#endif /* CKSPINNER */ tn_wait_buf[tn_wait_idx++] = (CHAR)(ch & 0xff); } /* switch */ outstanding = tn_outst(0); if ( outstanding && ch != IAC ) { int timer = gtimer(); if ( timer > tn_wait_tmo ) { if (!sstelnet) { printf( "\r\n?Telnet Protocol Timeout - connection closed\r\n"); if (tn_deb || debses) tn_debug( "<telnet protocol timeout - connection closed>"); tn_outst(1); } /* if we do not close the connection, then we will block */ /* the next time we hit a wait. and if we don't we will */ /* do the wrong thing if the host sends 0xFF and does */ /* not intend it to be an IAC. */ ttclos(0); whyclosed = WC_TELOPT; return(-1); }#ifndef NOHINTS else if ( hints && timer > 30 && nohintgiven && !inserver ) {#ifdef CKSPINNER printf("\b");#else /* CKSPINNER */ printf("\r\n");#endif /* CKSPINNER */ printf("*************************\r\n"); printf("The Telnet %s is not sending required responses.\r\n\r\n", sstelnet?"client":"server"); tn_outst(1); printf("\nYou can continue to wait or you can cancel with Ctrl-C.\r\n"); printf("In case the Telnet server never responds as required,\r\n"); printf("you can try connecting to this host with TELNET /NOWAIT.\r\n"); printf("Use SET HINTS OFF to suppress further hints.\r\n"); printf("*************************\r\n"); nohintgiven = 0; }#endif /* NOHINTS */ }#ifdef TN_COMPORT /* Must disable carrier detect check if we are using Telnet Comport */ savcarr = ttcarr; ttscarr(CAR_OFF); count = ttchk(); ttscarr(savcarr);#else /* TN_COMPORT */ count = ttchk();#endif /* TN_COMPORT */ } while ((tn_wait_idx < TN_WAIT_BUF_SZ) && (outstanding && count >= 0)); if (tn_wait_idx == TN_WAIT_BUF_SZ) { if (tn_deb || debses) tn_debug("<Telnet Wait Buffer filled>"); return(0); } if (!sstelnet && !quiet) {#ifdef CKSPINNER printf("\b \b");#else if (nflag > 0) { printf(" (OK)\n"); nflag = -1; }#endif /* CKSPINNER */ } if (tn_deb || debses) tn_debug("<no outstanding negotiations>"); return(0);}/* Push data from the Telnet Wait Buffer into the I/O Queue *//* Return 1 on success */inttn_push() {#ifdef NETLEBUF extern int tt_push_inited;#endif /* NETLEBUF */ if (tn_wait_idx) { hexdump((CHAR *)"tn_push",tn_wait_buf,tn_wait_idx);#ifdef NETLEBUF if (!tt_push_inited) /* Local handling */ le_init(); le_puts((CHAR *)tn_wait_buf,tn_wait_idx);#else /* External handling... */#ifdef OS2 /* K95 has its own way */ le_puts((CHAR *)tn_wait_buf,tn_wait_idx);#else#ifdef TTLEBUF /* UNIX, etc */ le_puts((CHAR *)tn_wait_buf,tn_wait_idx);#else/* If you see this message in AOS/VS, OS-9, VOS, etc, you need to copy the #ifdef TTLEBUF..#endif code from ckutio.c to the corresponding places in your ck?tio.c module.*/ printf("tn_push called but not implemented - data lost.\n");#endif /* TTLEBUF */#endif /* OS2 */#endif /* NETLEBUF */ tn_wait_idx = 0; } tn_wait_tmo = TN_TIMEOUT; /* Reset wait timer stats */ return(1);}/* T N _ S O P T *//* Sends a telnet option, avoids loops. Returns 1 if command was sent, 0 if not, -1 on error.*/inttn_sopt(cmd,opt) int cmd, opt; { /* TELNET SEND OPTION */ CHAR buf[5]; char msg[128]; int rc; if (ttnet != NET_TCPB) return(-1); /* Must be TCP/IP */ if (ttnproto != NP_TELNET) return(-1); /* Must be telnet protocol */ if (!TELCMD_OK(cmd)) return(-1); if (TELOPT_OK(opt)) { if (cmd == DO && TELOPT_UNANSWERED_DO(opt)) return(0); if (cmd == WILL && TELOPT_UNANSWERED_WILL(opt)) return(0); if (cmd == DONT && TELOPT_UNANSWERED_DONT(opt)) return(0); if (cmd == WONT && TELOPT_UNANSWERED_WONT(opt)) return(0); }#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) { return(0); }#endif /* CK_SSL */ if (cmd == DO && opt == TELOPT_AUTHENTICATION) buf[0] = 0; if (tn_infinite && TELOPT_OK(opt)) { /* See comment above about */ int index = TELOPT_INDEX(opt); /* preventing infinite loops */ int m = cmd - WILL; if (tncnts[index][m] > MAXTNCNT) {#ifdef DEBUG if (tn_deb || debses || deblog) { ckmakmsg(msg,sizeof(msg), "TELNET negotiation loop ", TELCMD(cmd), " ", TELOPT(opt)); debug(F101,msg,"",opt); if (tn_deb || debses) tn_debug(msg); }#endif /* DEBUG */ return(0); } tncnts[index][m]++; tncnts[index][tnopps[m]] = 0; } buf[0] = (CHAR) IAC; buf[1] = (CHAR) (cmd & 0xff); buf[2] = (CHAR) (opt & 0xff); buf[3] = (CHAR) 0;#ifdef DEBUG if ((tn_deb || debses || deblog) && cmd != SB) ckmakmsg(msg,sizeof(msg),"TELNET SENT ",TELCMD(cmd)," ", TELOPT(opt));#endif /* DEBUG */#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif debug(F101,msg,"",opt); if ((tn_deb || debses) && cmd != SB) tn_debug(msg); rc = (ttol(buf,3) < 3);#ifdef OS2 ReleaseTelnetMutex();#endif if (rc) return(-1); if (TELOPT_OK(opt)) { if (cmd == DONT && TELOPT_UNANSWERED_DO(opt)) TELOPT_UNANSWERED_DO(opt) = 0; if (cmd == WONT && TELOPT_UNANSWERED_WILL(opt)) TELOPT_UNANSWERED_WILL(opt) = 0; if (cmd == DO && TELOPT_UNANSWERED_DONT(opt)) TELOPT_UNANSWERED_DONT(opt) = 0; if (cmd == WILL && TELOPT_UNANSWERED_WONT(opt)) TELOPT_UNANSWERED_WONT(opt) = 0; } return(1);}/* Send a telnet sub-option *//* Returns 1 if command was sent, 0 if not, -1 on error */inttn_ssbopt(opt,sub,data,len) int opt, sub; CHAR * data; int len; { CHAR buf[256]; int n,m,rc; if (ttnet != NET_TCPB) return(0); /* Must be TCP/IP */ if (ttnproto != NP_TELNET) return(0); /* Must be telnet protocol */ if (!TELOPT_OK(opt)) return(-1); if (len < 0 || len > 250) { debug(F111,"Unable to Send TELNET SB - data too long","len",len); return(-1); /* Data too long */ }#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) { if (ttchk() < 0) return(-1); else return(1); }#endif /* CK_SSL */ if (!data) len = 0; buf[0] = (CHAR) IAC; buf[1] = (CHAR) (SB & 0xff); buf[2] = (CHAR) (opt & 0xff); buf[3] = (CHAR) (sub & 0xff); if (data && len > 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -