summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kermit.c91
-rw-r--r--main.c42
-rw-r--r--makefile2
-rw-r--r--unixio.c26
4 files changed, 98 insertions, 63 deletions
diff --git a/kermit.c b/kermit.c
index e041c71..d8d5644 100644
--- a/kermit.c
+++ b/kermit.c
@@ -57,8 +57,12 @@
/* See cdefs.h for meaning of STATIC, ULONG, and UCHAR */
+#ifdef F_AT
STATIC ULONG stringnum(UCHAR *, struct k_data *);
+#endif
+#ifndef RECVONLY
STATIC UCHAR * numstring(ULONG, UCHAR *, int, struct k_data *);
+#endif
int STATIC spkt(char, short, int, UCHAR *, struct k_data *);
int STATIC ack(struct k_data *, short, UCHAR * text);
int STATIC nak(struct k_data *, short, short);
@@ -72,21 +76,29 @@ int STATIC rpar(struct k_data *, char);
int STATIC decode(struct k_data *, struct k_response *, short, UCHAR *);
#ifdef F_AT
int STATIC gattr(struct k_data *, UCHAR *, struct k_response *);
+#ifndef RECVONLY
int STATIC sattr(struct k_data *, struct k_response *);
+#endif
#endif /* F_AT */
#ifndef RECVONLY
int STATIC sdata(struct k_data *, struct k_response *);
#endif /* RECVONLY */
void STATIC epkt(char *, struct k_data *);
+#ifndef RECVONLY
int STATIC getpkt(struct k_data *, struct k_response *);
int STATIC encstr(UCHAR *, struct k_data *, struct k_response *);
+#endif
+#if 0
void STATIC decstr(UCHAR *, struct k_data *, struct k_response *);
+#endif
+#ifndef RECVONLY
void STATIC encode(int, int, struct k_data *);
int STATIC nxtpkt(struct k_data *);
+#endif
int STATIC resend(struct k_data *);
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
int xerror(void);
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
int /* The kermit() function */
kermit(short f, /* Function code */
@@ -96,16 +108,19 @@ kermit(short f, /* Function code */
char *msg, /* Message for error packet */
struct k_response *r) { /* Response struct */
- int i, j, rc; /* Workers */
+ int i, rc; /* Workers */
int datalen; /* Length of packet data field */
UCHAR *p; /* Pointer to packet data field */
UCHAR *q; /* Pointer to data to be checked */
- UCHAR *s; /* Worker string pointer */
- UCHAR c, t; /* Worker chars */
+ UCHAR *s=0; /* Worker string pointer */
+#ifdef F_LP
+ UCHAR c; /* Worker chars */
+#endif
+ UCHAR t; /* Worker chars */
UCHAR pbc[4]; /* Copy of packet block check */
short seq, prev; /* Copies of sequence numbers */
- short chklen; /* Length of packet block check */
#ifdef F_CRC
+ short chklen; /* Length of packet block check */
unsigned int crc; /* 16-bit CRC */
#endif /* F_CRC */
int ok;
@@ -338,12 +353,13 @@ kermit(short f, /* Function code */
}
}
#else
- chklen = 1; /* Block check is always type 1 */
datalen = k->ipktinfo[r_slot].len - 3; /* Data length */
#endif /* F_CRC */
debug(DB_LOG,"bct",0,(k->bct));
debug(DB_LOG,"datalen",0,datalen);
- debug(DB_LOG,"chkalen",0,chklen);
+#ifdef F_CRC
+ debug(DB_LOG,"chklen",0,chklen);
+#endif
#ifdef F_CRC
for (i = 0; i < chklen; i++) /* Copy the block check */
@@ -359,9 +375,9 @@ kermit(short f, /* Function code */
case 1: /* Type 1, 6-bit checksum */
#endif /* F_CRC */
ok = (xunchar(*pbc) == chk1(q,k));
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
if (ok && xerror()) ok = 0;
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
if (!ok) {
freerslot(k,r_slot);
#ifdef RECVONLY
@@ -380,9 +396,9 @@ kermit(short f, /* Function code */
case 2: /* Type 2, 12-bit checksum */
i = xunchar(*pbc) << 6 | xunchar(pbc[1]);
ok = (i == chk2(q,k));
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
if (ok && xerror()) ok = 0;
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
if (!ok) { /* No match */
if (t == 'E') { /* Allow E packets to have type 1 */
int j;
@@ -412,12 +428,12 @@ kermit(short f, /* Function code */
| (xunchar(pbc[1]) << 6)
| (xunchar(pbc[2]));
ok = (crc == chk3(q,k));
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
if (ok && xerror()) {
ok = 0;
debug(DB_MSG,"CRC ERROR INJECTED",0,0);
}
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
if (!ok) {
debug(DB_LOG,"CRC ERROR t",0,t);
if (t == 'E') { /* Allow E packets to have type 1 */
@@ -863,17 +879,19 @@ chk3(UCHAR *pkt, struct k_data * k) {
STATIC int
spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) {
+#ifdef F_CRC
unsigned int crc; /* For building CRC */
- int i, j, lenpos, m, n, x; /* Workers */
+#endif
+ int i, j, lenpos; /* Workers */
UCHAR * s, * buf;
- debug(DB_LOG,"spkt len 1",0,len);
+ debug(DB_LOG,"spkt len",0,len);
if (len < 0) { /* Calculate data length ourselves? */
len = 0;
s = data;
while (*s++) len++;
+ debug(DB_LOG,"spkt len 2",0,len);
}
- debug(DB_LOG,"spkt len 2",0,len);
buf = k->opktbuf; /* Where to put packet (FOR NOW) */
i = 0; /* Packet buffer position */
@@ -950,7 +968,7 @@ spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) {
k->opktlen = i; /* Remember length for retransmit */
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
/* CORRUPT THE PACKET SENT BUT NOT THE ONE WE SAVE */
if (xerror()) {
UCHAR p[P_PKTLEN+8];
@@ -963,8 +981,9 @@ spkt(char typ, short seq, int len, UCHAR * data, struct k_data * k) {
return((*(k->txd))(k,p,k->opktlen)); /* Send it. */
}
debug(DB_PKT,"SPKT",(char *)&buf[1],0);
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
+ debug(DB_PKT,"SPKT",&buf[1],k->opktlen);
return((*(k->txd))(k,buf,k->opktlen)); /* Send it. */
}
@@ -974,6 +993,7 @@ STATIC int
nak(struct k_data * k, short seq, short slot) {
int rc;
rc = spkt('N', seq, 0, (UCHAR *)0, k);
+ debug(DB_LOG,"nak spkt rc",0,rc);
if (k->ipktinfo[slot].rtr++ > k->retry)
rc = X_ERROR;
return(rc);
@@ -1001,8 +1021,10 @@ ack(struct k_data * k, short seq, UCHAR * text) {
STATIC void
spar(struct k_data * k, UCHAR *s, int datalen) {
- int x, y;
- UCHAR c;
+ #if defined(F_LP) || defined(F_SW) || defined(F_AT) || defined(F_RS) || defined(F_LS)
+ int x;
+#endif
+ int y=0;
s--; /* Line up with field numbers. */
@@ -1048,7 +1070,9 @@ spar(struct k_data * k, UCHAR *s, int datalen) {
}
}
if (datalen >= 10) { /* Capability bits */
+#if defined(F_LP) || defined(F_SW) || defined(F_AT) || defined(F_RS) || defined(F_LS)
x = xunchar(s[10]);
+#endif
#ifdef F_LP /* Long packets */
if (!(x & CAP_LP))
@@ -1115,7 +1139,7 @@ rpar(struct k_data * k, char type) {
UCHAR *d;
int rc, len;
#ifdef F_CRC
- short b;
+ short b=0;
#endif /* F_CRC */
d = k->ack_s; /* Where to put it */
@@ -1191,7 +1215,7 @@ decode(struct k_data * k, struct k_response * r, short f, UCHAR *inbuf) {
unsigned int b8; /* 8th bit */
int rpt; /* Repeat count */
int rc; /* Return code */
- UCHAR *p;
+ UCHAR *p=0;
rc = X_OK;
rpt = 0; /* Initialize repeat count. */
@@ -1237,6 +1261,7 @@ decode(struct k_data * k, struct k_response * r, short f, UCHAR *inbuf) {
return(rc);
}
+#ifdef F_AT
STATIC ULONG /* Convert decimal string to number */
stringnum(UCHAR *s, struct k_data * k) {
long n;
@@ -1247,7 +1272,9 @@ stringnum(UCHAR *s, struct k_data * k) {
n = n * 10 + (*s++ - '0');
return(n);
}
+#endif
+#ifndef RECVONLY
STATIC UCHAR * /* Convert number to string */
numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) {
int i, x;
@@ -1271,6 +1298,7 @@ numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) {
}
return((UCHAR *)buf);
}
+#endif
#ifdef F_AT
@@ -1287,7 +1315,7 @@ numstring(ULONG n, UCHAR * buf, int buflen, struct k_data * k) {
STATIC int
gattr(struct k_data * k, UCHAR * s, struct k_response * r) {
- long fsize, fsizek; /* File size */
+ long fsize=-1L, fsizek=-1L; /* File size */
UCHAR c; /* Workers */
int aln, i, rc;
@@ -1345,11 +1373,12 @@ gattr(struct k_data * k, UCHAR * s, struct k_response * r) {
return(rc);
}
+#ifndef RECVONLY
#define ATTRLEN 48
STATIC int
sattr(struct k_data *k, struct k_response *r) { /* Build and send A packet */
- int i, x, aln;
+ int i, x;
short tmp;
long filelength;
UCHAR datebuf[DATE_MAX], * p;
@@ -1418,11 +1447,13 @@ sattr(struct k_data *k, struct k_response *r) { /* Build and send A packet */
debug(DB_LOG,"sattr k->xdata: ",k->xdata,0);
return(spkt('A',k->s_seq,-1,k->xdata,k));
}
+#endif
#endif /* F_AT */
+#ifndef RECVONLY
STATIC int
getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */
- int i, next, rpt, maxlen;
+ int i, next, maxlen;
static int c; /* PUT THIS IN STRUCT */
debug(DB_LOG,"getpkt k->s_first",0,(k->s_first));
@@ -1464,7 +1495,6 @@ getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */
if (k->s_first == -1)
return(k->size);
- rpt = 0; /* Initialize repeat counter. */
while (k->s_first > -1) { /* Until end of file or string... */
if (k->istring) {
next = *(k->istring)++;
@@ -1504,7 +1534,6 @@ getpkt(struct k_data *k, struct k_response *r) { /* Fill a packet from file */
return(k->size); /* EOF, return size. */
}
-#ifndef RECVONLY
STATIC int
sdata(struct k_data *k,struct k_response *r) { /* Send a data packet */
int len, rc;
@@ -1532,6 +1561,7 @@ epkt(char * msg, struct k_data * k) {
(void) spkt('E', 0, -1, (UCHAR *) msg, k);
}
+#ifndef RECVONLY
STATIC int /* Fill a packet from string s. */
encstr(UCHAR * s, struct k_data * k, struct k_response *r) {
k->s_first = 1; /* Start lookahead. */
@@ -1541,7 +1571,9 @@ encstr(UCHAR * s, struct k_data * k, struct k_response *r) {
k->s_first = 1; /* "Rewind" */
return(k->size); /* Return data field length */
}
+#endif
+#if 0
/* Decode packet data into a string */
STATIC void
@@ -1551,7 +1583,9 @@ decstr(UCHAR * s, struct k_data * k, struct k_response * r) {
*(k->ostring) = '\0'; /* Terminate with null */
k->ostring = (UCHAR *)0; /* Reset output string pointer */
}
+#endif
+#ifndef RECVONLY
STATIC void
encode(int a, int next, struct k_data * k) { /* Encode character into packet */
int a7, b8, maxlen;
@@ -1607,6 +1641,7 @@ nxtpkt(struct k_data * k) { /* Get next packet to send */
k->xdata = k->xdatabuf;
return(0);
}
+#endif
STATIC int
resend(struct k_data * k) {
diff --git a/main.c b/main.c
index 5bb398f..bbf1e7e 100644
--- a/main.c
+++ b/main.c
@@ -104,10 +104,10 @@ int check = 3; /* Block check */
int check = 1;
#endif /* F_CRC */
int remote = 1; /* 1 = Remote, 0 = Local */
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
int errorrate = 0; /* Simulated error rate */
int seed = 1234; /* Random number generator seed */
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
void
doexit(int status) {
@@ -134,10 +134,10 @@ usage() {
fprintf(stderr," -T Force text mode\n");
fprintf(stderr," -R Remote mode (vs local)\n");
fprintf(stderr," -L Local mode (vs remote)\n");
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
fprintf(stderr," -E <number> Simulated error rate (0-100)\n");
fprintf(stderr," -d Create debug.log\n");
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
fprintf(stderr," -h Help (this message)\n");
exit(FAILURE);
}
@@ -162,10 +162,10 @@ doarg(char c) { /* Command-line option parser */
struct stat statbuf;
xp = *xargv+1; /* Pointer for bundled args */
- while (c) {
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
if (errorrate) seed += (int)c;
-#endif /* DEBUG) */
+#endif /* SIMULATED_ERROR) */
+ while (c) {
switch (c) {
case 'r': /* Receive */
if (action) fatal("Conflicting actions",(char *)0,(char *)0);
@@ -183,9 +183,9 @@ doarg(char c) { /* Command-line option parser */
while (--xargc > 0) { /* Traverse the list */
xargv++;
s = *xargv;
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
if (errorrate) seed += (int)*s;
-#endif /* DEBUG) */
+#endif /* SIMULATED_ERROR */
if (**xargv == '-')
break;
errno = 0;
@@ -206,12 +206,12 @@ doarg(char c) { /* Command-line option parser */
#ifdef F_CRC
case 'b': /* Block-check type */
#endif /* F_CRC */
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
case 'E': /* Simulated error rate */
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
if (*(xp+1))
fatal("Invalid argument bundling",(char *)0,(char *)0);
- *xargv++, xargc--;
+ xargv++, xargc--;
if ((xargc < 1) || (**xargv == '-'))
fatal("Missing option argument",(char *)0,(char *)0);
s = *xargv;
@@ -224,12 +224,12 @@ doarg(char c) { /* Command-line option parser */
check = atoi(*xargv);
if (check < 1 || check > 5 || check == 4)
fatal("Invalid block check",(char *)0,(char *)0);
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
} else if (c == 'E') {
errorrate = atoi(*xargv);
if (errorrate > 100)
fatal("Invalid error rate",(char *)0,(char *)0);
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
}
break;
@@ -262,7 +262,7 @@ doarg(char c) { /* Command-line option parser */
case 'p': /* Parity */
if (*(xp+1))
fatal("Invalid argument bundling",(char *)0,(char *)0);
- *xargv++, xargc--;
+ xargv++; xargc--;
if ((xargc < 1) || (**xargv == '-'))
fatal("Missing parity",(char *)0,(char *)0);
switch(x = **xargv) {
@@ -292,9 +292,9 @@ doarg(char c) { /* Command-line option parser */
return(action);
}
-void
+int
main(int argc, char ** argv) {
- int status, rx_len, i, x;
+ int status, rx_len, x;
char c;
UCHAR *inbuf;
short r_slot;
@@ -319,10 +319,10 @@ main(int argc, char ** argv) {
if (!action) /* Nothing to do, give usage message */
usage();
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
debug(DB_LOG,"SIMULATED ERROR RATE:",0,errorrate);
if (errorrate) srand(seed); /* Init random error generator */
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */
/* THE REAL STUFF IS FROM HERE DOWN */
@@ -432,8 +432,8 @@ main(int argc, char ** argv) {
date, size, and bytes transferred so far. These can be used in a
file-transfer progress display, log, etc.
*/
- debug(DB_LOG,"NAME",r.filename ? (char *)r.filename : "(NULL)",0);
- debug(DB_LOG,"DATE",r.filedate ? (char *)r.filedate : "(NULL)",0);
+ debug(DB_LOG,"NAME",r.filename ? r.filename : (UCHAR *)"(NULL)",0);
+ debug(DB_LOG,"DATE",r.filedate ? r.filedate : (UCHAR *)"(NULL)",0);
debug(DB_LOG,"SIZE",0,r.filesize);
debug(DB_LOG,"STATE",0,r.status);
debug(DB_LOG,"SOFAR",0,r.sofar);
diff --git a/makefile b/makefile
index 090f83c..9bd1a25 100644
--- a/makefile
+++ b/makefile
@@ -29,7 +29,7 @@ cc:
#Build with gcc.
gcc:
- @UNAME=`uname` ; make "CC=gcc" "CC2=gcc" "CFLAGS=-D$$UNAME -O2" ek
+ @UNAME=`uname` ; make "CC=gcc" "CC2=gcc" "CFLAGS=-D$$UNAME -O0 -ggdb -Wall" ek
#Ditto but no debugging.
gccnd:
diff --git a/unixio.c b/unixio.c
index 5dd7843..62b81c6 100644
--- a/unixio.c
+++ b/unixio.c
@@ -80,13 +80,13 @@ dodebug(int fc, UCHAR * label, UCHAR * sval, long nval) {
if (fc != DB_OPN && !xdebug)
return;
if (!label)
- label = "";
+ label = (UCHAR *)"";
switch (fc) { /* Function code */
case DB_OPN: /* Open debug log */
if (dp) fclose(dp);
- if (!*label) label = "debug.log";
- dp = fopen(label,"w");
+ if (!*label) label = (UCHAR *)"debug.log";
+ dp = fopen((char *)label,"w");
if (!dp) {
dp = stderr;
} else {
@@ -239,7 +239,7 @@ inchk(struct k_data * k) {
int
readpkt(struct k_data * k, UCHAR *p, int len, int fc) {
- int x, n, max;
+ int x, n;
short flag;
UCHAR c;
/*
@@ -251,7 +251,7 @@ readpkt(struct k_data * k, UCHAR *p, int len, int fc) {
version might be driven by the value of the packet-length field.
*/
#ifdef DEBUG
- char * p2;
+ UCHAR * p2;
#endif /* DEBUG */
#ifdef F_CTRLC
@@ -353,7 +353,7 @@ openfile(struct k_data * k, UCHAR * s, int mode) {
switch (mode) {
case 1: /* Read */
- if (!(ifile = fopen(s,"r"))) {
+ if (!(ifile = fopen((char *)s,"r"))) {
debug(DB_LOG,"openfile read error",s,0);
return(X_ERROR);
}
@@ -365,7 +365,7 @@ openfile(struct k_data * k, UCHAR * s, int mode) {
return(X_OK);
case 2: /* Write (create) */
- ofile = creat(s,0644);
+ ofile = creat((char *)s,0644);
if (ofile < 0) {
debug(DB_LOG,"openfile write error",s,0);
return(X_ERROR);
@@ -429,10 +429,10 @@ fileinfo(struct k_data * k,
buf[0] = '\0';
if (buflen < 18)
return(X_ERROR);
- if (stat(filename,&statbuf) < 0)
+ if (stat((char *)filename,&statbuf) < 0)
return(X_ERROR);
timestamp = localtime(&(statbuf.st_mtime));
- sprintf(buf,"%04d%02d%02d %02d:%02d:%02d",
+ sprintf((char *)buf,"%04d%02d%02d %02d:%02d:%02d",
timestamp->tm_year + 1900,
timestamp->tm_mon + 1,
timestamp->tm_mday,
@@ -453,7 +453,7 @@ fileinfo(struct k_data * k,
*/
if (!mode) { /* File type determination requested */
int isbinary = 1;
- fp = fopen(filename,"r"); /* Open the file for scanning */
+ fp = fopen((char *)filename,"r"); /* Open the file for scanning */
if (fp) {
int n = 0, count = 0;
char c, * p;
@@ -605,7 +605,7 @@ closefile(struct k_data * k, UCHAR c, int mode) {
(c == 'D')) { /* This file was incomplete */
if (k->filename) {
debug(DB_LOG,"deleting incomplete",k->filename,0);
- unlink(k->filename); /* Delete it. */
+ unlink((char *)k->filename); /* Delete it. */
}
}
break;
@@ -615,7 +615,7 @@ closefile(struct k_data * k, UCHAR c, int mode) {
return(rc);
}
-#ifdef DEBUG
+#ifdef SIMULATED_ERROR
int xerror() {
unsigned int x;
extern int errorrate; /* Fix this - NO EXTERNS */
@@ -626,4 +626,4 @@ int xerror() {
debug(DB_LOG,"ERROR",0,(x < errorrate));
return(x < errorrate);
}
-#endif /* DEBUG */
+#endif /* SIMULATED_ERROR */