Changed mbcico raw ifcico protocol logging

This commit is contained in:
Michiel Broek 2003-04-12 18:36:43 +00:00
parent 821e1dc5b6
commit 4e6faee53c
3 changed files with 365 additions and 360 deletions

View File

@ -23,6 +23,7 @@ v0.37.3 09-Apr-2003.
mbcico: mbcico:
Removed some heavy debug code from ttyio functions to increase Removed some heavy debug code from ttyio functions to increase
throughput. throughput.
Standarized raw ifcico protocol logging.
lang: lang:
New language prompt number 17. New language prompt number 17.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Fidonet mailer * Purpose ...............: Fidonet mailer
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -55,84 +55,81 @@ extern int made_request;
int rxtcp(void) int rxtcp(void)
{ {
int rc = 0; int rc = 0;
fa_list *eff_remote, tmpl; fa_list *eff_remote, tmpl;
file_list *tosend = NULL, **tmpfl; file_list *tosend = NULL, **tmpfl;
Syslog('+', "Start TCP session"); Syslog('+', "TCP: inbound session start");
if (emsi_remote_lcodes & LCODE_NPU) { if (emsi_remote_lcodes & LCODE_NPU) {
Syslog('+', "Remote requested \"no pickup\", no send"); Syslog('+', "Remote requested \"no pickup\", no send");
eff_remote=NULL; eff_remote=NULL;
} else if (emsi_remote_lcodes & LCODE_PUP) { } else if (emsi_remote_lcodes & LCODE_PUP) {
Syslog('+', "Remote requested \"pickup primary\""); Syslog('+', "Remote requested \"pickup primary\"");
tmpl.addr=remote->addr; tmpl.addr=remote->addr;
tmpl.next=NULL; tmpl.next=NULL;
eff_remote=&tmpl; eff_remote=&tmpl;
} else } else
eff_remote=remote; eff_remote=remote;
tosend = create_filelist(eff_remote, (char *)ALL_MAIL, 0); tosend = create_filelist(eff_remote, (char *)ALL_MAIL, 0);
if ((rc=tcprcvfiles()) == 0) { if ((rc=tcprcvfiles()) == 0) {
if ((emsi_local_opts & OPT_NRQ) == 0) { if ((emsi_local_opts & OPT_NRQ) == 0) {
for (tmpfl = &tosend; *tmpfl; tmpfl = &((*tmpfl)->next)); for (tmpfl = &tosend; *tmpfl; tmpfl = &((*tmpfl)->next));
*tmpfl = respond_wazoo(); *tmpfl = respond_wazoo();
}
if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0))
rc = tcpsndfiles(tosend);
if ((rc == 0) && (made_request)) {
Syslog('+', "Freq was made, trying to receive files");
rc = tcprcvfiles();
}
} }
tidy_filelist(tosend,(rc == 0)); if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0))
rc = tcpsndfiles(tosend);
if (rc) if ((rc == 0) && (made_request)) {
WriteError("TCP session failed: rc=%d", rc); Syslog('+', "TCP: freq was made, trying to receive files");
else rc = tcprcvfiles();
Syslog('+', "TCP session completed"); }
return rc; }
tidy_filelist(tosend,(rc == 0));
if (rc)
WriteError("TCP: session failed: rc=%d", rc);
else
Syslog('+', "TCP: session completed");
return rc;
} }
int txtcp(void) int txtcp(void)
{ {
int rc=0; int rc=0;
file_list *tosend = NULL, *respond = NULL; file_list *tosend = NULL, *respond = NULL;
char *nonhold_mail; char *nonhold_mail;
Syslog('+', "Start TCP session"); Syslog('+', "TCP: outbound session start");
// if (localoptions & NOHOLD) nonhold_mail = (char *)ALL_MAIL;
nonhold_mail = (char *)ALL_MAIL; if (emsi_remote_lcodes & LCODE_HAT) {
// else Syslog('+', "Remote asked to \"hold all traffic\", no send");
// nonhold_mail = (char *)NONHOLD_MAIL; tosend=NULL;
if (emsi_remote_lcodes & LCODE_HAT) { } else
Syslog('+', "Remote asked to \"hold all traffic\", no send"); tosend = create_filelist(remote,nonhold_mail,0);
tosend=NULL;
} else
tosend = create_filelist(remote,nonhold_mail,0);
if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0)) if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0))
rc = tcpsndfiles(tosend); rc = tcpsndfiles(tosend);
if (rc == 0) if (rc == 0)
if ((rc = tcprcvfiles()) == 0) if ((rc = tcprcvfiles()) == 0)
if ((emsi_local_opts & OPT_NRQ) == 0) if ((emsi_local_opts & OPT_NRQ) == 0)
if ((respond = respond_wazoo())) if ((respond = respond_wazoo()))
rc = tcpsndfiles(respond); rc = tcpsndfiles(respond);
tidy_filelist(tosend,(rc == 0)); tidy_filelist(tosend,(rc == 0));
tidy_filelist(respond,0); tidy_filelist(respond,0);
if (rc) if (rc)
WriteError("TCP session failed: rc=%d", rc); WriteError("TCP: session failed: rc=%d", rc);
else else
Syslog('+', "TCP session completed"); Syslog('+', "TCP: session completed");
return rc; return rc;
} }

View File

@ -4,7 +4,7 @@
* Purpose ...............: Fidonet mailer * Purpose ...............: Fidonet mailer
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2001 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -79,403 +79,410 @@ extern char *ttystat[];
int tcpsndfiles(file_list *lst) int tcpsndfiles(file_list *lst)
{ {
int rc = 0, maxrc = 0; int rc = 0, maxrc = 0;
file_list *tmpf; file_list *tmpf;
Syslog('+', "Start TCP send%s",lst?"":" (dummy)"); Syslog('+', "TCP: start send files");
if (getsync()) { if (getsync()) {
WriteError("Can't get synchronization"); WriteError("TCP: can't get synchronization");
return MBERR_FTRANSFER; return MBERR_FTRANSFER;
} }
for (tmpf = lst; tmpf && (maxrc == 0); tmpf = tmpf->next) { for (tmpf = lst; tmpf && (maxrc == 0); tmpf = tmpf->next) {
if (tmpf->remote) { if (tmpf->remote) {
rc = sendtfile(tmpf->local,tmpf->remote); rc = sendtfile(tmpf->local,tmpf->remote);
rc = abs(rc); rc = abs(rc);
if (rc > maxrc) if (rc > maxrc)
maxrc=rc;
if (rc == 0)
execute_disposition(tmpf);
} else
if (maxrc == 0)
execute_disposition(tmpf);
}
if (maxrc < 2) {
rc = finsend();
rc = abs(rc);
}
if (rc > maxrc)
maxrc=rc; maxrc=rc;
if (rc == 0)
if (rc) { execute_disposition(tmpf);
WriteError("TCP send error: rc=%d",maxrc);
return MBERR_FTRANSFER;
} else } else
return 0; 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;
} }
int tcprcvfiles(void) int tcprcvfiles(void)
{ {
int rc, bufl; int rc, bufl;
long filesize, filetime; long filesize, filetime;
char *filename, *p; char *filename, *p;
Syslog('+', "TCP: start receive files");
if (getsync()) {
WriteError("TCP: can't get synchronization");
return MBERR_FTRANSFER;
}
Syslog('+', "Start TCP receive");
if (getsync()) {
WriteError("Can't get synchronization");
return MBERR_FTRANSFER;
}
next: next:
if ((rc = tcp_rblk(rxbuf, &bufl)) == 0) { if ((rc = tcp_rblk(rxbuf, &bufl)) == 0) {
if (strncmp(rxbuf, "SN", 2) == 0) { if (strncmp(rxbuf, "SN", 2) == 0) {
rc = tcp_sblk((char *)"RN", 2, TCP_CMD); rc = tcp_sblk((char *)"RN", 2, TCP_CMD);
return rc; return rc;
} else if (*rxbuf == 'S') { } else if (*rxbuf == 'S') {
p = strchr(rxbuf+2, ' '); p = strchr(rxbuf+2, ' ');
if (p != NULL) if (p != NULL)
*p=0; *p=0;
else else
return 1; return 1;
filename = xstrcpy(rxbuf+2); filename = xstrcpy(rxbuf+2);
p++; p++;
filesize = strtol(p, &p, 10); filesize = strtol(p, &p, 10);
filetime = strtol(++p, (char **)NULL, 10); filetime = strtol(++p, (char **)NULL, 10);
} else } else
return rc==0?1:rc; return rc==0?1:rc;
if (strlen(filename) && filesize && filetime) if (strlen(filename) && filesize && filetime)
rc = receivefile(filename,filetime,filesize); rc = receivefile(filename,filetime,filesize);
if (fout) { if (fout) {
if (closeit(0)) if (closeit(0))
WriteError("Error closing file"); WriteError("TCP: error closing file");
(void)tcp_sblk((char *)"FERROR",6,TCP_CMD); (void)tcp_sblk((char *)"FERROR",6,TCP_CMD);
} else
goto next;
}
if (rc) {
WriteError("TCP receive error: rc=%d", rc);
return MBERR_FTRANSFER;
} else } else
return 0; goto next;
}
if (rc) {
WriteError("TCP: receive error: rc=%d", rc);
return MBERR_FTRANSFER;
}
Syslog('+', "TCP: receive files completed");
return 0;
} }
static int sendtfile(char *ln, char *rn) static int sendtfile(char *ln, char *rn)
{ {
int rc=0; int rc=0;
struct stat st; struct stat st;
struct flock fl; struct flock fl;
int bufl, sverr; int bufl, sverr;
long offset; long offset;
fl.l_type = F_RDLCK; fl.l_type = F_RDLCK;
fl.l_whence = 0; fl.l_whence = 0;
fl.l_start = 0L; fl.l_start = 0L;
fl.l_len = 0L; fl.l_len = 0L;
if ((in = fopen(ln,"r")) == NULL) { if ((in = fopen(ln,"r")) == NULL) {
sverr = errno; sverr = errno;
if ((sverr == ENOENT) || (sverr == EINVAL)) { if ((sverr == ENOENT) || (sverr == EINVAL)) {
Syslog('+', "File %s doesn't exist, removing", MBSE_SS(ln)); Syslog('+', "TCP: file %s doesn't exist, removing", MBSE_SS(ln));
return 0; return 0;
} else {
WriteError("$tcpsend: cannot open file %s, skipping", MBSE_SS(ln));
return 1;
}
}
if (fcntl(fileno(in), F_SETLK, &fl) != 0) {
Syslog('+', "$tcpsend: cannot lock file %s, skipping", MBSE_SS(ln));
fclose(in);
return 1;
}
if (stat(ln, &st) != 0) {
Syslog('+', "$tcpsend: cannot access \"%s\", skipping", MBSE_SS(ln));
fclose(in);
return 1;
}
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 { } else {
Syslog('+', "File \"%s\" has 0 size, skiped",ln); WriteError("$TCP: can't open file %s, skipping", MBSE_SS(ln));
return 0; return 1;
}
sprintf(txbuf,"S %s %lu %lu",rn,(unsigned long)st.st_size,st.st_mtime+(st.st_mtime%2));
bufl = strlen(txbuf);
rc = tcp_sblk(txbuf, bufl, TCP_CMD);
rc = tcp_rblk(rxbuf, &bufl);
if (strncmp(rxbuf,"RS",2) == 0) {
Syslog('+', "File %s already received, skipping",rn);
return 0;
} else if (strncmp(rxbuf,"RN",2) == 0) {
Syslog('+', "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("$tcpsend cannot seek in file %s",ln);
return 1;
}
} else
offset = 0;
} else
return rc;
while ((bufl = fread(&txbuf, 1, 1024, in)) != 0) {
if ((rc = tcp_sblk(txbuf, bufl, TCP_DATA)) > 0)
break;
} }
}
if (fcntl(fileno(in), F_SETLK, &fl) != 0) {
WriteError("$TCP: can't lock file %s, skipping", MBSE_SS(ln));
fclose(in); fclose(in);
if (rc == 0){ return 1;
strcpy(txbuf, "EOF"); }
rc = tcp_sblk(txbuf, 3, TCP_CMD);
rc = tcp_rblk(rxbuf, &bufl);
}
if (rc == 0 && strncmp(rxbuf,"FOK",3) == 0) { if (stat(ln, &st) != 0) {
gettimeofday(&endtime, &tz); WriteError("$TCP: can't access \"%s\", skipping", MBSE_SS(ln));
Syslog('a', "st_size %d, offset %d",st.st_size,offset); fclose(in);
Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, st.st_size-offset, TRUE)); return 1;
sentbytes += (unsigned long)st.st_size - offset; }
return 0;
} else if(strncmp(rxbuf,"FERROR",6) == 0){ if (st.st_size > 0) {
WriteError("$tcpsend remote file error",ln); Syslog('+', "TCP: send \"%s\" as \"%s\"", MBSE_SS(ln), MBSE_SS(rn));
return rc==0?1:rc; 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;
}
sprintf(txbuf,"S %s %lu %lu",rn,(unsigned long)st.st_size,st.st_mtime+(st.st_mtime%2));
bufl = strlen(txbuf);
rc = tcp_sblk(txbuf, bufl, TCP_CMD);
rc = tcp_rblk(rxbuf, &bufl);
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;
}
} else } else
return rc==0?1:rc; offset = 0;
} else
return rc;
while ((bufl = fread(&txbuf, 1, 1024, in)) != 0) {
if ((rc = tcp_sblk(txbuf, bufl, TCP_DATA)) > 0)
break;
}
fclose(in);
if (rc == 0){
strcpy(txbuf, "EOF");
rc = tcp_sblk(txbuf, 3, TCP_CMD);
rc = tcp_rblk(rxbuf, &bufl);
}
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;
} }
static int resync(off_t off) static int resync(off_t off)
{ {
sprintf(txbuf,"ROK %ld",(long)off); sprintf(txbuf,"ROK %ld",(long)off);
return 0; return 0;
} }
static int closeit(int success) static int closeit(int success)
{ {
int rc; int rc;
rc = closefile(success); rc = closefile(success);
fout = NULL; fout = NULL;
sbytes = rxbytes - sbytes; sbytes = rxbytes - sbytes;
gettimeofday(&endtime, &tz); gettimeofday(&endtime, &tz);
if (success) if (success)
Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, sbytes, FALSE)); Syslog('+', "TCP: OK %s", transfertime(starttime, endtime, sbytes, FALSE));
else else
Syslog('+', "TCP: dropped after %ld bytes", sbytes); Syslog('+', "TCP: dropped after %ld bytes", sbytes);
rcvdbytes += sbytes; rcvdbytes += sbytes;
return rc; return rc;
} }
static int finsend(void) static int finsend(void)
{ {
int rc,bufl; int rc,bufl;
rc = tcp_sblk((char *)"SN",2,TCP_CMD); rc = tcp_sblk((char *)"SN",2,TCP_CMD);
if(rc) if(rc)
return rc; return rc;
rc = tcp_rblk(rxbuf,&bufl); rc = tcp_rblk(rxbuf,&bufl);
if (strncmp(rxbuf, "RN", 2) == 0) if (strncmp(rxbuf, "RN", 2) == 0)
return rc; return rc;
else else
return 1; return 1;
} }
static int receivefile(char *fn, time_t ft, off_t fs) static int receivefile(char *fn, time_t ft, off_t fs)
{ {
int rc, bufl; int rc, bufl;
Syslog('+', "TCP receive \"%s\" (%lu bytes) dated %s",fn,fs,date(ft)); Syslog('+', "TCP: receive \"%s\" (%lu bytes) dated %s",fn,fs,date(ft));
strcpy(txbuf,"ROK"); strcpy(txbuf,"ROK");
fout = openfile(fn, ft, fs, &rxbytes, resync); fout = openfile(fn, ft, fs, &rxbytes, resync);
gettimeofday(&starttime, &tz); gettimeofday(&starttime, &tz);
sbytes = rxbytes; sbytes = rxbytes;
if (fs == rxbytes) { if (fs == rxbytes) {
Syslog('+', "Skipping %s", fn); Syslog('+', "TCP: skipping %s", fn);
fout = NULL; fout = NULL;
rc = tcp_sblk((char *)"RS",2,TCP_CMD); rc = tcp_sblk((char *)"RS",2,TCP_CMD);
return rc; return rc;
} }
if (!fout) if (!fout)
return 1; return 1;
bufl = strlen(txbuf); bufl = strlen(txbuf);
rc = tcp_sblk(txbuf,bufl,TCP_CMD); rc = tcp_sblk(txbuf,bufl,TCP_CMD);
while ((rc = tcp_rblk(rxbuf, &bufl)) == 0) { while ((rc = tcp_rblk(rxbuf, &bufl)) == 0) {
if (rx_type == TCP_CMD) if (rx_type == TCP_CMD)
break; break;
if (fwrite(rxbuf, 1, bufl, fout) != bufl) if (fwrite(rxbuf, 1, bufl, fout) != bufl)
break; break;
rxbytes += bufl; rxbytes += bufl;
} }
if (rc) if (rc)
return rc; return rc;
if (rx_type == TCP_CMD && bufl == 3 && strncmp(rxbuf,"EOF",3) == 0) { if (rx_type == TCP_CMD && bufl == 3 && strncmp(rxbuf,"EOF",3) == 0) {
if (ftell(fout) == fs) { if (ftell(fout) == fs) {
closeit(1); closeit(1);
rc = tcp_sblk((char *)"FOK",3,TCP_CMD); rc = tcp_sblk((char *)"FOK",3,TCP_CMD);
return rc; return rc;
} else } else
return 1; return 1;
} else } else
return 1; return 1;
} }
static int tcp_sblk(char *buf, int len, int typ) static int tcp_sblk(char *buf, int len, int typ)
{ {
Nopper(); Nopper();
if (typ == TCP_CMD) if (typ == TCP_CMD)
Syslog('a', "tcp_sblk: cmd: %s", buf); Syslog('a', "tcp_sblk: cmd: %s", buf);
else else
Syslog('a', "tcp_sblk: data: %d bytes", len); Syslog('a', "tcp_sblk: data: %d bytes", len);
PUTCHAR(0xc6); PUTCHAR(0xc6);
PUTCHAR(typ); PUTCHAR(typ);
PUTCHAR((len >> 8) & 0x0ff); PUTCHAR((len >> 8) & 0x0ff);
PUTCHAR(len & 0x0ff); PUTCHAR(len & 0x0ff);
PUT(buf, len); PUT(buf, len);
PUTCHAR(0x6c); PUTCHAR(0x6c);
FLUSHOUT(); FLUSHOUT();
if (tty_status)
WriteError("TCP send error: %s", ttystat[tty_status]); if (tty_status)
else WriteError("TCP: send error: %s", ttystat[tty_status]);
Syslog('A', "tcp_sblk: complete"); return tty_status;
return tty_status;
} }
static int tcp_rblk(char *buf, int *len) static int tcp_rblk(char *buf, int *len)
{ {
int c; int c;
Syslog('A', "tcp_rblk: start"); *len = 0;
*len = 0;
/* /*
* Wait up to 3 minutes for the header * Wait up to 3 minutes for the header
*/ */
c = GETCHAR(180); c = GETCHAR(180);
if (tty_status) if (tty_status)
goto to; goto to;
if (c != 0xc6) { if (c != 0xc6) {
WriteError("tcp_rblk: got %d instead of block header", c); WriteError("tcp_rblk: got %d instead of block header", c);
return c; return c;
} }
/* /*
* Get block type * Get block type
*/ */
c = GETCHAR(120); c = GETCHAR(120);
if (tty_status) if (tty_status)
goto to; goto to;
rx_type = c; rx_type = c;
if (c != TCP_CMD && c != TCP_DATA) { if (c != TCP_CMD && c != TCP_DATA) {
WriteError("tcp_rblk: got %d character instead of DATA/CMD", c); WriteError("tcp_rblk: got %d character instead of DATA/CMD", c);
return c; return c;
} }
/* /*
* Get block length * Get block length
*/ */
c = GETCHAR(120); c = GETCHAR(120);
if (tty_status) if (tty_status)
goto to; goto to;
*len = c << 8; *len = c << 8;
c = GETCHAR(120); c = GETCHAR(120);
if (tty_status) if (tty_status)
goto to; goto to;
*len += c; *len += c;
Syslog('A', "tcp_rblk: expecting %d bytes", *len);
/* if (*len > 2048) {
* Get actual data block WriteError("TCP: remote sends too large block: %d bytes", len);
*/ return 1;
GET(buf, *len, 120); }
if (tty_status)
goto to;
/* /*
* Get block trailer * Get actual data block
*/ */
c = GETCHAR(120); GET(buf, *len, 120);
if (tty_status) if (tty_status)
goto to; goto to;
if (c != 0x6c)
return c;
if (rx_type == TCP_CMD) { /*
buf[*len] = '\0'; * Get block trailer
Syslog('a', "tcp_rblk: cmd: %s", buf); */
} else c = GETCHAR(120);
Syslog('a', "tcp_rblk: data: %d bytes", *len); if (tty_status)
goto to;
if (c != 0x6c)
return c;
if (rx_type == TCP_CMD) {
buf[*len] = '\0';
Syslog('a', "tcp_rblk: cmd: %s", buf);
} else
Syslog('a', "tcp_rblk: data: %d bytes", *len);
to: to:
if (tty_status) if (tty_status)
WriteError("TCP receive error: %s", ttystat[tty_status]); WriteError("TCP: receive error: %s", ttystat[tty_status]);
return tty_status; return tty_status;
} }
static int getsync(void) static int getsync(void)
{ {
int c; int c;
PUTCHAR(0xaa); PUTCHAR(0xaa);
PUTCHAR(0x55); PUTCHAR(0x55);
FLUSHOUT(); FLUSHOUT();
Syslog('a', "getsync try to synchronize"); Syslog('a', "getsync try to synchronize");
gs: gs:
if (tty_status) {
WriteError("TCP: getsync failed %s", ttystat[tty_status]);
return 1;
}
while ((c = GETCHAR(120)) != 0xaa)
if (tty_status) { if (tty_status) {
WriteError("TCP getsync failed %s", ttystat[tty_status]); WriteError("TCP: getsync failed: %s", ttystat[tty_status]);
return 1; return 1;
} }
while ((c = GETCHAR(180)) != 0xaa)
if (tty_status) {
WriteError("TCP getsync failed: %s", ttystat[tty_status]);
return 1;
}
if ((c = GETCHAR(120)) != 0x55) if ((c = GETCHAR(120)) != 0x55)
goto gs; goto gs;
Syslog('a', "getsync done, tty_status %s", ttystat[tty_status]); Syslog('a', "getsync done, tty_status %s", ttystat[tty_status]);
return tty_status; return tty_status;
} }