summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/network_NNI.cpp
authorwimpie <wimpie>2004-04-02 18:29:49 (UTC)
committer wimpie <wimpie>2004-04-02 18:29:49 (UTC)
commit5334b639c9f97793bcae4f50f7b47c7a2ada4e2f (patch) (side-by-side diff)
treef55aebd4314ab878bc39b6b08b8323a8ef78d803 /noncore/settings/networksettings2/network/network_NNI.cpp
parent7c8922b37b5bb7696c0ff2cbc999e2936b9b509f (diff)
downloadopie-5334b639c9f97793bcae4f50f7b47c7a2ada4e2f.zip
opie-5334b639c9f97793bcae4f50f7b47c7a2ada4e2f.tar.gz
opie-5334b639c9f97793bcae4f50f7b47c7a2ada4e2f.tar.bz2
First import of NS2 app
Diffstat (limited to 'noncore/settings/networksettings2/network/network_NNI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/network/network_NNI.cpp170
1 files changed, 170 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp
new file mode 100644
index 0000000..7130764
--- a/dev/null
+++ b/noncore/settings/networksettings2/network/network_NNI.cpp
@@ -0,0 +1,170 @@
+#include <system.h>
+#include <asdevice.h>
+#include "networkedit.h"
+#include "network_NNI.h"
+#include "network_NN.h"
+
+ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) {
+ Data.UseDHCP = 1;
+ Data.IPAddress = "";
+ Data.NetMask = "";
+ Data.Broadcast = "";
+ Data.Gateway = "";
+ Data.DNS1 = "";
+ Data.DNS2 = "";
+ Data.SendHostname = 0;
+ Data.Hostname = "";
+ Data.PreUp_SL.clear();
+ Data.PreDown_SL.clear();
+ Data.PostUp_SL.clear();
+ Data.PostDown_SL.clear();
+ GUI = 0;
+ RT = 0;
+}
+
+void ANetwork::setSpecificAttribute( QString & A, QString & V ) {
+ if( A == "usedhcp" ) {
+ Data.UseDHCP = (V == "yes");
+ } else if( A == "sendhostname" ) {
+ Data.SendHostname = (V=="yes");
+ } else if( A == "hostname" ) {
+ Data.Hostname = V;
+ } else if( A == "ipaddress" ) {
+ Data.IPAddress = V;
+ } else if( A == "netmask" ) {
+ Data.NetMask = V;
+ } else if( A == "broadcast" ) {
+ Data.Broadcast = V;
+ } else if( A == "gateway" ) {
+ Data.Gateway = V;
+ } else if( A == "dns1" ) {
+ Data.DNS1 = V;
+ } else if( A == "dns2" ) {
+ Data.DNS2 = V;
+ } else if( A == "preup" ) {
+ Data.PreUp_SL.append( V );
+ } else if( A == "predown" ) {
+ Data.PreDown_SL.append( V );
+ } else if( A == "postup" ) {
+ Data.PostUp_SL.append( V );
+ } else if( A == "postdown" ) {
+ Data.PostDown_SL.append( V );
+ }
+}
+
+void ANetwork::saveSpecificAttribute( QTextStream & TS ) {
+ TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl;
+ TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl;
+ TS << "hostname=" << Data.Hostname << endl;
+ TS << "ipaddress=" << Data.IPAddress << endl;
+ TS << "netmask=" << Data.NetMask << endl;
+ TS << "broadcast=" << Data.Broadcast << endl;
+ TS << "gateway=" << Data.Gateway << endl;
+ TS << "dns1=" << Data.DNS1 << endl;
+ TS << "dns2=" << Data.DNS2 << endl;
+ for ( QStringList::Iterator it = Data.PreUp_SL.begin();
+ it != Data.PreUp_SL.end();
+ ++it ) {
+ TS << "preup=" << quote(*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PreDown_SL.begin();
+ it != Data.PreDown_SL.end();
+ ++it ) {
+ TS << "predown=" << quote(*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PostUp_SL.begin();
+ it != Data.PostUp_SL.end();
+ ++it ) {
+ TS << "postup=" << quote(*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PostDown_SL.begin();
+ it != Data.PostDown_SL.end();
+ ++it ) {
+ TS << "postdown=" << quote(*it) << endl;
+ }
+}
+
+QWidget * ANetwork::edit( QWidget * parent ) {
+ GUI = new NetworkEdit( parent );
+ GUI->showData( Data );
+ return GUI;
+}
+
+QString ANetwork::acceptable( void ) {
+ return ( GUI ) ? GUI->acceptable( ) : QString();
+}
+
+void ANetwork::commit( void ) {
+ if( GUI && GUI->commit( Data ) )
+ setModified( 1 );
+}
+
+bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) {
+ AsDevice * Dev = runtime()->device();
+ QString NIC = Dev->genNic( DevNr );
+
+ if( S.name() == "interfaces" ) {
+ // generate mapping stanza for this interface
+ S << "# check if " << NIC << " can be brought UP" << endl;
+ S << "mapping " << NIC << endl;
+ S << " script networksettings2-request" << endl << endl;
+
+ // we can safely call from here since device item is deeper
+ if( Data.UseDHCP ) {
+ S << "iface " << NIC << "-c" << connection()->number() <<
+ "-allowed inet dhcp" << endl;
+ S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() <<
+ ".up" << Data.IPAddress << endl;
+ if( Data.SendHostname ) {
+ S << " hostname "<< Data.Hostname << endl;
+ }
+
+ S << " down rm -f /tmp/profile-" << connection()->number() <<
+ ".up" << Data.IPAddress << endl;
+ } else {
+ S << "iface " << NIC << "-c" << connection()->number() <<
+ "-allowed inet static" << endl;
+ S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() <<
+ ".up" << Data.IPAddress << endl;
+ S << " down rm -f /tmp/profile-" << connection()->number() <<
+ ".up" << Data.IPAddress << endl;
+ S << " address " << Data.IPAddress << endl;
+ S << " broadcast " << Data.Broadcast << endl;
+ S << " netmask " << Data.NetMask << endl;
+
+ // derive network address = IPAddress & netmask
+ { QString NW;
+ QStringList ipal = QStringList::split( '.', Data.IPAddress );
+ QStringList nmal = QStringList::split( '.', Data.NetMask );
+
+ NW = QString( "%1.%2.%3.%4" ).
+ arg( ipal[0].toShort() & nmal[0].toShort() ).
+ arg( ipal[1].toShort() & nmal[1].toShort() ).
+ arg( ipal[2].toShort() & nmal[2].toShort() ).
+ arg( ipal[3].toShort() & nmal[3].toShort() );
+ S << " network " << NW << endl;
+ }
+ }
+ for ( QStringList::Iterator it = Data.PreUp_SL.begin();
+ it != Data.PreUp_SL.end();
+ ++it ) {
+ S << " pre-up " << (*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PostUp_SL.begin();
+ it != Data.PostUp_SL.end();
+ ++it ) {
+ S << " up " << (*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PreDown_SL.begin();
+ it != Data.PreDown_SL.end();
+ ++it ) {
+ S << " down " << (*it) << endl;
+ }
+ for ( QStringList::Iterator it = Data.PostDown_SL.begin();
+ it != Data.PostDown_SL.end();
+ ++it ) {
+ S << " post-down " << (*it) << endl;
+ }
+ }
+ return 0;
+}