SOURCE CODE
(kermit_.h Module Description)
___ Called By:
Header_Files
___ Calls:
This module does not call other modules.
static char *sccsid = "@(#)Kermit version 3.1(0) 8/24/84";
/*
* K e r m i t File Transfer Utility
*
* UNIX Kermit, Columbia University, 1982, 1983, 1984
* Bill Catchings, Bob Cattani, Chris Maio, Frank da Cruz,
* Alan Crosswell, Jeff Damens
*
* Also: Jim Guyton, Rand Corporation
* Walter Underwood, Ford Aerospace
*
* usage: kermit c [lbphe line baud par escape-char] to connect
* kermit s [ddiflbpt line baud par] file ... to send files
* kermit r [ddiflbpt line baud par] to receive files
*
* where c=connect, s=send, r=receive,
* d=debug, i=image mode, f=no filename conversion, l=tty line,
* b=baud rate, e=escape char, h=half duplex, t=turnaround char,
* p=parity, z=log packet transactions.
*
* For remote Kermit, format is either:
* kermit r to receive files
* or kermit s file ... to send files
*
*/
/*
* Modification History:
*
* Aug 84 David Mutterer - Add definition for UNIX System 5 Version 2.
*
* July 84 Bill Catchings and Jeff Damens - Add necessary commands for
* communicating with IBM mainframes (t,p,h). Also started to
* make it more modular. Eventually all conditionals should be
* removed. After that we will go to a LEX version which will
* implement all the states needed for a full server version. A
* command parser is also needed. Limited VAX VMS support was also
* added (no connect command). Link together KERMIT.C, KER%%%.C
* (UNX for all present UNIX versions, VMS for VAX VMS) and KERCN%.C
* (V for Venix on the Pro and U for UNIX this module not used for
* VMS).
*
* May 21 84 - Roy Smith (CUCS), strip parity from checksum in rpack()
*
* Oct. 17 Included fixes from Alan Crosswell (CUCCA) for IBM_UTS:
* - Changed MYEOL character from \\n to \\r.
* - Change char to int in bufill so getc would return -1 on
* EOF instead of 255 (-1 truncated to 8 bits)
* - Added read() in rpack to eat the EOL character
* - Added fflush() call in printmsg to force the output
* NOTE: The last three changes are not conditionally compiled
* since they should work equally well on any system.
*
* Changed Berkeley 4.x conditional compilation flag from
* UNIX4X to UCB4X.
* Added support for error packets and cleaned up the printing
* routines.
*/
/* Conditional compilation for different machines/operating systems */
/* One and only one of the following lines should be 1 */
#define UCB4X 1 /* Berkeley 4.x UNIX */
#define TOPS_20 0 /* TOPS-20 */
#define IBM_UTS 0 /* Amdahl UTS on IBM systems */
#define VAX_VMS 0 /* VAX/VMS */
#define S5V2 0 /* AT&T 5.2 UNIX */
/* Conditional compilation for the different Unix variants */
/* 0 means don't compile it, nonzero means do */
#if UCB4X
#define V6_LIBS 0 /* Dont't use retrofit libraries */
#define NO_FIONREAD 0 /* We have ioctl(FIONREAD,...) for flushinput() */
#define NO_TANDEM 0 /* We have TANDEM line discipline (xon/xoff) */
#endif
#if IBM_UTS
#define V6_LIBS 0 /* Don't use retrofit libraries */
#define NO_FIONREAD 1 /* No ioctl(FIONREAD,...) for flushinput() */
#define NO_TANDEM 1 /* No TANDEM line discipline (xon/xoff) */
#endif
#if TOPS_20
#define V6_LIBS 0 /* Don't use retrofit libraries */
#define NO_FIONREAD 1 /* No ioctl(FIONREAD,...) for flushinput() */
#define NO_TANDEM 1 /* No TANDEM line discipline (xon/xoff) */
#endif
#if VAX_VMS
#define V6_LIBS 0 /* Don't use retrofit libraries */
#define NO_FIONREAD 1 /* No ioctl(FIONREAD,...) for flushinput() */
#define NO_TANDEM 1 /* No TANDEM line discipline (xon/xoff) */
#endif
#if S5V2
#define UCB4X 1
#define V6_LIBS 0 /* Dont't use retrofit libraries */
#define NO_FIONREAD 1 /* We have ioctl(FIONREAD,...) for flushinput() */
#define NO_TANDEM 1 /* We have TANDEM line discipline (xon/xoff) */
#endif
#include <stdio.h> /* Standard UNIX definitions */
#include <ctype.h>
#if V6_LIBS
#include <retrofit/sgtty.h>
#include <retrofit/signal.h>
#include <retrofit/setjmp.h>
#else
#include <signal.h>
#include <setjmp.h>
#endif
#if !(V6_LIBS | VAX_VMS)
#include <sgtty.h>
#endif
#if NO_TANDEM
#define TANDEM 0 /* define it to be nothing if it's unsupported */
#endif
/* Symbol Definitions */
#define MAXPACKSIZ 94 /* Maximum packet size */
#define SOH 1 /* Start of header */
#define CR 13 /* ASCII Carriage Return */
#define SP 32 /* ASCII space */
#define DEL 127 /* Delete (rubout) */
#define XON 17 /* ASCII XON */
#define MAXTRY 10 /* Times to retry a packet */
#define MYQUOTE '#' /* Quote character I will use */
#define MYPAD 0 /* Number of padding characters I will need */
#define MYPCHAR 0 /* Padding character I need (NULL) */
#define MYTIME 10 /* Seconds after which I should be timed out */
#define MAXTIM 60 /* Maximum timeout interval */
#define MINTIM 2 /* Minumum timeout interval */
#define TRUE -1 /* Boolean constants */
#define FALSE 0
#define DEFESC '^' /* Default escape character for CONNECT */
#define DEFTRN FALSE /* Default turn around */
#define DEFLCH FALSE /* Default local echo */
#define DEFPAR FALSE /* Default parity */
#define DEFIM FALSE /* Default image mode */
#if UCB4X | VAX_VMS | IBM_UTS
#define DEFFNC TRUE /* Default file name conversion */
#else
#define DEFFNC FALSE
#endif
#if IBM_UTS | VAX_VMS
#define MYEOL '\\r' /* End-Of-Line character for UTS or VMS systems */
#else
#define MYEOL '\\n' /* End-Of-Line character I need */
#endif
/* Macro Definitions */
/*
* tochar: converts a control character to a printable one by adding a space.
*
* unchar: undoes tochar.
*
* ctl: converts between control characters and printable characters by
* toggling the control bit (ie. ^A becomes A and A becomes ^A).
*
* unpar: turns off the parity bit.
*/
#define tochar(ch) ((ch) + ' ')
#define unchar(ch) ((ch) - ' ')
#define ctl(ch) ((ch) ^ 64 )
#define unpar(ch) ((ch) & 127)
/* Conditional Global Variables */
#if VAX_VMS
int confd, /* FD of the controlling terminal */
ttnam, /* Line name pointer */
oldtty[4],
oldcon[4];
#else
struct sgttyb
oldtty; /* Controlling tty raw mode */
#endif
#include <stdio.h>
#include <ctype.h>
/* Global Variables */
int size, /* Size of present data */
rpsiz, /* Maximum receive packet size */
spsiz, /* Maximum send packet size */
pad, /* How much padding to send */
timint, /* Timeout for foreign host on sends */
n, /* Packet number */
numtry, /* Times this packet retried */
oldtry, /* Times previous packet retried */
ttyfd, /* File descriptor of tty for I/O, 0 if remote */
remote, /* -1 means we're a remote kermit */
image, /* -1 means 8-bit mode */
parflg, /* TRUE means use parity specified */
turn, /* TRUE means look for turnaround char (XON) */
lecho, /* TRUE for locally echo chars in connect mode */
debug, /* Indicates level of debugging output (0=none) */
pktdeb, /* TRUE means log all packet to a file */
filnamcnv, /* -1 means do file name case conversions */
speed, /* speed to set */
filecount; /* Number of files left to send */
char state, /* Present state of the automaton */
cchksum, /* Our (computed) checksum */
padchar, /* Padding character to send */
eol, /* End-Of-Line character to send */
escchr, /* Connect command escape character */
quote, /* Quote character in incoming data */
**filelist, /* List of files to be sent */
*filnam, /* Current file name */
recpkt[MAXPACKSIZ], /* Receive packet buffer */
packet[MAXPACKSIZ]; /* Packet buffer */
FILE *fp, /* File pointer for current disk file */
*dpfp; /* File pointer for debugging packet log file */
jmp_buf env; /* Environment ptr for timeout longjump */
/*
* m a i n
*
* Main routine - parse command and options, set up the
* tty lines, and dispatch to the appropriate routine.
*/