2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-12-23 16:44:18 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Fidonet mailer
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-28 11:34:24 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
contributed by Stanislav Voronyi <stas@uanet.kharkov.ua>
|
|
|
|
*/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "ttyio.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "emsi.h"
|
|
|
|
#include "lutil.h"
|
|
|
|
#include "openfile.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
#include "tcpproto.h"
|
|
|
|
|
|
|
|
|
2003-04-13 12:24:37 +00:00
|
|
|
#define TCP_CMD 0x87
|
|
|
|
#define TCP_DATA 0xe1
|
|
|
|
#define TCP_BLKSTRT 0xc6
|
|
|
|
#define TCP_BLKEND 0x6c
|
|
|
|
#define TCP_BLKSIZE 2048
|
|
|
|
#define TCP_DATSIZE 1024
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
static FILE *fout;
|
|
|
|
static FILE *in;
|
2003-04-13 12:24:37 +00:00
|
|
|
static char txbuf[TCP_BLKSIZE];
|
|
|
|
static char rxbuf[TCP_BLKSIZE];
|
2001-08-17 05:46:24 +00:00
|
|
|
static int rx_type;
|
2002-04-04 20:58:04 +00:00
|
|
|
static long sbytes;
|
|
|
|
struct timeval starttime, endtime;
|
|
|
|
struct timezone tz;
|
2001-08-25 19:53:11 +00:00
|
|
|
static off_t rxbytes;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-08-25 19:53:11 +00:00
|
|
|
static int sendtfile(char *,char *);
|
2001-08-17 05:46:24 +00:00
|
|
|
static int finsend(void);
|
|
|
|
static int receivefile(char *,time_t,off_t);
|
|
|
|
static int resync(off_t);
|
|
|
|
static int closeit(int);
|
|
|
|
static int tcp_sblk(char *,int,int);
|
|
|
|
static int tcp_rblk(char *,int *);
|
|
|
|
static int getsync(void);
|
|
|
|
|
|
|
|
extern unsigned long sentbytes;
|
|
|
|
extern unsigned long rcvdbytes;
|
|
|
|
extern char *ttystat[];
|
|
|
|
|
|
|
|
|
|
|
|
int tcpsndfiles(file_list *lst)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc = 0, maxrc = 0;
|
|
|
|
file_list *tmpf;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
Syslog('+', "TCP: start send files");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (getsync()) {
|
|
|
|
WriteError("TCP: can't get synchronization");
|
|
|
|
return MBERR_FTRANSFER;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
for (tmpf = lst; tmpf && (maxrc == 0); tmpf = tmpf->next) {
|
|
|
|
if (tmpf->remote) {
|
|
|
|
rc = sendtfile(tmpf->local,tmpf->remote);
|
|
|
|
rc = abs(rc);
|
|
|
|
if (rc > maxrc)
|
2001-08-17 05:46:24 +00:00
|
|
|
maxrc=rc;
|
2003-04-12 18:36:43 +00:00
|
|
|
if (rc == 0)
|
|
|
|
execute_disposition(tmpf);
|
2002-10-20 20:58:55 +00:00
|
|
|
} else
|
2003-04-12 18:36:43 +00:00
|
|
|
if (maxrc == 0)
|
|
|
|
execute_disposition(tmpf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxrc < 2) {
|
|
|
|
rc = finsend();
|
|
|
|
rc = abs(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc > maxrc)
|
|
|
|
maxrc=rc;
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
WriteError("TCP: send error: rc=%d",maxrc);
|
|
|
|
return MBERR_FTRANSFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Syslog('+', "TCP: send files completed");
|
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tcprcvfiles(void)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc, bufl;
|
|
|
|
long filesize, filetime;
|
2003-12-06 16:35:33 +00:00
|
|
|
char *filename = NULL, *p;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
Syslog('+', "TCP: start receive files");
|
|
|
|
if (getsync()) {
|
|
|
|
WriteError("TCP: can't get synchronization");
|
|
|
|
return MBERR_FTRANSFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
if ((rc = tcp_rblk(rxbuf, &bufl)) == 0) {
|
|
|
|
if (strncmp(rxbuf, "SN", 2) == 0) {
|
|
|
|
rc = tcp_sblk((char *)"RN", 2, TCP_CMD);
|
|
|
|
return rc;
|
|
|
|
} else if (*rxbuf == 'S') {
|
|
|
|
p = strchr(rxbuf+2, ' ');
|
|
|
|
if (p != NULL)
|
|
|
|
*p=0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
filename = xstrcpy(rxbuf+2);
|
|
|
|
p++;
|
|
|
|
filesize = strtol(p, &p, 10);
|
|
|
|
filetime = strtol(++p, (char **)NULL, 10);
|
|
|
|
} else
|
|
|
|
return rc==0?1:rc;
|
|
|
|
|
2003-12-06 16:35:33 +00:00
|
|
|
if (strlen(filename) && filesize && filetime) {
|
2003-04-12 18:36:43 +00:00
|
|
|
rc = receivefile(filename,filetime,filesize);
|
2003-12-06 16:35:33 +00:00
|
|
|
if (filename)
|
|
|
|
free(filename);
|
|
|
|
filename = NULL;
|
|
|
|
}
|
2003-04-12 18:36:43 +00:00
|
|
|
|
|
|
|
if (fout) {
|
|
|
|
if (closeit(0))
|
|
|
|
WriteError("TCP: error closing file");
|
|
|
|
(void)tcp_sblk((char *)"FERROR",6,TCP_CMD);
|
2002-10-20 20:58:55 +00:00
|
|
|
} else
|
2003-04-12 18:36:43 +00:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
WriteError("TCP: receive error: rc=%d", rc);
|
|
|
|
return MBERR_FTRANSFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Syslog('+', "TCP: receive files completed");
|
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-25 19:53:11 +00:00
|
|
|
static int sendtfile(char *ln, char *rn)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc=0;
|
|
|
|
struct stat st;
|
|
|
|
struct flock fl;
|
|
|
|
int bufl, sverr;
|
|
|
|
long offset;
|
|
|
|
|
|
|
|
fl.l_type = F_RDLCK;
|
|
|
|
fl.l_whence = 0;
|
|
|
|
fl.l_start = 0L;
|
|
|
|
fl.l_len = 0L;
|
|
|
|
|
|
|
|
if ((in = fopen(ln,"r")) == NULL) {
|
|
|
|
sverr = errno;
|
|
|
|
if ((sverr == ENOENT) || (sverr == EINVAL)) {
|
|
|
|
Syslog('+', "TCP: file %s doesn't exist, removing", MBSE_SS(ln));
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
WriteError("$TCP: can't open file %s, skipping", MBSE_SS(ln));
|
|
|
|
return 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-04-12 18:36:43 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (fcntl(fileno(in), F_SETLK, &fl) != 0) {
|
|
|
|
WriteError("$TCP: can't lock file %s, skipping", MBSE_SS(ln));
|
|
|
|
fclose(in);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (stat(ln, &st) != 0) {
|
|
|
|
WriteError("$TCP: can't access \"%s\", skipping", MBSE_SS(ln));
|
|
|
|
fclose(in);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (st.st_size > 0) {
|
|
|
|
Syslog('+', "TCP: send \"%s\" as \"%s\"", MBSE_SS(ln), MBSE_SS(rn));
|
|
|
|
Syslog('+', "TCP: size %lu bytes, dated %s", (unsigned long)st.st_size, date(st.st_mtime));
|
|
|
|
gettimeofday(&starttime, &tz);
|
|
|
|
} else {
|
|
|
|
Syslog('+', "TCP: file \"%s\" has 0 size, skiped",ln);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-08-28 13:45:26 +00:00
|
|
|
snprintf(txbuf,TCP_BLKSIZE, "S %s %lu %lu",rn,(unsigned long)st.st_size,(unsigned long)st.st_mtime+(st.st_mtime%2));
|
2003-04-12 18:36:43 +00:00
|
|
|
bufl = strlen(txbuf);
|
|
|
|
rc = tcp_sblk(txbuf, bufl, TCP_CMD);
|
|
|
|
rc = tcp_rblk(rxbuf, &bufl);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (strncmp(rxbuf,"RS",2) == 0) {
|
|
|
|
Syslog('+', "TCP: file %s already received, skipping",rn);
|
|
|
|
return 0;
|
|
|
|
} else if (strncmp(rxbuf,"RN",2) == 0) {
|
|
|
|
Syslog('+', "TCP: remote refused file, aborting",rn);
|
|
|
|
return 2;
|
|
|
|
} else if (strncmp(rxbuf,"ROK",3) == 0) {
|
|
|
|
if (bufl > 3 && rxbuf[3]==' ') {
|
|
|
|
offset = strtol(rxbuf+4,(char **)NULL,10);
|
|
|
|
if (fseek(in,offset,SEEK_SET) != 0) {
|
|
|
|
WriteError("$TCP: can't seek offset %ld in file %s", offset, ln);
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
} else
|
2003-04-12 18:36:43 +00:00
|
|
|
offset = 0;
|
|
|
|
} else
|
|
|
|
return rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-13 12:24:37 +00:00
|
|
|
while ((bufl = fread(&txbuf, 1, TCP_DATSIZE, in)) != 0) {
|
2003-04-12 18:36:43 +00:00
|
|
|
if ((rc = tcp_sblk(txbuf, bufl, TCP_DATA)) > 0)
|
|
|
|
break;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
fclose(in);
|
|
|
|
if (rc == 0){
|
|
|
|
strcpy(txbuf, "EOF");
|
|
|
|
rc = tcp_sblk(txbuf, 3, TCP_CMD);
|
|
|
|
rc = tcp_rblk(rxbuf, &bufl);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (rc == 0 && strncmp(rxbuf,"FOK",3) == 0) {
|
|
|
|
gettimeofday(&endtime, &tz);
|
|
|
|
Syslog('a', "st_size %d, offset %d",st.st_size,offset);
|
|
|
|
Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, st.st_size-offset, TRUE));
|
|
|
|
sentbytes += (unsigned long)st.st_size - offset;
|
|
|
|
return 0;
|
|
|
|
} else if(strncmp(rxbuf,"FERROR",6) == 0){
|
|
|
|
WriteError("TCP: remote file error",ln);
|
|
|
|
return rc==0?1:rc;
|
|
|
|
} else
|
|
|
|
return rc==0?1:rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int resync(off_t off)
|
|
|
|
{
|
2005-08-28 13:45:26 +00:00
|
|
|
snprintf(txbuf, TCP_BLKSIZE, "ROK %ld",(long)off);
|
2003-04-12 18:36:43 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int closeit(int success)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc;
|
|
|
|
|
2003-08-23 14:57:51 +00:00
|
|
|
rc = closefile();
|
2003-04-12 18:36:43 +00:00
|
|
|
fout = NULL;
|
|
|
|
sbytes = rxbytes - sbytes;
|
|
|
|
gettimeofday(&endtime, &tz);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, sbytes, FALSE));
|
|
|
|
else
|
|
|
|
Syslog('+', "TCP: dropped after %ld bytes", sbytes);
|
|
|
|
rcvdbytes += sbytes;
|
|
|
|
return rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int finsend(void)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc,bufl;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
rc = tcp_sblk((char *)"SN",2,TCP_CMD);
|
|
|
|
if(rc)
|
|
|
|
return rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
rc = tcp_rblk(rxbuf,&bufl);
|
|
|
|
if (strncmp(rxbuf, "RN", 2) == 0)
|
|
|
|
return rc;
|
|
|
|
else
|
|
|
|
return 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int receivefile(char *fn, time_t ft, off_t fs)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int rc, bufl;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
Syslog('+', "TCP: receive \"%s\" (%lu bytes) dated %s",fn,fs,date(ft));
|
|
|
|
strcpy(txbuf,"ROK");
|
|
|
|
fout = openfile(fn, ft, fs, &rxbytes, resync);
|
|
|
|
gettimeofday(&starttime, &tz);
|
|
|
|
sbytes = rxbytes;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (fs == rxbytes) {
|
|
|
|
Syslog('+', "TCP: skipping %s", fn);
|
|
|
|
fout = NULL;
|
|
|
|
rc = tcp_sblk((char *)"RS",2,TCP_CMD);
|
|
|
|
return rc;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (!fout)
|
|
|
|
return 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
bufl = strlen(txbuf);
|
|
|
|
rc = tcp_sblk(txbuf,bufl,TCP_CMD);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
while ((rc = tcp_rblk(rxbuf, &bufl)) == 0) {
|
|
|
|
if (rx_type == TCP_CMD)
|
|
|
|
break;
|
|
|
|
if (fwrite(rxbuf, 1, bufl, fout) != bufl)
|
|
|
|
break;
|
|
|
|
rxbytes += bufl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if (rx_type == TCP_CMD && bufl == 3 && strncmp(rxbuf,"EOF",3) == 0) {
|
|
|
|
if (ftell(fout) == fs) {
|
|
|
|
closeit(1);
|
|
|
|
rc = tcp_sblk((char *)"FOK",3,TCP_CMD);
|
|
|
|
return rc;
|
|
|
|
} else
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
return 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int tcp_sblk(char *buf, int len, int typ)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
Nopper();
|
|
|
|
if (typ == TCP_CMD)
|
|
|
|
Syslog('a', "tcp_sblk: cmd: %s", buf);
|
|
|
|
else
|
|
|
|
Syslog('a', "tcp_sblk: data: %d bytes", len);
|
|
|
|
|
2003-04-13 12:24:37 +00:00
|
|
|
PUTCHAR(TCP_BLKSTRT);
|
2003-04-12 18:36:43 +00:00
|
|
|
PUTCHAR(typ);
|
|
|
|
PUTCHAR((len >> 8) & 0x0ff);
|
|
|
|
PUTCHAR(len & 0x0ff);
|
|
|
|
PUT(buf, len);
|
2003-04-13 12:24:37 +00:00
|
|
|
PUTCHAR(TCP_BLKEND);
|
2003-04-12 18:36:43 +00:00
|
|
|
FLUSHOUT();
|
|
|
|
|
|
|
|
if (tty_status)
|
|
|
|
WriteError("TCP: send error: %s", ttystat[tty_status]);
|
|
|
|
return tty_status;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int tcp_rblk(char *buf, int *len)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int c;
|
|
|
|
|
|
|
|
*len = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait up to 3 minutes for the header
|
|
|
|
*/
|
|
|
|
c = GETCHAR(180);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
2003-04-13 12:24:37 +00:00
|
|
|
if (c != TCP_BLKSTRT) {
|
2003-04-12 18:36:43 +00:00
|
|
|
WriteError("tcp_rblk: got %d instead of block header", c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get block type
|
|
|
|
*/
|
|
|
|
c = GETCHAR(120);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
|
|
|
rx_type = c;
|
|
|
|
if (c != TCP_CMD && c != TCP_DATA) {
|
|
|
|
WriteError("tcp_rblk: got %d character instead of DATA/CMD", c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get block length
|
|
|
|
*/
|
|
|
|
c = GETCHAR(120);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
|
|
|
*len = c << 8;
|
|
|
|
c = GETCHAR(120);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
|
|
|
*len += c;
|
|
|
|
|
2003-04-13 12:24:37 +00:00
|
|
|
if (*len > TCP_BLKSIZE) {
|
2003-04-12 18:36:43 +00:00
|
|
|
WriteError("TCP: remote sends too large block: %d bytes", len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get actual data block
|
|
|
|
*/
|
2003-04-13 12:24:37 +00:00
|
|
|
if (*len != 0) {
|
|
|
|
GET(buf, *len, 120);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
|
|
|
} else {
|
|
|
|
WriteError("TCP: remote sends empty frame");
|
|
|
|
}
|
2003-04-12 18:36:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get block trailer
|
|
|
|
*/
|
|
|
|
c = GETCHAR(120);
|
|
|
|
if (tty_status)
|
|
|
|
goto to;
|
2003-04-13 12:24:37 +00:00
|
|
|
if (c != TCP_BLKEND) {
|
|
|
|
WriteError("TCP: got %d instead of block trailer", c);
|
2003-04-12 18:36:43 +00:00
|
|
|
return c;
|
2003-04-13 12:24:37 +00:00
|
|
|
}
|
2003-04-12 18:36:43 +00:00
|
|
|
|
|
|
|
if (rx_type == TCP_CMD) {
|
|
|
|
buf[*len] = '\0';
|
|
|
|
Syslog('a', "tcp_rblk: cmd: %s", buf);
|
|
|
|
} else
|
|
|
|
Syslog('a', "tcp_rblk: data: %d bytes", *len);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
to:
|
2003-04-12 18:36:43 +00:00
|
|
|
if (tty_status)
|
|
|
|
WriteError("TCP: receive error: %s", ttystat[tty_status]);
|
|
|
|
return tty_status;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int getsync(void)
|
|
|
|
{
|
2003-04-12 18:36:43 +00:00
|
|
|
int c;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
PUTCHAR(0xaa);
|
|
|
|
PUTCHAR(0x55);
|
|
|
|
FLUSHOUT();
|
|
|
|
Syslog('a', "getsync try to synchronize");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
gs:
|
2003-04-12 18:36:43 +00:00
|
|
|
if (tty_status) {
|
|
|
|
WriteError("TCP: getsync failed %s", ttystat[tty_status]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
while ((c = GETCHAR(120)) != 0xaa)
|
2001-08-17 05:46:24 +00:00
|
|
|
if (tty_status) {
|
2003-04-12 18:36:43 +00:00
|
|
|
WriteError("TCP: getsync failed: %s", ttystat[tty_status]);
|
|
|
|
return 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
if ((c = GETCHAR(120)) != 0x55)
|
|
|
|
goto gs;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-04-12 18:36:43 +00:00
|
|
|
Syslog('a', "getsync done, tty_status %s", ttystat[tty_status]);
|
|
|
|
return tty_status;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|