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

📄 ckcfn2.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#define NEWDPL/*  C K C F N 2  --  System-independent Kermit protocol support functions... *//*  ...Part 2 (continued from ckcfns.c)  *//*  Author: Frank da Cruz <fdc@columbia.edu>,  Columbia University Academic Information Systems, New York City.  Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New  York.  The C-Kermit software may not be, in whole or in part, licensed or  sold for profit as a software product itself, nor may it be included in or  distributed with commercial products or otherwise distributed by commercial  concerns to their clients or customers without written permission of the  Office of Kermit Development and Distribution, Columbia University.  This  copyright notice must not be removed, altered, or obscured.*//* Note -- if you change this file, please amend the version number and date at the top of ckcfns.c accordingly.*/#include "ckcsym.h"			/* Compilation options */#include "ckcdeb.h"			/* Debugging and other symbols */#include "ckcasc.h"			/* ASCII symbols */#include "ckcker.h"			/* Kermit symbols */#include "ckcxla.h"			/* Translation */#ifdef TCPSOCKET			/* For TELNET business in spack() */#ifndef NP_TELNET			/* Avoid dragging in ckcnet.h */#define NP_TELNET  1#define TNL_CR     0			/* CR sends bare carriage return */#define TNL_CRNUL  1			/* CR and NUL */#define TNL_CRLF   2			/* CR and LF */#define TNL_LF     3			/* LF instead of CR */#endif /* NP_TELNET */extern int tn_nlm, ttnproto;extern int me_binary, tn_b_nlm;#endif /* TCPSOCKET */#ifdef DYNAMICextern struct pktinfo *s_pkt;		/* array of pktinfo structures */extern struct pktinfo *r_pkt;		/* array of pktinfo structures */#elseextern struct pktinfo s_pkt[];		/* array of pktinfo structures */extern struct pktinfo r_pkt[];		/* array of pktinfo structures */#endif /* DYNAMIC */extern int sseqtbl[], rseqtbl[], sbufuse[], sacktbl[], wslots, winlo,  sbufnum, rbufnum, pktpaus;extern int ttprty;			/* from ck*tio.c */extern int autopar;extern int spsiz, spmax, rpsiz, timint, timef, npad, bestlen, maxsend;extern int rpt, rptq, rptflg, capas, spsizf, en_fin, tsecs, network, flow;extern int pktnum, sndtyp, rcvtyp, bctr, bctu, bctl, rsn, rln, maxtry, size;extern int osize, maxsize, spktl, rpktl, nfils, stdouf, warn, parity;extern int turn, turnch,  delay, displa, pktlog, tralog, seslog, xflg, mypadn;extern int hcflg, local, server, cxseen, czseen, discard, slostart;extern int nakstate, quiet, success, xitsta, what;extern int spackets, rpackets, timeouts, retrans, crunched, urpsiz;extern long filcnt, filrej, ffc, flci, flco, tlci, tlco, tfc, speed;extern char *cmarg, filnam[], *hlptxt;extern CHAR padch, mypadc, eol, seol, ctlq, sstate;extern CHAR *recpkt, *data, myinit[];extern CHAR *srvptr, stchr, mystch, *rdatap;extern CHAR padbuf[];#ifdef pdp11  extern CHAR srvcmd[];  extern CHAR *pktmsg;#else#ifdef DYNAMIC  extern CHAR *srvcmd;  extern CHAR *pktmsg;#else  extern CHAR srvcmd[];  extern CHAR pktmsg[];#endif /* DYNAMIC */#endif /* pdp11 */int numerrs = 0;			/* Number of packet errors so far */int rcvtimo = 0;			/* Timeout for receiving a packet */#ifdef CK_TIMERSint rrttbl[64], srttbl[64];		/* Packet timestamp tables */extern int rttflg;#define RTT_SCALE 1000long  rttsamples,				/* Round trip time samples */  rttdelay,				/* RTT delay */  pktintvl,				/* Interpacket arrival time */  rttvariance,				/* RTT variance */  rttstddev;				/* RTT standard deviation */#endif /* CK_TIMERS */static CHAR p_tbl[] = {			/* Even parity table for dopar(). */    (CHAR) '\000',			/* ANSI C casts '\ooo' constants  */    (CHAR) '\201',			/* to signed char, so we have to  */    (CHAR) '\202',			/* cast back to unsigned char...  */    (CHAR) '\003',    (CHAR) '\204',    (CHAR) '\005',    (CHAR) '\006',    (CHAR) '\207',    (CHAR) '\210',    (CHAR) '\011',    (CHAR) '\012',    (CHAR) '\213',    (CHAR) '\014',    (CHAR) '\215',    (CHAR) '\216',    (CHAR) '\017',    (CHAR) '\220',    (CHAR) '\021',    (CHAR) '\022',    (CHAR) '\223',    (CHAR) '\024',    (CHAR) '\225',    (CHAR) '\226',    (CHAR) '\027',    (CHAR) '\030',    (CHAR) '\231',    (CHAR) '\232',    (CHAR) '\033',    (CHAR) '\234',    (CHAR) '\035',    (CHAR) '\036',    (CHAR) '\237',    (CHAR) '\240',    (CHAR) '\041',    (CHAR) '\042',    (CHAR) '\243',    (CHAR) '\044',    (CHAR) '\245',    (CHAR) '\246',    (CHAR) '\047',    (CHAR) '\050',    (CHAR) '\251',    (CHAR) '\252',    (CHAR) '\053',    (CHAR) '\254',    (CHAR) '\055',    (CHAR) '\056',    (CHAR) '\257',    (CHAR) '\060',    (CHAR) '\261',    (CHAR) '\262',    (CHAR) '\063',    (CHAR) '\264',    (CHAR) '\065',    (CHAR) '\066',    (CHAR) '\267',    (CHAR) '\270',    (CHAR) '\071',    (CHAR) '\072',    (CHAR) '\273',    (CHAR) '\074',    (CHAR) '\275',    (CHAR) '\276',    (CHAR) '\077',    (CHAR) '\300',    (CHAR) '\101',    (CHAR) '\102',    (CHAR) '\303',    (CHAR) '\104',    (CHAR) '\305',    (CHAR) '\306',    (CHAR) '\107',    (CHAR) '\110',    (CHAR) '\311',    (CHAR) '\312',    (CHAR) '\113',    (CHAR) '\314',    (CHAR) '\115',    (CHAR) '\116',    (CHAR) '\317',    (CHAR) '\120',    (CHAR) '\321',    (CHAR) '\322',    (CHAR) '\123',    (CHAR) '\324',    (CHAR) '\125',    (CHAR) '\126',    (CHAR) '\327',    (CHAR) '\330',    (CHAR) '\131',    (CHAR) '\132',    (CHAR) '\333',    (CHAR) '\134',    (CHAR) '\335',    (CHAR) '\336',    (CHAR) '\137',    (CHAR) '\140',    (CHAR) '\341',    (CHAR) '\342',    (CHAR) '\143',    (CHAR) '\344',    (CHAR) '\145',    (CHAR) '\146',    (CHAR) '\347',    (CHAR) '\350',    (CHAR) '\151',    (CHAR) '\152',    (CHAR) '\353',    (CHAR) '\154',    (CHAR) '\355',    (CHAR) '\356',    (CHAR) '\157',    (CHAR) '\360',    (CHAR) '\161',    (CHAR) '\162',    (CHAR) '\363',    (CHAR) '\164',    (CHAR) '\365',    (CHAR) '\366',    (CHAR) '\167',    (CHAR) '\170',    (CHAR) '\371',    (CHAR) '\372',    (CHAR) '\173',    (CHAR) '\374',    (CHAR) '\175',    (CHAR) '\176',    (CHAR) '\377'};/* CRC generation tables */long crcta[16] = { 0L, 010201L, 020402L, 030603L, 041004L,  051205L, 061406L, 071607L, 0102010L, 0112211L, 0122412L, 0132613L, 0143014L,  0153215L, 0163416L, 0173617L};long crctb[16] = { 0L, 010611L, 021422L, 031233L, 043044L,  053655L, 062466L, 072277L, 0106110L, 0116701L, 0127532L, 0137323L, 0145154L,  0155745L, 0164576L, 0174367L};#ifdef CK_TIMERS/*  Round-trip timer calculations adapted from Tim Kientzle's article,  "Improving Kermit Performance", Dr Dobb's Journal, February 1996.*//*  R T T I N I T  --  Initialize timers at start of transaction  */VOIDrttinit() {				/* Initialize round-trip timing */    int i;    rttsamples  = 0L;			/* Samples (packets) */    rttvariance = 0L;			/* Variance in delay */    rttdelay    = (long) timint * RTT_SCALE; /* Delay */    pktintvl    = (long) timint * RTT_SCALE; /* Delay */    rttstddev   = (long) timint * RTT_SCALE; /* Standard deviation of delay */    /* Tables of timestamps indexed by packet sequence number */    for (i = 0; i < 64; i++) {			rrttbl[i] = -1;			/* Time each packet was received */	srttbl[i] = -1;			/* Time each packet was sent */    }    rcvtimo = timint;			/* Initial timeout is what user said */}/*  G E T R T T  --  Get packet round trip time  *//*  Call with nakstate == 0 if file sender, nonzero if receiver,  and n == packet sequence number of the packet we just received.   Returns:  -1 on failure with rcvtimo set to timint (what the user said), or:   0 on success with rcvtimo set to dynamically calculated value:     1 <= rcvtimo <= timint * 3.*/intgetrtt(nakstate, n) int nakstate, n; {    long rttdiff;    extern int mintime, maxtime;    int x, y, yy, z = 0, zz = 0;	/* How long did it take to get here? */    rcvtimo = timint;			/* Default timeout is what user said */    if (timint == 0)			/* We're not timing out. */      return(0);    if (!rttflg)			/* Not supposed to be doing this? */      return(-1);			/*  So don't */    if (!RTT_SCALE)			/* Paranoia... */      return(-1);    /* rtimer() (reset timer) is not called until 1st data packet */    /* S (F [ A ] D* Z)* B */    /* NOTE: we calculate both the round-trip time AND the packet */    /* arrival rate.  We don't use the RTT for anything, we just display it. */    /* Timeouts are based on the packet arrival rate. */    if (spackets > 3) {			/* Don't start till 4th packet */	if (nakstate) {			/* File receiver */	    x = rrttbl[n];		     /* Time when I got packet n */	    y = rrttbl[n > 0 ? n - 1 : 63];  /* Time when I got packet n-1 */	    yy = srttbl[n > 0 ? n - 1 : 63]; /* Time when I sent ACK(n-1) */	    if (x > -1 && y > -1) {	/* Be careful */		z = x - y;		/* Packet rate */		zz = x - yy;		/* Round trip time */		debug(F101,"RTT RECV","",z);	    } else {			/* This shouldn't happen */		debug(F101,"RTT RECV ERROR spackets","",spackets);		debug(F101,"RTT RECV ERROR sequence","",n);		return(-1);	    }	} else {			/* File sender */	    x = rrttbl[n];		/* Time when I got ACK(n) */	    y = rrttbl[n > 0 ? n - 1 : 63]; /* Time when I got packet n-1 */	    yy = srttbl[n];		/* Time when I sent n */	    if (x > -1 && y > -1) {		z = x - y;		/* Packet rate */		zz = x - yy;		/* Round trip time */		debug(F101,"RTT SEND","",z);	    } else {		debug(F100,"RTT SEND ERROR","",0);		return(-1);	    }	}	if (z < 1)			/* For fast connections */	  z = RTT_SCALE / 2;		/* Convert to scale... */	else	  z *= RTT_SCALE;	if (zz < 1)			/* For fast connections */	  zz = RTT_SCALE / 2;		/* Convert to scale... */	else	  zz *= RTT_SCALE;	rttdelay = zz;			/* Round trip time of this packet */	if (rttsamples++ == 0L) {	/* First sample */	    pktintvl = z;	    rttdiff = 0;	} else {			/* Subsequent samples */	    long oldavg = pktintvl;	    long rttdiffsq;	    if (rttsamples > 30)	/* Use real average for first 30 */	      rttsamples = 30;		/*  then decaying average. */	    /* Average delay, difference squared, variance, std deviation */	    pktintvl += (z - pktintvl) / rttsamples;	    rttdiffsq = (z - oldavg) * (z - oldavg);	    rttvariance += (rttdiffsq - rttvariance) / rttsamples;	    debug(F101,"RTT stddev1","",rttstddev);	    if (rttstddev < 1L)		/* It can be zero, in which case */	      rttstddev = RTT_SCALE / 3; /* set it to something small... */	    rttstddev = (rttstddev + rttvariance / rttstddev) / 2;	}	debug(F101,"RTT stddev2","",rttstddev);	debug(F101,"RTT delay  ","",pktintvl);	rcvtimo = (pktintvl + (3L * rttstddev)) / RTT_SCALE + 1;	if (rpackets < 32)		/* Allow for slow start */	  rcvtimo += rcvtimo + 2;	else if (rpackets < 64)	  rcvtimo += rcvtimo / 2 + 1;	if (rcvtimo < mintime)		/* Lower bound */	  rcvtimo = mintime;	if (maxtime > 0) {		/* User specified an upper bound */	    if (rcvtimo > maxtime)	      rcvtimo = maxtime;	} else if (maxtime == 0) {	/* User didn't specify */	    if (rcvtimo > timint * 6)	      rcvtimo = timint * 6;	}	debug(F101,"RTT rcvtimo","",rcvtimo);    }    return(0);}#endif /* CK_TIMERS *//*  I N P U T  --  Attempt to read packet number 'pktnum'.  *//* This is the function that feeds input to Kermit's finite state machine, in the form of a character in the range 32-126, normally a packet type (uppercase letter) or pseudo-packet-type (lowercase letter). If a special start state is in effect, that state is returned as if it were the type of an incoming packet.*/intinput() {    int type, acktype;			/* Received packet type */    int x, y, k;			/* Workers */    int z, pi, nf;			/* Worker, packet index, NAK flag */    int nak2ack = 0;    debug(F101,"input sstate","",sstate);    debug(F101," nakstate","",nakstate);    debug(F000," sndtyp","",sndtyp);    while (1) {				/* Big loop... */	if (sstate != 0) {		/* If a start state is in effect, */	    type = sstate;		/* return it like a packet type, */	    sstate = 0;			/* and then nullify it. */	    numerrs = 0;		/* (PWP) no errors so far */	    return(type);	}		if (nakstate) {			/* This section for file receiver. */

⌨️ 快捷键说明

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