M.Z. 20.08.2003
This commit is contained in:
42
tecs/six.c
42
tecs/six.c
@@ -54,7 +54,7 @@ int readWrite(int fd, int skip) {
|
||||
* a timeout occured (1 or 5 sec.), or a <go ahead> message
|
||||
* received.
|
||||
* skip=0: timeout 1 sec (normal behaviour)
|
||||
* skip>0: timeout 5 sec.
|
||||
* skip>0: timeout 10 sec.
|
||||
* skip>1: swallow text
|
||||
* skip=1,2: return 0 if SICS not found in message text
|
||||
* skip=3: return 0 if not acknowledged
|
||||
@@ -62,7 +62,7 @@ int readWrite(int fd, int skip) {
|
||||
n=0;
|
||||
go=0;
|
||||
ires=0;
|
||||
iret=term_wait_fd(fd, skip?5000:1000);
|
||||
iret=term_wait_fd(fd, skip?10000:1000);
|
||||
while (iret==1) {
|
||||
ERR_SI(l=recv(fd, msg, sizeof(msg)-1, 0));
|
||||
/* if (l==0) return(0); */
|
||||
@@ -86,18 +86,25 @@ int readWrite(int fd, int skip) {
|
||||
n+=strlen(msg);
|
||||
}
|
||||
if (go) break;
|
||||
iret=term_wait_fd(fd, skip?5000:1000);
|
||||
iret=term_wait_fd(fd, skip?10000:1000);
|
||||
}
|
||||
if (n==0 && ires==1) return 1;
|
||||
return ires*n;
|
||||
OnError: return -1;
|
||||
}
|
||||
|
||||
void Usage(void) {
|
||||
printf(" Usage:\n\n");
|
||||
printf(" six [options] [\"username\" \"password\"]\n\n");
|
||||
printf(" Options: -s simulation mode (on some instruments)\n");
|
||||
printf(" -w do not skip welcome message\n\n");
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
int iret, pos;
|
||||
fd_set mask;
|
||||
int fd, l, i, j, port, skip;
|
||||
char buf[128], lbuf[16], ibuf[64];
|
||||
char buf[128], lbuf[16], ibuf[64], ilow[64];
|
||||
char *rights, *instr, *sim="", *us, *ps;
|
||||
|
||||
struct sockaddr_in sadr;
|
||||
@@ -113,6 +120,7 @@ int main (int argc, char *argv[]) {
|
||||
} else {
|
||||
if (strlen(argv[i])>=32) {
|
||||
printf("argument too long\n");
|
||||
Usage(); return 0;
|
||||
} else {
|
||||
if (j==0) {
|
||||
us=argv[i];
|
||||
@@ -122,19 +130,19 @@ int main (int argc, char *argv[]) {
|
||||
j=2;
|
||||
} else {
|
||||
printf("too many arguments\n");
|
||||
return 0;
|
||||
Usage(); return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j==1) {
|
||||
printf("missing password\n");
|
||||
return(0);
|
||||
Usage(); return 0;
|
||||
}
|
||||
instr=getenv("Instrument");
|
||||
if (instr==NULL || instr[0]=='\0') {
|
||||
printf("Instrument is undefined\n");
|
||||
return(0);
|
||||
Usage(); return 0;
|
||||
}
|
||||
ERR_I(CocCreateSockAdr(&sadr, "0", port));
|
||||
ERR_SI(fd=socket(AF_INET, SOCK_STREAM, 0));
|
||||
@@ -163,7 +171,9 @@ int main (int argc, char *argv[]) {
|
||||
sprintf(buf, "config Rights %s %s\r\n", us, ps);
|
||||
ERR_SI(send(fd, buf, strlen(buf), 0));
|
||||
ERR_I(i=readWrite(fd,3));
|
||||
if (!i) {
|
||||
if (!i && 0 != strcmp(instr, "TASP")) {
|
||||
printf("password guess failed, logged in as Spy\n\n");
|
||||
Usage();
|
||||
us="Spy";
|
||||
}
|
||||
printf("\rlogged in to SICS as %s on %s%s\n", us, instr, sim);
|
||||
@@ -171,14 +181,15 @@ int main (int argc, char *argv[]) {
|
||||
if (*sim!='\0') {
|
||||
strcpy(buf, "sync\r\n");
|
||||
ERR_SI(send(fd, buf, strlen(buf), 0));
|
||||
printf("\rsynchronize ...\n");
|
||||
ERR_I(i=readWrite(fd,1));
|
||||
}
|
||||
*/
|
||||
iret=1;
|
||||
buf[0]='\0';
|
||||
pos=0;
|
||||
str_lowcase(instr,instr);
|
||||
sprintf(ibuf, "six[%s%s] ", instr, sim);
|
||||
str_lowcase(ilow,instr);
|
||||
sprintf(ibuf, "six[%s%s] ", ilow, sim);
|
||||
while (1) {
|
||||
FD_ZERO(&mask);
|
||||
FD_SET(fd, &mask);
|
||||
@@ -194,7 +205,10 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
fputs("\n", stdout);
|
||||
skip=0;
|
||||
if (0==strcmp(lbuf,"sync")) skip=1;
|
||||
if (0==strcmp(lbuf,"sync")) {
|
||||
printf("\rsynchronize ...\n");
|
||||
skip=1;
|
||||
}
|
||||
l=strlen(buf);
|
||||
/*
|
||||
printf("sent> %s[%d chars]\n", buf, l);
|
||||
@@ -213,8 +227,10 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
fputs("\n", stdout);
|
||||
return(0);
|
||||
return 0;
|
||||
Usage:
|
||||
return 0;
|
||||
OnError:
|
||||
ErrShow("end");
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user