basicTester
::basicTester(QObject *parent
) :{
dAddr
= QHostAddress("192.168.111.84");
//tftp server address dPort = 69;
connect(sock, SIGNAL(readyRead()), this, SLOT(readData()));
sock->bind(2152); /// \TODO need generate random client TID, and check if port available (select another if not) ; see RFC1350
}
void basicTester::send() {
dgram.resize(( 2 + remote.length() + 1 + modestring.length() + 1 ));
//TFTP WRQ
dgram[0] = 0x00;
dgram[1] = 0x02;
memcpy( dgram.data()+2, remote.toAscii(), remote.length() +1 );
memcpy( dgram.data()+2+remote.length()+1, modestring.toAscii(), modestring.length() +1 );
qDebug() << "Writing dgram to " << dAddr << ":" << dPort;
if(sock->writeDatagram(dgram, dAddr, dPort) == -1){
qDebug() << "Error sending WRQ packet " << sock->errorString();
}
qDebug() << "sock peer : " << sock->peerAddress() << sock->peerPort();
qDebug() << "sock local: " << sock->localAddress() << sock->localPort();
}
void basicTester::readData() {
qDebug() << "basicTester::readData";
while(sock->hasPendingDatagrams()){
datagram.resize(sock->pendingDatagramSize());
quint16 senderPort;
sock->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
qDebug() << "tftp server response : " << datagram.toHex();
}
}
basicTester::basicTester(QObject *parent) :
QObject(parent)
{
dAddr = QHostAddress("192.168.111.84"); //tftp server address
dPort = 69;
sock = new QUdpSocket(this);
connect(sock, SIGNAL(readyRead()), this, SLOT(readData()));
sock->bind(2152); /// \TODO need generate random client TID, and check if port available (select another if not) ; see RFC1350
}
void basicTester::send() {
QByteArray dgram;
QString remote("myfile.txt");
QString modestring ("octet");
dgram.resize(( 2 + remote.length() + 1 + modestring.length() + 1 ));
//TFTP WRQ
dgram[0] = 0x00;
dgram[1] = 0x02;
memcpy( dgram.data()+2, remote.toAscii(), remote.length() +1 );
memcpy( dgram.data()+2+remote.length()+1, modestring.toAscii(), modestring.length() +1 );
qDebug() << "Writing dgram to " << dAddr << ":" << dPort;
if(sock->writeDatagram(dgram, dAddr, dPort) == -1){
qDebug() << "Error sending WRQ packet " << sock->errorString();
}
qDebug() << "sock peer : " << sock->peerAddress() << sock->peerPort();
qDebug() << "sock local: " << sock->localAddress() << sock->localPort();
}
void basicTester::readData() {
qDebug() << "basicTester::readData";
while(sock->hasPendingDatagrams()){
QByteArray datagram;
datagram.resize(sock->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
sock->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
qDebug() << "tftp server response : " << datagram.toHex();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks