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

📄 ckucns.c

📁 KERMIT工具 这在办公室下载不了,很多人都没有载不到.
💻 C
📖 第 1 页 / 共 5 页
字号:
	return h_errno;    }    debug(F111,"socketpair","socket",servsock);    memset(&serv_addr, 0, sizeof(serv_addr));    serv_addr.sin_family = AF_INET;    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);    serv_addr.sin_port = htons(0);    val = sizeof(serv_addr);    if (bind(servsock, (struct sockaddr *) &serv_addr, val) < 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","bind",0);    listen(servsock, 1);    debug(F111,"socketpair","listen",0);    if (getsockname(servsock, (struct sockaddr *) &serv_addr, &val) < 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","getsockname",0);    pair[0] = socket(AF_INET, SOCK_STREAM, 0);    if (pair[0] == 0) {	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","socket",pair[0]);    memset(&cli_addr, 0, sizeof(cli_addr));    cli_addr.sin_family = AF_INET;    cli_addr.sin_addr.s_addr = inet_addr(myipaddr[0]?myipaddr:"127.0.0.1");    cli_addr.sin_port = serv_addr.sin_port;    if (connect(pair[0],(struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0) {	closesocket(pair[0]);	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","connect",0);    pair[1] = accept(servsock, (struct sockaddr *) &serv_addr, &val);    if (pair[1] == 0) {	closesocket(pair[0]);	closesocket(servsock);	return h_errno;    }    debug(F111,"socketpair","accept",pair[1]);    closesocket(servsock);    debug(F111,"socketpair","closesocket",0);    return 0;}longkbdread(void * param) {    int sock = (int) param;    char ch;    int rc = 0;    debug(F111,"kbdread","sock",sock);    while (rc >= 0) {	rc = read(fileno(stdin), &ch, 1); /* Read a character. */	if (rc > 0) {	    rc = send(sock,&ch,1,0);	    /* debug(F000,"kbdread","send()",ch); */	    printf("\r\ngot: %c rc = %d\r\n",ch,rc);	} else	  msleep(100);    }    debug(F110,"kbdread","terminating",0);    return(rc);}#endif /* BEBOX */#ifdef CKLEARNstatic VOIDlearnchar(c) int c; {			/* Learned script keyboard character */    int cc;    char xbuf[8];    if (!learning || !learnfp)      return;    switch (learnst) {			/* Learn state... */      case 0:				/* Neutral */      case 1:				/* Net */	if (learnbc > 0) {		/* Have net characters? */	    char buf[LEARNBUFSIZ];	    int i, j, n;	    ULONG t;	    t = (ULONG) time(0);	/* Calculate INPUT timeout */	    j = t - learnt1;	    j += (j / 4) > 0 ? (j / 4) : 1; /* Add some slop */	    if (j < 2) j = 2;		    /* 2 seconds minimum */	    fputs("\nINPUT ",learnfp);	/* Give INPUT command for them */	    fputs(ckitoa(j),learnfp);	    fputs(" {",learnfp);	    learnt1 = t;	    n = LEARNBUFSIZ;	    if (learnbc < LEARNBUFSIZ) {  /* Circular buffer */		n = learnbc;		  /*  hasn't wrapped yet. */		learnbp = 0;	    }	    j = 0;			/* Copy to linear buffer */	    for (i = 0; i < n; i++) {	/* Number of chars in circular buf */		cc = learnbuf[(learnbp + i) % LEARNBUFSIZ];		/* Later account for prompts that end with a newline? */		if (cc == CR && j > 0) {		    if (buf[j-1] != LF)		      j = 0;		}		buf[j++] = cc;	    }	    for (i = 0; i < j; i++) {	/* Now copy out the buffer */		cc = buf[i];		/* interpreting control chars */		if (cc == 0) {		/* We don't INPUT NULs */		    continue;		} else if (cc < SP ||	/* Controls need quoting */			   (cc > 126 && cc < 160)) {		    ckmakmsg(xbuf,8,"\\{",ckitoa((int)cc),"}",NULL);		    fputs(xbuf,learnfp);		} else {		/* Plain character */		    putc(cc,learnfp);		}	    }	    fputs("}\nIF FAIL STOP 1 INPUT timeout",learnfp);	    learnbc = 0;	}	learnbp = 0;	fputs("\nPAUSE 1\nOUTPUT ",learnfp); /* Emit OUTPUT and fall thru */      case 2:				/* Already in Keyboard state */	if (c == 0) {	    fputs("\\N",learnfp);	} else if (c == -7) {	    fputs("\\B",learnfp);	} else if (c == -8) {	    fputs("\\L",learnfp);	} else if (c < SP || (c > 126 && c < 160)) {	    ckmakmsg(xbuf,8,"\\{",ckitoa((int)c),"}",NULL);	    fputs(xbuf,learnfp);	} else {	    putc(c,learnfp);	}    }}#endif /* CKLEARN */static int printbar = 0;#define OUTXBUFSIZ 15static CHAR inxbuf[OUTXBUFSIZ+1];	/* Host-to-screen expansion buffer */static int inxcount = 0;		/* and count */static CHAR outxbuf[OUTXBUFSIZ+1];	/* Keyboard-to-host expansion buf */static int outxcount = 0;		/* and count */intconect() {    int rc = 0;				/* Return code: 0 = fail, 1 = OK */    int i, x = 0, prev = -1;		/* Reason code in cx_status */#ifdef CKLEARN    int crflag = 0;#endif /* CKLEARN */    register int c = -1, c2, csave;	/* Characters */#ifdef TNCODE    int tx;				/* For Telnet negotiations */#endif /* TNCODE */    int apcrc = 0;			/* For APC and transparent print */    int n, kbin, scrnout;		/* select() items... */    fd_set in, out, err;		/* File descriptor sets */    int gotnet = 0;			/* Flag for net ready to read */    int gotkbd = 0;			/* Flag for keyboard ready to read */    int oldprt = 0;			/* Used with printing */    int msgflg = 0;    char cbuf[2];			/* Ditto */#ifdef BEBOX    int tid = 0;			/* Thread ID */    int pair[2];			/* Socket Pair */    CHAR ch;    CHAR buf[64];#endif /* BEBOX */    cx_status = CSX_INTERNAL;    debok = 1;#ifdef BEBOX    {	/* Create a socket pair to be used for the keyboard input */	if (socketpair(pair)) {	    debug(F110,"conect","unable to create socket pair",0);	    return(-1);	}	debug(F111,"connect","socket pair[0]",pair[0]);	debug(F111,"connect","socket pair[1]",pair[1]);	/* Assign one end of the socket to kbin */	kbin = pair[0];        tid = spawn_thread(kbdread,			   "Kbd to Socket Pair",			    B_NORMAL_PRIORITY,			   (void *)pair[1]			   );        resume_thread(tid);	debug(F110,"connect","tid",tid);    }#else /* BEBOX */    kbin = fileno(stdin);		/* stdin file descriptor */#endif /* BEBOX */    scrnout = fileno(stdout);		/* stdout file descriptor */#ifdef CK_TRIGGER    makestr(&triggerval,NULL);		/* Reset trigger */#endif /* CK_TRIGGER */#ifdef XPRINT    escbufc = 0;			/* Reset esc-sequence buffer */    escbuf[0] = NUL;#endif /* XPRINT */    cbuf[1] = NUL;    ttimoff();				/* Turn off any timer interrupts */    if (!local) {			/* Be sure we're not in remote mode */#ifdef NETCONN#ifdef NEWFTP	if (ftpisconnected())	  printf("Sorry, you can't CONNECT to an FTP server\n");	else#endif /* NEWFTP */	  printf("Sorry, you must SET LINE or SET HOST first\n");#else	printf("Sorry, you must SET LINE first\n");#endif /* NETCONN */	return(0);    }    if (speed < 0L && network == 0 && ttfdflg == 0) {	printf("Sorry, you must SET SPEED first\n");	return(0);    }#ifdef TCPSOCKET    if (network && !ttpipe && (nettype != NET_TCPB && nettype != NET_PTY)) {	printf("Sorry, network type not supported\n");	return(0);    }#endif /* TCPSOCKET */#ifdef DYNAMIC    if (!ibuf) {	if (!(ibuf = malloc(IBUFL+1))) { /* Allocate input line buffer */	    printf("Sorry, CONNECT input buffer can't be allocated\n");	    return(0);	} else {	    ibp = ibuf;	    ibc = 0;	}    }    if (!obuf) {	if (!(obuf = malloc(OBUFL+1))) { /* Allocate output line buffer */	    printf("Sorry, CONNECT output buffer can't be allocated\n");	    return(0);	} else {	    obp = obuf;	    obc = 0;	}    }    if (!kbuf) {	if (!(kbuf = malloc(KBUFL+1))) { /* Allocate keyboard input buffer */	    printf("Sorry, CONNECT keyboard buffer can't be allocated\n");	    return(0);	}    }    if (!temp) {	if (!(temp = malloc(TMPLEN+1))) { /* Allocate temporary buffer */	    printf("Sorry, CONNECT temporary buffer can't be allocated\n");	    return(0);	}    }#else    obp = obuf;    obc = 0;#endif /* DYNAMIC */    kbp = kbuf;				/* Always clear these. */    *kbp = NUL;				/* No need to preserve them between */    kbc = 0;				/* CONNECT sessions. */#ifdef DEBUG    if (deblog) {	debug(F101,"CONNECT conect entry ttyfd","",ttyfd);	debug(F101,"CONNECT conect entry ibc","",ibc);	debug(F101,"CONNECT conect entry obc","",obc);	debug(F101,"CONNECT conect entry kbc","",kbc);#ifdef CK_TRIGGER	debug(F110,"CONNECT conect trigger",tt_trigger[0],0);#endif /* CK_TRIGGER */	if (ttyfd > -1) {	    n = ttchk();	    debug(F101,"CONNECT conect entry ttchk","",n);	}    }#endif /* DEBUG */    if (ttyfd < 0) {			/* If communication device not open */#ifdef TTLEBUF        int n = le_inbuf();        debug(F111,"CONNECT le_inbuf()","ttyfd < 0",n);        if (n > 0) {            while (n--) {                CHAR ch;                le_getchar(&ch);                conoc(ch);            }            return(0);        }#endif /* TTLEBUF */	debug(F101,"CONNECT ttnproto","",ttnproto);	debug(F111,"CONNECT opening",ttname,0); /* Open it now */	if (ttopen(ttname,		   &local,		   network ? -nettype : mdmtyp,		   0		   ) < 0) {	    ckmakmsg(temp,TMPLEN,"Sorry, can't open ",ttname,NULL,NULL);	    perror(temp);	    debug(F110,"CONNECT open failure",ttname,0);	    return(0);	}#ifdef IKS_OPTION	/* If peer is in Kermit server mode, return now. */	if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {	    cx_status = CSX_IKSD;	    return(0);	}#endif /* IKS_OPTION */    }    dohangup = 0;			/* Hangup not requested yet */    msgflg = !quiet#ifdef CK_APC      && !apcactive#endif /* CK_APC */	;    if (msgflg) {#ifdef NETCONN	if (network) {#ifdef CK_ENCRYPTION	    extern int me_encrypt, u_encrypt;	    if (ck_tn_encrypting() && ck_tn_decrypting())	      printf("SECURE connection to host %s",ttname);	    else#endif /* CK_ENCRYPTION */	      if (ttpipe || ttpty)		printf("Connecting via command \"%s\"",ttname);	      else		printf("Connecting to host %s",ttname);	} else {#endif /* NETCONN */	    printf("Connecting to %s",ttname);	    if (speed > -1L) printf(", speed %ld",speed);#ifdef NETCONN	}#endif /* NETCONN */	if (tt_escape) {	    printf("\r\n");	    shoesc(escape);	    printf("Type the escape character followed by C to get back,\r\n");	    printf("or followed by ? to see other options.\r\n");	} else {	    printf(".\r\n\nESCAPE CHARACTER IS DISABLED\r\n\n");	}	if (seslog) {	    extern int slogts;	    char * s = "";	    switch (sessft) {	      case XYFT_D:		s = "debug"; break;	      case XYFT_T:		s = slogts ? "timestamped-text" : "text"; break;	      default:		s = "binary";	    }	    printf("Session Log: %s, %s\r\n",sesfil,s);	}	if (debses) printf("Debugging Display...)\r\n");    }/* Condition console terminal and communication line */    if (conbin((char)escape) < 0) {	printf("Sorry, can't condition console terminal\n");	fflush(stdout);	return(0);    }    debug(F101,"CONNECT cmask","",cmask);    debug(F101,"CONNECT cmdmsk","",cmdmsk);    debug(F101,"CONNECT speed before ttvt","",speed);    if ((n = ttvt(speed,flow)) < 0) {	/* Enter "virtual terminal" mode */	if (!network) {	    debug(F101,"CONNECT ttvt","",n);	    tthang();			/* Hang up and close the device. */	    ttclos(0);	    dologend();	    if (ttopen(ttname,		/* Open it again... */		       &local,		       network ? -nettype : mdmtyp,		       0		       ) < 0) {		cx_status = CSX_INTERNAL;		ckmakmsg(temp,TMPLEN,"Sorry, can't reopen ",ttname,NULL,NULL);		perror(temp);		return(0);	    }#ifdef IKS_OPTION	    if (TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {		cx_status = CSX_IKSD;		return(0);	    }#endif /* IKS_OPTION */	    if (ttvt(speed,flow) < 0) {	/* Try virtual terminal mode again. */		conres();		/* Failure this time is fatal. */		printf("Sorry, Can't condition communication line\n");		cx_status = CSX_INTERNAL;		return(0);	    }	}    }    debug(F101,"CONNECT ttvt ok, escape","",escape);    /* Despite ttvt() this is still needed in HP-UX */    /* because of the HP-9000 <RESET> key.*/

⌨️ 快捷键说明

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