/* This is a bastard piece of code. It sits on the UNIX end of the */ /* LSI's transmission line and catches packets and sends them back */ /* and does file serving stuff too. This is bugged and badly */ /* designed. Beware the big hairy code monster. */ #include #include #include #include main() { int ck, fd, a, b, in, cn, l, x, lock; char c[8], msg[8], d, dud=32; struct termios trm; uid_t me; char *fname; char *files[16]; int fds[16]; int sizes[16]; system("rm -rf txlock"); if( (fd=open("/dev/lsi",O_RDWR|O_EXCL)) < 0 ) { perror(NULL); printf("LSI\n"); exit(-1); } system("rm tx1"); if( mknod( "tx1", 0600 | S_IFIFO, NULL ) != 0 ) { perror(NULL); exit(-1); } if( (in=open("tx1",O_RDWR|O_NOCTTY)) < 0 ) { perror(NULL); printf("tx1\n"); exit(-1); } system("rm tc1"); if( mknod( "tc1", 0600 | S_IFIFO, NULL ) != 0 ) { perror(NULL); exit(-1); } if( (cn=open("tc1",O_RDWR|O_NOCTTY)) < 0 ) { perror(NULL); printf("tc1\n"); exit(-1); } system("bootlsi ker"); printf("Booted.\n"); sleep(1); /* Initialise /dev/lsi */ /* ioctl( fd, TCGETS, &trm ); trm.c_oflag=CBAUD|B4800; ioctl( fd, TCSETS, &trm );*/ msg[0]=1; msg[1]=0; msg[2]=2; msg[3]=0; msg[4]=0; msg[5]=0; msg[6]=10; msg[7]=0; write( cn, &dud, 1 ); fflush(stdout); if( !fork() ) { if( (lock=open("txlock",O_CREAT,0666)) <0 ) { perror(NULL); printf("lock file(2)\n"); exit(-1); } while(1) { for(b=0;b<8;b++) while( read(fd,&c[b],1) != 1 ); if( (c[1]==0) && (c[0]==1) ) { if( (c[7]==1) && (c[6]==0) ) { write( cn, &c[6], 1); } else { printf("%c",c[6]); fflush(stdout); } } if( (c[1]==0) && (c[0]==3) ) { l=((unsigned char)c[5]*256)+(unsigned char)c[4]; fname=(char*)malloc(l); for(b=0;b_dir"); fds[ck]=open( fname, O_RDONLY, 0 ); if( fds[ck]>=0 ) { files[ck]=(char*)malloc(65536); x=0; while( read( fds[ck], ((x++)+files[ck]), 1) == 1 ); sizes[ck]=x; msg[0]=4; msg[1]=0; msg[2]=c[2]; msg[3]=c[3]; msg[4]=0; msg[5]=0; msg[6]=x%256; msg[7]=x/256; flock( lock, LOCK_EX ); for(b=0;b<8;b++) write(fd,&msg[b],1); flock( lock, LOCK_UN ); } else { msg[0]=4; msg[1]=0; msg[2]=c[2]; msg[3]=c[3]; msg[4]=0; msg[5]=0; msg[6]=0; msg[7]=0; flock( lock, LOCK_EX ); for(b=0;b<8;b++) write(fd,msg+b,1); flock( lock, LOCK_UN ); } } if( (c[1]==0) && (c[0]==5) ) { ck=((unsigned char)c[3]*256)+(unsigned char)c[2]; if(fds[ck]<0) { printf("send failed\n"); } else { l=((unsigned char)c[7]*256)+(unsigned char)c[6]; msg[0]=2; msg[1]=0; msg[2]=c[2]; msg[3]=c[3]; msg[4]=0; msg[5]=1; msg[6]=1; msg[7]=0; flock( lock, LOCK_EX ); for(b=0;b<8;b++) write(fd,msg+b,1); sleep(1); for( b=0; b<256; b++ ) write(fd,files[ck]+l+b,1); flock( lock, LOCK_UN ); } } } } else { if( (lock=open("txlock",O_CREAT,0666)) <0 ) { perror(NULL); printf("lock file(2)\n"); exit(-1); } while(1) { while( read(in,&d,1) != 1) sleep(0); read( cn, &dud, 1); msg[6]=d; flock( lock, LOCK_EX ); for(b=0;b<8;b++) write(fd,msg+b,1); flock( lock, LOCK_UN ); } } }