#if 0 source makefile.tcl exit #endif #include "tftp.h" #include "b.h" #include "debug.h" #include "fei82559.h" bool TftpClient::readFile(EthernetCapable *ec,U8*ptr,U8 *filename) { static const Ethernet::Address ethServer={{0x00,0xc0,0xa8,0x7c,0x3c,0xec}}; //static const Ethernet::Address ethClient={{0x00,0x13,0x95,0x00,0x00,0x4a}}; static const Ethernet::Address ethClient={{0x00,0x30,0x59,0x05,0x30,0x08}}; static const Ip::Address ipServer={{192,168,0,1}}; static const Ip::Address ipClient={{192,168,0,3}}; const U16 portServer=69; const U16 portClient=2080; Tftp *tftp; U8 buf[1500]; U32 len; tftp=(Tftp*)buf; debug<<"loading \""<asReadRequest->request; for(unsigned i=0;iopcode=Tftp::idReadRequest; sock.send(buf,sizeof(Tftp)+sizeof(Tftp::ReadRequest)+len); U32 blockId=0; U32 totalLength=0; bool quit=false; while(!quit) { len=sock.recv(buf,sizeof(buf)); if(len==~0U) continue; switch(tftp->opcode) { case Tftp::idOptionAcknowledgement: { U8*pt=tftp->asOptionAcknowledgement->response; U32 fileSize=0; while(*pt) pt++; pt++; while(*pt) { fileSize*=10;fileSize+=(*pt-'0'); pt++; } ifdebug(1) { debug<<"tftp opt ack "<asOptionAcknowledgement->response<<' '<opcode=Tftp::idError; tftp->asError->code=0; const U8 err[]={"TFTP Aborted"}; bCopy(err,tftp->asError->response,sizeof(err)); sock.send(buf,sizeof(Tftp)+sizeof(Tftp::Error)+sizeof(err)); } break; case Tftp::idDataPacket: { U16 block; block=tftp->asDataPacket->block-1; len-=sizeof(Tftp)+sizeof(Tftp::DataPacket); if( block%256==0 ) debug<<'.'; ifdebug(2) { debug<<"tftp " << block << "\r\n"; } if(blockId!=block) com1<<"tftp data packet id "<asDataPacket->data, ptr+block*512, len ); tftp->opcode=Tftp::idAcknowledgement; tftp->asAcknowledgement->block=(block+1); if(sock.send(buf,sizeof(Tftp)+sizeof(Tftp::Acknowledgement))==~0U) debug<<"send pb\r\n"; } break; default: quit=true; } } debug<<"\r\n"<