?? ewsdtest2.c
字號:
BLANK_C=0x00;
CONNECT_C=0x02;
SEND_C=0x0a;
RELEASE_C=0x04;
strcpy(PASS,"ewsdewsd");
strcpy(USER,"system01");
/****************************************************************/
init()
{
struct configst conff[MAX_PORT_NO];
int n,port=0;
FILE *confd;
if ((confd=fopen(CONFIGFILE,"rb"))==NULL)
{
perror("config open");
exit(1);
}
if((n=fread(conff,CONFIGLEN,MAX_PORT_NO,confd))<=0)
{
perror("fread");
exit(0);
}
fclose(confd);
for(port=0;port<n;port++)
{
if (conff[port].data_type==OPERAT)
{
sprintf(ttyname[use_scrn],"/dev/%s",conff[port].omcport);
if ((fd[use_scrn]=open(ttyname[use_scrn],O_WRONLY))<0)
{
perror("comis open");
exit(1);
}
conf[use_scrn].release_char=conff[port].release_char;
Krelease_char=conff[port].release_char;
conf[use_scrn].connect_char=conff[port].connect_char;
Kconnect_char=conff[port].connect_char;
conf[use_scrn].send_char=conff[port].send_char;
Ksend_char=conff[port].send_char;
strcpy(conf[use_scrn].iogtype,conff[port].iogtype);
use_scrn++;
} /* if */
} /* for */
return(use_scrn);
}
/****************************************************************/
exec_comm(int fd1,char *comm)
{int i,t,resul;
char c;
star:
t=0;
resul=0;
while(resul<=0 && t<10)
{
resul=justsend(">",0);
if(resul<0 || t>1)
{
connect_file();
nap(1000);
}
resul=justsend("USERID:",0)+justsend("<",0);
/* printf("scan userid or < is==%d\n",resul);*/
i=0;
while(resul==0 && i<5)
{
i++;
nap(1000);
/* printf("scan USERID or < ==%d time /n",i); */
resul=justsend("USERID:",0)+justsend("<",0);
}
t++;
} /* send mm to connect the SWITCH */
if(resul==0) return(0);
resul=justsend("USERID:",0);
if(resul>0)
{
user_file();
nap(1000);
resul=justsend("PASSWORD:",0);
i=0;
while(resul==0 && i<10)
{
i++;
nap(1000);
/* printf("scan USERID or < ==%d time /n",i); */
resul=justsend("PASSWORD:",0);
}
if(resul>0) passwd_file();
else goto star;
nap(1000);
} /*** sent userid and password ***/
resul=justsend("<",0);
i=0;
while(resul==0 && i<10)
{
i++;
nap(1000);
/* printf("scan USERID or < ==%d time /n",i); */
resul=justsend("<",0);
}
if(resul>0)
{
command_file();
nap(3000);
i=0;
resul=0;
while(resul==0 && i<10)
{
i++;
nap(2000);
resul=justsend(">",0);
}
return(1);
}
else goto star;
}
/****************************************************************/
connect_file()
{
int fdd,i;
/******creat the send char file **************/
if((fdd=open("/u/omc/tmp/send_f5",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
printf("lwj1 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&CONNECT_C,1);
for(i=1;i<=159;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/send_f5 /u/omc/tmp/send_file");
}
/****************************************************************/
release_file()
{
int fdd,i;
/******creat the release char file **************/
if((fdd=open("/u/omc/tmp/send_f1",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
printf("lwj4 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&RELEASE_C,1);
for(i=1;i<=159;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/send_f1 /u/omc/tmp/send_file");
}
/****************************************************************/
command_file()
{
int fdd,len,i;
/******creat the command char file **************/
if((fdd=open("/u/omc/tmp/send_comm",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
len=strlen(COMM);
printf("lwj3 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&COMM,len);
write(fdd,&SEND_C,1);
len=167-8-len;
for(i=1;i<=len;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/send_comm /u/omc/tmp/send_file");
}
/****************************************************************/
passwd_file()
{
int fdd,len,i;
/******creat the command char file **************/
if((fdd=open("/u/omc/tmp/send_pass",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
len=strlen(PASS);
printf("lwj3 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&PASS,len);
write(fdd,&SEND_C,1);
len=167-8-len;
for(i=1;i<=len;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/send_pass /u/omc/tmp/send_file");
}
/****************************************************************/
user_file()
{
int fdd,len,i;
/******creat the command char file **************/
if((fdd=open("/u/omc/tmp/send_user",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
len=strlen(USER);
printf("lwj3 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&USER,len);
write(fdd,&SEND_C,1);
len=167-8-len;
for(i=1;i<=len;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/send_user /u/omc/tmp/send_file");
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -