From: <f-r...@us...> - 2011-02-11 23:05:21
|
Revision: 243 http://netemul.svn.sourceforge.net/netemul/?rev=243&view=rev Author: f-r-o-s-t Date: 2011-02-11 23:05:12 +0000 (Fri, 11 Feb 2011) Log Message: ----------- I'm sorry =( Modified Paths: -------------- trunk/src/devices/smartdevice.h trunk/src/programs/dhcpdemon.h Added Paths: ----------- trunk/src/programs/ trunk/src/programs/dhcpclientprogram.cpp trunk/src/programs/dhcpclientprogram.h trunk/src/programs/dhcpserverprogram.cpp trunk/src/programs/dhcpserverprogram.h trunk/src/programs/program.cpp trunk/src/programs/program.h trunk/src/programs/programs.pri trunk/src/programs/ripprogram.cpp trunk/src/programs/ripprogram.h trunk/src/programs/spoofingprogram.cpp trunk/src/programs/spoofingprogram.h Removed Paths: ------------- trunk/src/programs/dhcpclientprogramm.cpp trunk/src/programs/dhcpclientprogramm.h trunk/src/programs/dhcpserverprogramm.cpp trunk/src/programs/dhcpserverprogramm.h trunk/src/programs/programmrep.cpp trunk/src/programs/programmrep.h trunk/src/programs/programms.pri trunk/src/programs/ripprogramm.cpp trunk/src/programs/ripprogramm.h trunk/src/programs/spoofingprogramm.cpp trunk/src/programs/spoofingprogramm.h Modified: trunk/src/devices/smartdevice.h =================================================================== --- trunk/src/devices/smartdevice.h 2011-02-11 21:56:14 UTC (rev 242) +++ trunk/src/devices/smartdevice.h 2011-02-11 23:05:12 UTC (rev 243) @@ -24,7 +24,7 @@ #include <QtGui/QIcon> #include "deviceimpl.h" #include "interface.h" -#include "programrep.h" +#include "program.h" class RouteModel; class ArpModel; Copied: trunk/src/programs/dhcpclientprogram.cpp (from rev 240, trunk/src/programms/dhcpclientprogramm.cpp) =================================================================== --- trunk/src/programs/dhcpclientprogram.cpp (rev 0) +++ trunk/src/programs/dhcpclientprogram.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,376 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "dhcpclientprogram.h" +#include "smartdevice.h" +#include "udpsocket.h" +#include "dhcpclientproperty.h" +#include "udppacket.h" + +DhcpClientProgram::DhcpClientProgram(QObject *parent) : Program(parent) +{ + myName = tr("DHCP client"); + myOfferTime = 60; +} + +DhcpClientProgram::~DhcpClientProgram() +{ + qDeleteAll(myStates); + // Make it + //delete listener; + myDevice->disposeSocket(listener); +} + +void DhcpClientProgram::incTime() +{ + foreach ( InterfaceState *i , myStates ) { + --i->time; + if ( i->time <= 0 ) { + switch ( i->state ) { + case InterfaceState::CS_ALL_RIGHT: restartSession(i); break; + case InterfaceState::CS_WAIT_VARIANT: sendDiscover( i->name ); break; + case InterfaceState::CS_WAIT_RESPONSE: sendRequest(i->name ); break; + } + } + } +} +/*! + * Переопределяем функцию установки устройства чтобы соединиться со слотом. + * @param s - указатель на устройство на которое установлена программа. + */ +void DhcpClientProgram::setDevice(SmartDevice *s) +{ + if ( s == 0 ) { + foreach ( InterfaceState *i , myStates ) resetClient(i); + return; + } + Program::setDevice(s); + listener = s->openSocket( CLIENT_SOCKET , SmartDevice::UDP ); + listener->setBind("0.0.0.0"); + connect( listener , SIGNAL(readyRead(QByteArray)) , SLOT(processData(QByteArray)) ); + connect( s , SIGNAL(interfaceDeleted(QString)), SLOT(deleteInterface(QString)) ); + foreach ( InterfaceState *i , myStates ) { + resetClient( i ); + } +} +//------------------------------------------------------ + +void DhcpClientProgram::resetClient(InterfaceState *session) +{ + myDevice->adapter(session->name)->setIp(IpAddress("0.0.0.0")); + myDevice->adapter(session->name)->setMask(IpAddress("0.0.0.0")); + myDevice->connectedNet( myDevice->adapter( session->name ) ); + myDevice->setGateway("0.0.0.0"); +} + +bool DhcpClientProgram::isUnderDhcpControl(const QString name) const +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) { + return true; + } + return false; +} + +/*! + Посылает Request серверу + @param name - имя интерфейса + */ +void DhcpClientProgram::sendRequest(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + if ( REPEAT_COUNT < ++t->count ) { + restartSession(t); + return; + } + t->time = myOfferTime; + DhcpPacket message; + message.setType( DhcpPacket::DHCPREQUEST ); + message.setXid( t->xid ); + message.setChaddr( myDevice->adapter(t->name)->mac() ); + message.setSiaddr( t->serverAddress ); + sendDhcpMessage(message,t); +} +//------------------------------------------------------ +/*! + * Посылает запрос на получение настроек. + * @param name - имя интерфейса. + */ +void DhcpClientProgram::sendDiscover(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + t->state = InterfaceState::CS_WAIT_VARIANT; + t->time = myOfferTime; + t->count = 0; + DhcpPacket message; + message.setType( DhcpPacket::DHCPDISCOVER ); + message.setXid(t->xid); + message.setChaddr( myDevice->adapter(t->name)->mac() ); + if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); + sendDhcpMessage(message,t); +} +//-------------------------------------------------------------- +void DhcpClientProgram::sendDecLine(const QString &name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + DhcpPacket message; + message.setType( DhcpPacket::DHCPDECLINE ); + message.setXid( t->xid ); + if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); + message.setChaddr( myDevice->adapter( t->name )->mac() ); + sendDhcpMessage( message , t ); +} +/*! + Обрабатывает входящие данные. + @param data - пришедщие данные. + */ +void DhcpClientProgram::processData(QByteArray data) +{ + DhcpPacket packet(data); + switch ( packet.type() ) { + case DhcpPacket::DHCPOFFER: receiveOffer(packet); break; + case DhcpPacket::DHCPACK: receiveAck(packet); break; + } +} +//--------------------------------------------------------------- +/*! + Начинает заново сессию + @param session - указатель на сессию + */ +void DhcpClientProgram::restartSession(InterfaceState *session) +{ + resetClient(session); + sendDiscover( session->name ); +} +//--------------------------------------------------------------- +/*! + Обрабатывает входящее предложение настроек. + @param packet - пакет с настройками. + */ +void DhcpClientProgram::receiveOffer(DhcpPacket packet) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_VARIANT ) { + i->state = InterfaceState::CS_WAIT_RESPONSE; + i->serverAddress = packet.siaddr(); + sendRequest( i->name ); + return; + } +} +//--------------------------------------------------------------- +/*! + Обрабатывает вхоодящий АСК. + @param packet - ack пакет + */ +void DhcpClientProgram::receiveAck(DhcpPacket packet) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_RESPONSE ) { + i->state = InterfaceState::CS_ALL_RIGHT; + myDevice->adapter(i->name)->setIp( packet.yiaddr() ); + myDevice->adapter(i->name)->setMask( packet.mask() ); + myDevice->connectedNet(myDevice->adapter(i->name)); + myDevice->setGateway( packet.gateway().toString() ); + myDevice->updateView(); + i->time = packet.time(); + i->lastIp = packet.yiaddr(); + myDevice->adapter(i->name)->sendArpRequest( packet.yiaddr() ); + return; + } +} +//--------------------------------------------------------------- +/*! + Отправляет пакет с нужного интерфейса. + @param message - пакет. + @param state - поток-отправитель. + */ +void DhcpClientProgram::sendDhcpMessage(DhcpPacket message, InterfaceState *state) +{ + if (!myDevice->adapter(state->name)->isConnect() ) return; + UdpPacket udp; + udp.setSender(CLIENT_SOCKET); + udp.setReceiver(SERVER_SOCKET); + udp.pack( message.toData() ); + IpPacket packet( myDevice->adapter(state->name)->ip() , IpAddress::full() ); + packet.pack( udp.toData() ); + packet.setUpProtocol( IpPacket::udp ); + myDevice->adapter(state->name)->sendPacket( packet); +} +//--------------------------------------------------------------- +/*! + * Показывает диалог программы. + */ +void DhcpClientProgram::showProperty() +{ + dhcpClientProperty *d = new dhcpClientProperty; + d->setProgramm(this); + d->exec(); +} +//--------------------------------------------------------------- +/*! + * Ищет указанный сеанс связи для интерфейса. + * @param name - имя интерфейса. + * @return указатель на сеанс, если такого нет то 0 + */ +InterfaceState* DhcpClientProgram::stateAt(const QString name) +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) return i; + return 0; +} +//-------------------------------------------------------------- +QStringList DhcpClientProgram::interfacesList() const +{ + return myDevice->sockets(); +} +/*! + * Возвращаем иконку подключения, для указанного интерфейса. + * @param имя интерефейса + * @return иконка соединения + */ +QIcon DhcpClientProgram::isConnectSocketIcon(const QString &name) const +{ + return myDevice->isConnectSocketIcon(name); +} +//----------------------------------------------------------------------- +/*! + * Вызывается когда у устройства удаляется интерфейс, если мы за + * ним следим, то мы прекращаем это делать и удаляем его из списка. + */ +void DhcpClientProgram::deleteInterface(const QString name) +{ + InterfaceState *t = stateAt(name); + if ( !t ) return; + myStates.removeOne(t); + delete t; +} +//-------------------------------------------------------------------- +/*! + * Если интерфейс еще не добавлен под наблюдение, то добавляем его. + * @param name - имя интерфейса. + * @param b - включить или выключить наблюдение. + */ +void DhcpClientProgram::observeInterface(const QString &name, bool b) +{ + if ( !myEnable ) return; + InterfaceState *temp = stateAt(name); + if ( temp ) { + if ( b ) return; + resetClient( temp ); + myStates.removeOne(temp); + delete temp; + return; + } + if ( !b ) return; + InterfaceState *session = new InterfaceState; + session->name = name; + session->xid = qrand()%5000; + session->time = 0; + connect( myDevice->adapter(session->name) , SIGNAL(equalIpDetected()) , SLOT(onDetectEqualIp()) ); + myStates << session; + sendDiscover(session->name); +} +//-------------------------------------------------------------------- + +void DhcpClientProgram::onDetectEqualIp() +{ + Interface *t = qobject_cast<Interface*>(sender()); + InterfaceState *client = 0; + foreach ( InterfaceState *i , myStates ) + if ( myDevice->adapter( i->name ) == t ) client = i; + if ( !client ) return; + sendDecLine(client->name); + client->xid = qrand()%5000; + client->lastIp.setIp("0.0.0.0"); + restartSession( client); +} + +Qt::CheckState DhcpClientProgram::checkedState(const QString &name) const +{ + foreach ( InterfaceState *i , myStates ) + if ( i->name == name ) return Qt::Checked; + return Qt::Unchecked; +} +/*! + Записывает отличительные черты в поток. + @param stream - поток для записи. +*/ +void DhcpClientProgram::write(QDataStream &stream) const +{ + stream << DHCPClient; + Program::write(stream); + stream << myOfferTime; + stream << myStates.size(); + foreach ( InterfaceState *i , myStates ) i->write(stream); +} +//--------------------------------------------------- +/*! + Считывает отличительные черты из потока. + @param stream - поток для чтения. +*/ +void DhcpClientProgram::read(QDataStream &stream) +{ + Program::read(stream); + stream >> myOfferTime; + int n; + stream >> n; + for ( int i = 0 ; i < n ; i++ ) { + InterfaceState *temp = new InterfaceState; + temp->read(stream); + temp->time = 0; + temp->state = InterfaceState::CS_WAIT_VARIANT; + myStates << temp; + } +} +//--------------------------------------------------- +QVariantList DhcpClientProgram::statesObjectList() const +{ + QVariantList list; + foreach ( InterfaceState *i , myStates ) { + QObject *o = new InterfaceStateObject(i); + list << qVariantFromValue(o); + } + return list; +} + +void DhcpClientProgram::addInterfaceStateObject(InterfaceStateObject *obj) +{ + InterfaceState *s = obj->object(); + s->state = InterfaceState::CS_WAIT_VARIANT; + myStates << s; + obj->deleteLater(); +} + +//--------------------------------------------------- +//--------------------------------------------------- +void InterfaceState::write(QDataStream &stream) const +{ + stream << xid << time << serverAddress << lastIp << name; +} + +void InterfaceState::read(QDataStream &stream) +{ + stream >> xid >> time >> serverAddress >> lastIp >> name; +} + + + Copied: trunk/src/programs/dhcpclientprogram.h (from rev 240, trunk/src/programms/dhcpclientprogramm.h) =================================================================== --- trunk/src/programs/dhcpclientprogram.h (rev 0) +++ trunk/src/programs/dhcpclientprogram.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,130 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef DHCPCLIENTPROGRAMM_H +#define DHCPCLIENTPROGRAMM_H + +#include <QMetaType> +#include <QIcon> +#include "program.h" +#include "dhcppacket.h" + +static const int MINUTE = 60; +static const int REPEAT_COUNT = 3; + +class Interface; +class AbstractSocket; + +struct InterfaceState { + enum { CS_NONE , CS_WAIT_VARIANT , CS_WAIT_RESPONSE , CS_ALL_RIGHT }; + int state; + int xid; + int time; + qint8 count; + IpAddress serverAddress; + IpAddress lastIp; + QString name; + void write(QDataStream &stream) const; + void read(QDataStream &stream); +}; +typedef QList<InterfaceState*> InterfaceStateList; + +//xid << time << serverAddress << lastIp << name; + +class InterfaceStateObject : public QObject +{ + Q_OBJECT + Q_PROPERTY( int xid READ xid WRITE setXid ) + Q_PROPERTY( QString serverAddress READ serverAddress WRITE setServerAddress ) + Q_PROPERTY( QString lastIp READ lastIp WRITE setLastIp ) + Q_PROPERTY( QString name READ name WRITE setName ) +public: + InterfaceStateObject(InterfaceState *s) { st = s; } + InterfaceStateObject(QObject *parent = 0) : QObject(parent) { st = new InterfaceState(); } + + InterfaceState* object() { return st; } + + int xid() const { return st->xid; } + QString serverAddress() const { return st->serverAddress.toString(); } + QString lastIp() const { return st->lastIp.toString(); } + QString name() const { return st->name; } + + void setXid( int x ) { st->xid = x; } + void setServerAddress( const QString &x ) { st->serverAddress.setIp(x); } + void setLastIp( const QString &x ) { st->lastIp.setIp(x); } + void setName( const QString &x ) { st->name = x; } + +private: + InterfaceState *st; +}; + + +class DhcpClientProgram : public Program +{ + Q_OBJECT + Q_PROPERTY( int offerTime READ offerTime WRITE setOfferTime ) + Q_PROPERTY( QVariantList states READ statesObjectList ) +public: + enum { DHCPClient = 1 ,CLIENT_SOCKET = 67, SERVER_SOCKET = 68 }; + DhcpClientProgram(QObject *parent = 0); + ~DhcpClientProgram(); + int id() const { return DHCPClient; } + bool interrupt(int) { return false; } + void setDevice(SmartDevice *s); + void showProperty(); + void incTime(); + bool isUnderDhcpControl(const QString name) const; + void write(QDataStream &stream) const; + void read(QDataStream &stream); + void observeInterface(const QString &name, bool b); + QStringList interfacesList() const; + QIcon isConnectSocketIcon(const QString &name) const; + Qt::CheckState checkedState(const QString &name) const; + virtual QString featureName() const { return "dc"; } +public slots: + void deleteInterface(const QString name); +private slots: + void processData(QByteArray data); + void onDetectEqualIp(); +//Property +public: + Q_INVOKABLE void addInterfaceStateObject(InterfaceStateObject *obj); + void setOfferTime(int time) { myOfferTime = time; } + int offerTime() const { return myOfferTime; } + InterfaceStateList states() { return myStates; } + QVariantList statesObjectList() const; + +private: + InterfaceStateList myStates; + int myOfferTime; + +private: + void sendDhcpMessage(DhcpPacket message, InterfaceState *state); + void sendRequest(const QString &name); + void sendDiscover(const QString &name); + void sendDecLine(const QString &name); + void receiveOffer(DhcpPacket packet); + void receiveAck(DhcpPacket packet); + void restartSession( InterfaceState *session); + InterfaceState* stateAt(const QString name); + void resetClient( InterfaceState *session); + AbstractSocket *listener; +}; + +#endif // DHCPCLIENTPROGRAMM_H Deleted: trunk/src/programs/dhcpclientprogramm.cpp =================================================================== --- trunk/src/programms/dhcpclientprogramm.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpclientprogramm.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,376 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "dhcpclientprogramm.h" -#include "smartdevice.h" -#include "udpsocket.h" -#include "dhcpclientproperty.h" -#include "udppacket.h" - -DhcpClientProgram::DhcpClientProgram(QObject *parent) : Program(parent) -{ - myName = tr("DHCP client"); - myOfferTime = 60; -} - -DhcpClientProgram::~DhcpClientProgram() -{ - qDeleteAll(myStates); - // Make it - //delete listener; - myDevice->disposeSocket(listener); -} - -void DhcpClientProgram::incTime() -{ - foreach ( InterfaceState *i , myStates ) { - --i->time; - if ( i->time <= 0 ) { - switch ( i->state ) { - case InterfaceState::CS_ALL_RIGHT: restartSession(i); break; - case InterfaceState::CS_WAIT_VARIANT: sendDiscover( i->name ); break; - case InterfaceState::CS_WAIT_RESPONSE: sendRequest(i->name ); break; - } - } - } -} -/*! - * Переопределяем функцию установки устройства чтобы соединиться со слотом. - * @param s - указатель на устройство на которое установлена программа. - */ -void DhcpClientProgram::setDevice(SmartDevice *s) -{ - if ( s == 0 ) { - foreach ( InterfaceState *i , myStates ) resetClient(i); - return; - } - Program::setDevice(s); - listener = s->openSocket( CLIENT_SOCKET , SmartDevice::UDP ); - listener->setBind("0.0.0.0"); - connect( listener , SIGNAL(readyRead(QByteArray)) , SLOT(processData(QByteArray)) ); - connect( s , SIGNAL(interfaceDeleted(QString)), SLOT(deleteInterface(QString)) ); - foreach ( InterfaceState *i , myStates ) { - resetClient( i ); - } -} -//------------------------------------------------------ - -void DhcpClientProgram::resetClient(InterfaceState *session) -{ - myDevice->adapter(session->name)->setIp(IpAddress("0.0.0.0")); - myDevice->adapter(session->name)->setMask(IpAddress("0.0.0.0")); - myDevice->connectedNet( myDevice->adapter( session->name ) ); - myDevice->setGateway("0.0.0.0"); -} - -bool DhcpClientProgram::isUnderDhcpControl(const QString name) const -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) { - return true; - } - return false; -} - -/*! - Посылает Request серверу - @param name - имя интерфейса - */ -void DhcpClientProgram::sendRequest(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - if ( REPEAT_COUNT < ++t->count ) { - restartSession(t); - return; - } - t->time = myOfferTime; - DhcpPacket message; - message.setType( DhcpPacket::DHCPREQUEST ); - message.setXid( t->xid ); - message.setChaddr( myDevice->adapter(t->name)->mac() ); - message.setSiaddr( t->serverAddress ); - sendDhcpMessage(message,t); -} -//------------------------------------------------------ -/*! - * Посылает запрос на получение настроек. - * @param name - имя интерфейса. - */ -void DhcpClientProgram::sendDiscover(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - t->state = InterfaceState::CS_WAIT_VARIANT; - t->time = myOfferTime; - t->count = 0; - DhcpPacket message; - message.setType( DhcpPacket::DHCPDISCOVER ); - message.setXid(t->xid); - message.setChaddr( myDevice->adapter(t->name)->mac() ); - if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); - sendDhcpMessage(message,t); -} -//-------------------------------------------------------------- -void DhcpClientProgram::sendDecLine(const QString &name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - DhcpPacket message; - message.setType( DhcpPacket::DHCPDECLINE ); - message.setXid( t->xid ); - if ( !t->lastIp.isEmpty() ) message.setYiaddr( t->lastIp ); - message.setChaddr( myDevice->adapter( t->name )->mac() ); - sendDhcpMessage( message , t ); -} -/*! - Обрабатывает входящие данные. - @param data - пришедщие данные. - */ -void DhcpClientProgram::processData(QByteArray data) -{ - DhcpPacket packet(data); - switch ( packet.type() ) { - case DhcpPacket::DHCPOFFER: receiveOffer(packet); break; - case DhcpPacket::DHCPACK: receiveAck(packet); break; - } -} -//--------------------------------------------------------------- -/*! - Начинает заново сессию - @param session - указатель на сессию - */ -void DhcpClientProgram::restartSession(InterfaceState *session) -{ - resetClient(session); - sendDiscover( session->name ); -} -//--------------------------------------------------------------- -/*! - Обрабатывает входящее предложение настроек. - @param packet - пакет с настройками. - */ -void DhcpClientProgram::receiveOffer(DhcpPacket packet) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_VARIANT ) { - i->state = InterfaceState::CS_WAIT_RESPONSE; - i->serverAddress = packet.siaddr(); - sendRequest( i->name ); - return; - } -} -//--------------------------------------------------------------- -/*! - Обрабатывает вхоодящий АСК. - @param packet - ack пакет - */ -void DhcpClientProgram::receiveAck(DhcpPacket packet) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->xid == packet.xid() && i->state == InterfaceState::CS_WAIT_RESPONSE ) { - i->state = InterfaceState::CS_ALL_RIGHT; - myDevice->adapter(i->name)->setIp( packet.yiaddr() ); - myDevice->adapter(i->name)->setMask( packet.mask() ); - myDevice->connectedNet(myDevice->adapter(i->name)); - myDevice->setGateway( packet.gateway().toString() ); - myDevice->updateView(); - i->time = packet.time(); - i->lastIp = packet.yiaddr(); - myDevice->adapter(i->name)->sendArpRequest( packet.yiaddr() ); - return; - } -} -//--------------------------------------------------------------- -/*! - Отправляет пакет с нужного интерфейса. - @param message - пакет. - @param state - поток-отправитель. - */ -void DhcpClientProgram::sendDhcpMessage(DhcpPacket message, InterfaceState *state) -{ - if (!myDevice->adapter(state->name)->isConnect() ) return; - UdpPacket udp; - udp.setSender(CLIENT_SOCKET); - udp.setReceiver(SERVER_SOCKET); - udp.pack( message.toData() ); - IpPacket packet( myDevice->adapter(state->name)->ip() , IpAddress::full() ); - packet.pack( udp.toData() ); - packet.setUpProtocol( IpPacket::udp ); - myDevice->adapter(state->name)->sendPacket( packet); -} -//--------------------------------------------------------------- -/*! - * Показывает диалог программы. - */ -void DhcpClientProgram::showProperty() -{ - dhcpClientProperty *d = new dhcpClientProperty; - d->setProgramm(this); - d->exec(); -} -//--------------------------------------------------------------- -/*! - * Ищет указанный сеанс связи для интерфейса. - * @param name - имя интерфейса. - * @return указатель на сеанс, если такого нет то 0 - */ -InterfaceState* DhcpClientProgram::stateAt(const QString name) -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) return i; - return 0; -} -//-------------------------------------------------------------- -QStringList DhcpClientProgram::interfacesList() const -{ - return myDevice->sockets(); -} -/*! - * Возвращаем иконку подключения, для указанного интерфейса. - * @param имя интерефейса - * @return иконка соединения - */ -QIcon DhcpClientProgram::isConnectSocketIcon(const QString &name) const -{ - return myDevice->isConnectSocketIcon(name); -} -//----------------------------------------------------------------------- -/*! - * Вызывается когда у устройства удаляется интерфейс, если мы за - * ним следим, то мы прекращаем это делать и удаляем его из списка. - */ -void DhcpClientProgram::deleteInterface(const QString name) -{ - InterfaceState *t = stateAt(name); - if ( !t ) return; - myStates.removeOne(t); - delete t; -} -//-------------------------------------------------------------------- -/*! - * Если интерфейс еще не добавлен под наблюдение, то добавляем его. - * @param name - имя интерфейса. - * @param b - включить или выключить наблюдение. - */ -void DhcpClientProgram::observeInterface(const QString &name, bool b) -{ - if ( !myEnable ) return; - InterfaceState *temp = stateAt(name); - if ( temp ) { - if ( b ) return; - resetClient( temp ); - myStates.removeOne(temp); - delete temp; - return; - } - if ( !b ) return; - InterfaceState *session = new InterfaceState; - session->name = name; - session->xid = qrand()%5000; - session->time = 0; - connect( myDevice->adapter(session->name) , SIGNAL(equalIpDetected()) , SLOT(onDetectEqualIp()) ); - myStates << session; - sendDiscover(session->name); -} -//-------------------------------------------------------------------- - -void DhcpClientProgram::onDetectEqualIp() -{ - Interface *t = qobject_cast<Interface*>(sender()); - InterfaceState *client = 0; - foreach ( InterfaceState *i , myStates ) - if ( myDevice->adapter( i->name ) == t ) client = i; - if ( !client ) return; - sendDecLine(client->name); - client->xid = qrand()%5000; - client->lastIp.setIp("0.0.0.0"); - restartSession( client); -} - -Qt::CheckState DhcpClientProgram::checkedState(const QString &name) const -{ - foreach ( InterfaceState *i , myStates ) - if ( i->name == name ) return Qt::Checked; - return Qt::Unchecked; -} -/*! - Записывает отличительные черты в поток. - @param stream - поток для записи. -*/ -void DhcpClientProgram::write(QDataStream &stream) const -{ - stream << DHCPClient; - Program::write(stream); - stream << myOfferTime; - stream << myStates.size(); - foreach ( InterfaceState *i , myStates ) i->write(stream); -} -//--------------------------------------------------- -/*! - Считывает отличительные черты из потока. - @param stream - поток для чтения. -*/ -void DhcpClientProgram::read(QDataStream &stream) -{ - Program::read(stream); - stream >> myOfferTime; - int n; - stream >> n; - for ( int i = 0 ; i < n ; i++ ) { - InterfaceState *temp = new InterfaceState; - temp->read(stream); - temp->time = 0; - temp->state = InterfaceState::CS_WAIT_VARIANT; - myStates << temp; - } -} -//--------------------------------------------------- -QVariantList DhcpClientProgram::statesObjectList() const -{ - QVariantList list; - foreach ( InterfaceState *i , myStates ) { - QObject *o = new InterfaceStateObject(i); - list << qVariantFromValue(o); - } - return list; -} - -void DhcpClientProgram::addInterfaceStateObject(InterfaceStateObject *obj) -{ - InterfaceState *s = obj->object(); - s->state = InterfaceState::CS_WAIT_VARIANT; - myStates << s; - obj->deleteLater(); -} - -//--------------------------------------------------- -//--------------------------------------------------- -void InterfaceState::write(QDataStream &stream) const -{ - stream << xid << time << serverAddress << lastIp << name; -} - -void InterfaceState::read(QDataStream &stream) -{ - stream >> xid >> time >> serverAddress >> lastIp >> name; -} - - - Deleted: trunk/src/programs/dhcpclientprogramm.h =================================================================== --- trunk/src/programms/dhcpclientprogramm.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpclientprogramm.h 2011-02-11 23:05:12 UTC (rev 243) @@ -1,130 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#ifndef DHCPCLIENTPROGRAMM_H -#define DHCPCLIENTPROGRAMM_H - -#include <QMetaType> -#include <QIcon> -#include "programmrep.h" -#include "dhcppacket.h" - -static const int MINUTE = 60; -static const int REPEAT_COUNT = 3; - -class Interface; -class AbstractSocket; - -struct InterfaceState { - enum { CS_NONE , CS_WAIT_VARIANT , CS_WAIT_RESPONSE , CS_ALL_RIGHT }; - int state; - int xid; - int time; - qint8 count; - IpAddress serverAddress; - IpAddress lastIp; - QString name; - void write(QDataStream &stream) const; - void read(QDataStream &stream); -}; -typedef QList<InterfaceState*> InterfaceStateList; - -//xid << time << serverAddress << lastIp << name; - -class InterfaceStateObject : public QObject -{ - Q_OBJECT - Q_PROPERTY( int xid READ xid WRITE setXid ) - Q_PROPERTY( QString serverAddress READ serverAddress WRITE setServerAddress ) - Q_PROPERTY( QString lastIp READ lastIp WRITE setLastIp ) - Q_PROPERTY( QString name READ name WRITE setName ) -public: - InterfaceStateObject(InterfaceState *s) { st = s; } - InterfaceStateObject(QObject *parent = 0) : QObject(parent) { st = new InterfaceState(); } - - InterfaceState* object() { return st; } - - int xid() const { return st->xid; } - QString serverAddress() const { return st->serverAddress.toString(); } - QString lastIp() const { return st->lastIp.toString(); } - QString name() const { return st->name; } - - void setXid( int x ) { st->xid = x; } - void setServerAddress( const QString &x ) { st->serverAddress.setIp(x); } - void setLastIp( const QString &x ) { st->lastIp.setIp(x); } - void setName( const QString &x ) { st->name = x; } - -private: - InterfaceState *st; -}; - - -class DhcpClientProgram : public Program -{ - Q_OBJECT - Q_PROPERTY( int offerTime READ offerTime WRITE setOfferTime ) - Q_PROPERTY( QVariantList states READ statesObjectList ) -public: - enum { DHCPClient = 1 ,CLIENT_SOCKET = 67, SERVER_SOCKET = 68 }; - DhcpClientProgram(QObject *parent = 0); - ~DhcpClientProgram(); - int id() const { return DHCPClient; } - bool interrupt(int) { return false; } - void setDevice(SmartDevice *s); - void showProperty(); - void incTime(); - bool isUnderDhcpControl(const QString name) const; - void write(QDataStream &stream) const; - void read(QDataStream &stream); - void observeInterface(const QString &name, bool b); - QStringList interfacesList() const; - QIcon isConnectSocketIcon(const QString &name) const; - Qt::CheckState checkedState(const QString &name) const; - virtual QString featureName() const { return "dc"; } -public slots: - void deleteInterface(const QString name); -private slots: - void processData(QByteArray data); - void onDetectEqualIp(); -//Property -public: - Q_INVOKABLE void addInterfaceStateObject(InterfaceStateObject *obj); - void setOfferTime(int time) { myOfferTime = time; } - int offerTime() const { return myOfferTime; } - InterfaceStateList states() { return myStates; } - QVariantList statesObjectList() const; - -private: - InterfaceStateList myStates; - int myOfferTime; - -private: - void sendDhcpMessage(DhcpPacket message, InterfaceState *state); - void sendRequest(const QString &name); - void sendDiscover(const QString &name); - void sendDecLine(const QString &name); - void receiveOffer(DhcpPacket packet); - void receiveAck(DhcpPacket packet); - void restartSession( InterfaceState *session); - InterfaceState* stateAt(const QString name); - void resetClient( InterfaceState *session); - AbstractSocket *listener; -}; - -#endif // DHCPCLIENTPROGRAMM_H Modified: trunk/src/programs/dhcpdemon.h =================================================================== --- trunk/src/programms/dhcpdemon.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpdemon.h 2011-02-11 23:05:12 UTC (rev 243) @@ -30,7 +30,6 @@ class DhcpDemon : public QObject { Q_OBJECT - Q_PROPERTY( QString interfaceName READ interfaceName WRITE setInterfaceName ) Q_PROPERTY( QString beginIp READ beginIp WRITE setBeginIp ) Q_PROPERTY( QString endIp READ endIp WRITE setEndIp ) @@ -39,7 +38,6 @@ Q_PROPERTY( int time READ time WRITE setTime ) Q_PROPERTY( int waitingTime READ waitingTime WRITE setWaitingTime ) Q_PROPERTY( bool dynamic READ dynamic WRITE setDynamic ) - public: enum { CLIENT_SOCKET = 67 , SERVER_SOCKET = 68 }; Copied: trunk/src/programs/dhcpserverprogram.cpp (from rev 240, trunk/src/programms/dhcpserverprogramm.cpp) =================================================================== --- trunk/src/programs/dhcpserverprogram.cpp (rev 0) +++ trunk/src/programs/dhcpserverprogram.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,159 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "dhcpserverprogram.h" +#include "dhcpserverproperty.h" +#include "dhcppacket.h" +#include "smartdevice.h" +#include "udpsocket.h" +#include "socketfactory.h" +#include <QMessageBox> + +#include "dhcpservermodel.h" + +int DhcpServerProgram::myServerCount = 0; + +DhcpServerProgram::DhcpServerProgram(QObject *parent) : Program(parent) +{ + myName = tr("DHCP server"); + myServerCount++; + myServerName = QString("Server%1").arg(myServerCount); + myDemons.clear(); + qDeleteAll(myDemons); +} + +DhcpServerProgram::~DhcpServerProgram() +{ + myDevice->disposeSocket(receiver); + myDemons.clear(); + qDeleteAll(myDemons); +} + +void DhcpServerProgram::setDevice(SmartDevice *s) +{ + if ( s == 0 ) return; + Program::setDevice(s); + receiver = myDevice->openSocket(DhcpDemon::SERVER_SOCKET, SocketFactory::UDP); + //receiver = new udpSocket(myDevice, SERVER_SOCKET); + foreach ( Interface *i, myDevice->interfaces() ) { + if ( i->isConnect() ) { + DhcpDemon *demon = new DhcpDemon(i); + myDemons << demon; + } + } + receiver->setBind("0.0.0.0"); + connect( receiver , SIGNAL(readyRead(QByteArray)), SLOT(execute(QByteArray))); + connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterface(QString)) ); +} + +//void dhcpServerProgramm::checkInterface(QString port) +//{ +// if ( myInterface.isEmpty() ) setInterfaceName(port); +//} + +void DhcpServerProgram::execute(QByteArray data) +{ + DhcpPacket packet(data); + foreach ( DhcpDemon *demon, myDemons ) { + IpAddress deviceIp = myDevice->adapter(demon->interfaceName())->ip(); + if ( deviceIp.isEmpty() ) { + QMessageBox::warning(0,tr("Warning"), + tr("Your DHCP server <i>%1</i> isn't configured.").arg(myServerName), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + if ( deviceIp == packet.siaddr() ) { + switch ( packet.type() ) { + case DhcpPacket::DHCPDISCOVER : + demon->executeDiscover(packet); + break; + case DhcpPacket::DHCPREQUEST : + demon->executeRequest(packet); + break; + case DhcpPacket::DHCPDECLINE : + demon->executeDecline(packet); + break; + } + } + } +} + + + +void DhcpServerProgram::incTime() +{ + foreach ( DhcpDemon *demon, myDemons ) { + demon->incTime(); + } +} + +void DhcpServerProgram::showProperty() +{ + DhcpServerProperty *d = new DhcpServerProperty(myDevice); + d->setProgramm(this); + d->exec(); +} + +/*! + Записывает отличительные черты в поток. + @param stream - поток для записи. +*/ +void DhcpServerProgram::write(QDataStream &stream) const +{ + stream << DHCPServer; + Program::write(stream); + DhcpDemon *d = myDemons.at(0); + d->dhcpModel()->write(stream); + stream << d->interfaceName(); + stream << d->beginIp(); + stream << d->endIp(); + stream << d->mask(); + stream << d->gateway(); + stream << d->time(); + stream << d->dynamic(); + stream << d->waitingTime(); +} +//--------------------------------------------------- + +/*! + Считывает отличительные черты из потока. + @param stream - поток для чтения. +*/ +void DhcpServerProgram::read(QDataStream &stream) +{ + Program::read(stream); + DhcpDemon *d = new DhcpDemon(device()->interfaces().at(0)); + d->dhcpModel()->read(stream); + d->read(stream); +} +//--------------------------------------------------- + + + +//--------------------------------------------------- +//СlientState::СlientState(StaticDhcpRecord *rec) +//{ +// ip = rec->yiaddr; +// mac = rec->chaddr; +// mask = rec->mask; +// gateway = rec->gateway; +// time = rec->time; +//} + Copied: trunk/src/programs/dhcpserverprogram.h (from rev 240, trunk/src/programms/dhcpserverprogramm.h) =================================================================== --- trunk/src/programs/dhcpserverprogram.h (rev 0) +++ trunk/src/programs/dhcpserverprogram.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,63 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef DHCPSERVERPROGRAMM_H +#define DHCPSERVERPROGRAMM_H + +#include "program.h" +#include "dhcpdemon.h" + +class AbstractSocket; + +class DhcpServerProgram : public Program +{ + Q_OBJECT +public: + enum { DHCPServer = 2 }; + DhcpServerProgram(QObject *parent = 0); + ~DhcpServerProgram(); + +// Атрибуты +public: + int id() const { return DHCPServer; } + void setDevice(SmartDevice *s); + void setServerName(QString n) { myServerName = n; } + QString serverName() const { return myServerName; } + virtual QString featureName() const { return "ds"; } +public: + void showProperty(); + void incTime(); + bool interrupt(int) { return false; } + void write(QDataStream &stream) const; + void read(QDataStream &stream); + +// Слоты +public slots: + void execute(QByteArray data); +// void checkInterface(QString port); + +// Переменные +private: + static int myServerCount; + QString myServerName; + QList<DhcpDemon*> myDemons; + AbstractSocket *receiver; +}; + +#endif // DHCPSERVERPROGRAMM_H Deleted: trunk/src/programs/dhcpserverprogramm.cpp =================================================================== --- trunk/src/programms/dhcpserverprogramm.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpserverprogramm.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,159 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "dhcpserverprogramm.h" -#include "dhcpserverproperty.h" -#include "dhcppacket.h" -#include "smartdevice.h" -#include "udpsocket.h" -#include "socketfactory.h" -#include <QMessageBox> - -#include "dhcpservermodel.h" - -int DhcpServerProgram::myServerCount = 0; - -DhcpServerProgram::DhcpServerProgram(QObject *parent) : Program(parent) -{ - myName = tr("DHCP server"); - myServerCount++; - myServerName = QString("Server%1").arg(myServerCount); - myDemons.clear(); - qDeleteAll(myDemons); -} - -DhcpServerProgram::~DhcpServerProgram() -{ - myDevice->disposeSocket(receiver); - myDemons.clear(); - qDeleteAll(myDemons); -} - -void DhcpServerProgram::setDevice(SmartDevice *s) -{ - if ( s == 0 ) return; - Program::setDevice(s); - receiver = myDevice->openSocket(DhcpDemon::SERVER_SOCKET, SocketFactory::UDP); - //receiver = new udpSocket(myDevice, SERVER_SOCKET); - foreach ( Interface *i, myDevice->interfaces() ) { - if ( i->isConnect() ) { - DhcpDemon *demon = new DhcpDemon(i); - myDemons << demon; - } - } - receiver->setBind("0.0.0.0"); - connect( receiver , SIGNAL(readyRead(QByteArray)), SLOT(execute(QByteArray))); - connect( myDevice, SIGNAL(interfaceConnected(QString)), SLOT(checkInterface(QString)) ); -} - -//void dhcpServerProgramm::checkInterface(QString port) -//{ -// if ( myInterface.isEmpty() ) setInterfaceName(port); -//} - -void DhcpServerProgram::execute(QByteArray data) -{ - DhcpPacket packet(data); - foreach ( DhcpDemon *demon, myDemons ) { - IpAddress deviceIp = myDevice->adapter(demon->interfaceName())->ip(); - if ( deviceIp.isEmpty() ) { - QMessageBox::warning(0,tr("Warning"), - tr("Your DHCP server <i>%1</i> isn't configured.").arg(myServerName), - QMessageBox::Ok, QMessageBox::Ok); - return; - } - - if ( deviceIp == packet.siaddr() ) { - switch ( packet.type() ) { - case DhcpPacket::DHCPDISCOVER : - demon->executeDiscover(packet); - break; - case DhcpPacket::DHCPREQUEST : - demon->executeRequest(packet); - break; - case DhcpPacket::DHCPDECLINE : - demon->executeDecline(packet); - break; - } - } - } -} - - - -void DhcpServerProgram::incTime() -{ - foreach ( DhcpDemon *demon, myDemons ) { - demon->incTime(); - } -} - -void DhcpServerProgram::showProperty() -{ - DhcpServerProperty *d = new DhcpServerProperty(myDevice); - d->setProgramm(this); - d->exec(); -} - -/*! - Записывает отличительные черты в поток. - @param stream - поток для записи. -*/ -void DhcpServerProgram::write(QDataStream &stream) const -{ - stream << DHCPServer; - Program::write(stream); - DhcpDemon *d = myDemons.at(0); - d->dhcpModel()->write(stream); - stream << d->interfaceName(); - stream << d->beginIp(); - stream << d->endIp(); - stream << d->mask(); - stream << d->gateway(); - stream << d->time(); - stream << d->dynamic(); - stream << d->waitingTime(); -} -//--------------------------------------------------- - -/*! - Считывает отличительные черты из потока. - @param stream - поток для чтения. -*/ -void DhcpServerProgram::read(QDataStream &stream) -{ - Program::read(stream); - DhcpDemon *d = new DhcpDemon(device()->interfaces().at(0)); - d->dhcpModel()->read(stream); - d->read(stream); -} -//--------------------------------------------------- - - - -//--------------------------------------------------- -//СlientState::СlientState(StaticDhcpRecord *rec) -//{ -// ip = rec->yiaddr; -// mac = rec->chaddr; -// mask = rec->mask; -// gateway = rec->gateway; -// time = rec->time; -//} - Deleted: trunk/src/programs/dhcpserverprogramm.h =================================================================== --- trunk/src/programms/dhcpserverprogramm.h 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/dhcpserverprogramm.h 2011-02-11 23:05:12 UTC (rev 243) @@ -1,63 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#ifndef DHCPSERVERPROGRAMM_H -#define DHCPSERVERPROGRAMM_H - -#include "programmrep.h" -#include "dhcpdemon.h" - -class AbstractSocket; - -class DhcpServerProgram : public Program -{ - Q_OBJECT -public: - enum { DHCPServer = 2 }; - DhcpServerProgram(QObject *parent = 0); - ~DhcpServerProgram(); - -// Атрибуты -public: - int id() const { return DHCPServer; } - void setDevice(SmartDevice *s); - void setServerName(QString n) { myServerName = n; } - QString serverName() const { return myServerName; } - virtual QString featureName() const { return "ds"; } -public: - void showProperty(); - void incTime(); - bool interrupt(int) { return false; } - void write(QDataStream &stream) const; - void read(QDataStream &stream); - -// Слоты -public slots: - void execute(QByteArray data); -// void checkInterface(QString port); - -// Переменные -private: - static int myServerCount; - QString myServerName; - QList<DhcpDemon*> myDemons; - AbstractSocket *receiver; -}; - -#endif // DHCPSERVERPROGRAMM_H Copied: trunk/src/programs/program.cpp (from rev 240, trunk/src/programms/programmrep.cpp) =================================================================== --- trunk/src/programs/program.cpp (rev 0) +++ trunk/src/programs/program.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,87 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#include "program.h" +#include "smartdevice.h" +#include "ripprogram.h" +#include "dhcpserverprogram.h" +#include "dhcpclientprogram.h" +#include "spoofingprogram.h" + +static const int MAGIC_PROGRAMM_NUMBER = 50; + +Program::Program(QObject *parent) : QObject(parent) +{ +} + +Program::~Program() +{ +} + +void Program::setEnable(bool b) +{ + if ( b != myEnable ) { + myEnable = b; + } +} + +void Program::updateView() +{ + myDevice->updateView(); +} + +Program* Program::createFromStream(QObject *parent, QDataStream &stream) +{ + int n; + stream >> n; + Program *p = createImpl(parent,n); + p->read(stream); + return p; +} + +Program* Program::createImpl(QObject *parent, int n) +{ + switch (n%MAGIC_PROGRAMM_NUMBER) { + case RIP: return new RipProgram(parent); + case DHCPClient : return new DhcpClientProgram(parent); + case DHCPServer : return new DhcpServerProgram(parent); + case SPOOFING : return new SpoofingProgram(parent); + default: break; + } + return 0; +} + +/*! + Записывает программу в поток. + @param stream - поток для записи. +*/ +void Program::write(QDataStream &stream) const +{ + stream << myEnable; +} +//-------------------------------------------- +/*! + Считывает программу из потока. + @param stream - поток для чтения. +*/ +void Program::read(QDataStream &stream) +{ + stream >> myEnable; +} +//------------------------------------------- Copied: trunk/src/programs/program.h (from rev 240, trunk/src/programms/programmrep.h) =================================================================== --- trunk/src/programs/program.h (rev 0) +++ trunk/src/programs/program.h 2011-02-11 23:05:12 UTC (rev 243) @@ -0,0 +1,64 @@ +/**************************************************************************************** +** NetEmul - program for simulating computer networks. +** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia +** +** NetEmul is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** NetEmul is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with the NetEmul; if not, write to the Free +** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +** 02111-1307 USA. +****************************************************************************************/ +#ifndef PROGRAMMREP_H +#define PROGRAMMREP_H + +#include <QDataStream> + +class Device; +class SmartDevice; +class Program; + +typedef QList<Program*> ProgramList; + +class Program : public QObject +{ + Q_OBJECT + Q_PROPERTY( bool enable READ isEnable WRITE setEnable ) +public: + Program(QObject *parent = 0); + virtual ~Program(); + + static Program* createFromStream(QObject *parent , QDataStream &stream); + static Program* createImpl(QObject *parent , int n); + +public: + enum { RIP = 0 , DHCPClient = 1 , DHCPServer = 2, SPOOFING = 3 }; + + void setEnable(bool b); + bool isEnable() const { return myEnable; } + QString name() const { return myName; } + virtual void setDevice(SmartDevice *s) { myDevice = s; } + void updateView(); + SmartDevice* device() const { return myDevice; } + virtual bool interrupt(int u) = 0; + virtual void showProperty() = 0; + virtual QString featureName() const = 0; + virtual void incTime() { } + virtual void write(QDataStream &stream) const; + virtual void read(QDataStream &stream); + virtual int id() const = 0; +protected: + SmartDevice *myDevice; + bool myEnable; + QString myName; //!< Имя программы. +}; + +#endif // PROGRAMMREP_H Deleted: trunk/src/programs/programmrep.cpp =================================================================== --- trunk/src/programms/programmrep.cpp 2011-02-11 21:27:21 UTC (rev 240) +++ trunk/src/programs/programmrep.cpp 2011-02-11 23:05:12 UTC (rev 243) @@ -1,87 +0,0 @@ -/**************************************************************************************** -** NetEmul - program for simulating computer networks. -** Copyright © 2009 Semenov Pavel and Omilaeva Anastasia -** -** NetEmul is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** NetEmul is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with the NetEmul; if not, write to the Free -** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -** 02111-1307 USA. -****************************************************************************************/ -#include "programmrep.h" -#include "smartdevice.h" -#include "ripprogramm.h" -#include "dhcpserverprogramm.h" -#include "dhcpclientprogramm.h" -#include "spoofingprogramm.h" - -static const int MAGIC_PROGRAMM_NUMBER = 50; - -Program::Program(QObject *parent) : QObject(parent) -{ -} - -Program::~Program() -{ -} - -void Program::setEnable(bool b) -{ - if ( b != myEnable ) { - myEnable = b; - } -} - -void Program::updateView() -{ - myDevice->updateView(); -} - -Program* Program::createFromStream(QObject *parent, QDataStream &stream) -{ - int n; - str... [truncated message content] |