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) (unidiff)
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 @@
1#include <system.h>
2#include <asdevice.h>
3#include "networkedit.h"
4#include "network_NNI.h"
5#include "network_NN.h"
6
7ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) {
8 Data.UseDHCP = 1;
9 Data.IPAddress = "";
10 Data.NetMask = "";
11 Data.Broadcast = "";
12 Data.Gateway = "";
13 Data.DNS1 = "";
14 Data.DNS2 = "";
15 Data.SendHostname = 0;
16 Data.Hostname = "";
17 Data.PreUp_SL.clear();
18 Data.PreDown_SL.clear();
19 Data.PostUp_SL.clear();
20 Data.PostDown_SL.clear();
21 GUI = 0;
22 RT = 0;
23}
24
25void ANetwork::setSpecificAttribute( QString & A, QString & V ) {
26 if( A == "usedhcp" ) {
27 Data.UseDHCP = (V == "yes");
28 } else if( A == "sendhostname" ) {
29 Data.SendHostname = (V=="yes");
30 } else if( A == "hostname" ) {
31 Data.Hostname = V;
32 } else if( A == "ipaddress" ) {
33 Data.IPAddress = V;
34 } else if( A == "netmask" ) {
35 Data.NetMask = V;
36 } else if( A == "broadcast" ) {
37 Data.Broadcast = V;
38 } else if( A == "gateway" ) {
39 Data.Gateway = V;
40 } else if( A == "dns1" ) {
41 Data.DNS1 = V;
42 } else if( A == "dns2" ) {
43 Data.DNS2 = V;
44 } else if( A == "preup" ) {
45 Data.PreUp_SL.append( V );
46 } else if( A == "predown" ) {
47 Data.PreDown_SL.append( V );
48 } else if( A == "postup" ) {
49 Data.PostUp_SL.append( V );
50 } else if( A == "postdown" ) {
51 Data.PostDown_SL.append( V );
52 }
53}
54
55void ANetwork::saveSpecificAttribute( QTextStream & TS ) {
56 TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl;
57 TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl;
58 TS << "hostname=" << Data.Hostname << endl;
59 TS << "ipaddress=" << Data.IPAddress << endl;
60 TS << "netmask=" << Data.NetMask << endl;
61 TS << "broadcast=" << Data.Broadcast << endl;
62 TS << "gateway=" << Data.Gateway << endl;
63 TS << "dns1=" << Data.DNS1 << endl;
64 TS << "dns2=" << Data.DNS2 << endl;
65 for ( QStringList::Iterator it = Data.PreUp_SL.begin();
66 it != Data.PreUp_SL.end();
67 ++it ) {
68 TS << "preup=" << quote(*it) << endl;
69 }
70 for ( QStringList::Iterator it = Data.PreDown_SL.begin();
71 it != Data.PreDown_SL.end();
72 ++it ) {
73 TS << "predown=" << quote(*it) << endl;
74 }
75 for ( QStringList::Iterator it = Data.PostUp_SL.begin();
76 it != Data.PostUp_SL.end();
77 ++it ) {
78 TS << "postup=" << quote(*it) << endl;
79 }
80 for ( QStringList::Iterator it = Data.PostDown_SL.begin();
81 it != Data.PostDown_SL.end();
82 ++it ) {
83 TS << "postdown=" << quote(*it) << endl;
84 }
85}
86
87QWidget * ANetwork::edit( QWidget * parent ) {
88 GUI = new NetworkEdit( parent );
89 GUI->showData( Data );
90 return GUI;
91}
92
93QString ANetwork::acceptable( void ) {
94 return ( GUI ) ? GUI->acceptable( ) : QString();
95}
96
97void ANetwork::commit( void ) {
98 if( GUI && GUI->commit( Data ) )
99 setModified( 1 );
100}
101
102bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) {
103 AsDevice * Dev = runtime()->device();
104 QString NIC = Dev->genNic( DevNr );
105
106 if( S.name() == "interfaces" ) {
107 // generate mapping stanza for this interface
108 S << "# check if " << NIC << " can be brought UP" << endl;
109 S << "mapping " << NIC << endl;
110 S << " script networksettings2-request" << endl << endl;
111
112 // we can safely call from here since device item is deeper
113 if( Data.UseDHCP ) {
114 S << "iface " << NIC << "-c" << connection()->number() <<
115 "-allowed inet dhcp" << endl;
116 S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() <<
117 ".up" << Data.IPAddress << endl;
118 if( Data.SendHostname ) {
119 S << " hostname "<< Data.Hostname << endl;
120 }
121
122 S << " down rm -f /tmp/profile-" << connection()->number() <<
123 ".up" << Data.IPAddress << endl;
124 } else {
125 S << "iface " << NIC << "-c" << connection()->number() <<
126 "-allowed inet static" << endl;
127 S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() <<
128 ".up" << Data.IPAddress << endl;
129 S << " down rm -f /tmp/profile-" << connection()->number() <<
130 ".up" << Data.IPAddress << endl;
131 S << " address " << Data.IPAddress << endl;
132 S << " broadcast " << Data.Broadcast << endl;
133 S << " netmask " << Data.NetMask << endl;
134
135 // derive network address = IPAddress & netmask
136 { QString NW;
137 QStringList ipal = QStringList::split( '.', Data.IPAddress );
138 QStringList nmal = QStringList::split( '.', Data.NetMask );
139
140 NW = QString( "%1.%2.%3.%4" ).
141 arg( ipal[0].toShort() & nmal[0].toShort() ).
142 arg( ipal[1].toShort() & nmal[1].toShort() ).
143 arg( ipal[2].toShort() & nmal[2].toShort() ).
144 arg( ipal[3].toShort() & nmal[3].toShort() );
145 S << " network " << NW << endl;
146 }
147 }
148 for ( QStringList::Iterator it = Data.PreUp_SL.begin();
149 it != Data.PreUp_SL.end();
150 ++it ) {
151 S << " pre-up " << (*it) << endl;
152 }
153 for ( QStringList::Iterator it = Data.PostUp_SL.begin();
154 it != Data.PostUp_SL.end();
155 ++it ) {
156 S << " up " << (*it) << endl;
157 }
158 for ( QStringList::Iterator it = Data.PreDown_SL.begin();
159 it != Data.PreDown_SL.end();
160 ++it ) {
161 S << " down " << (*it) << endl;
162 }
163 for ( QStringList::Iterator it = Data.PostDown_SL.begin();
164 it != Data.PostDown_SL.end();
165 ++it ) {
166 S << " post-down " << (*it) << endl;
167 }
168 }
169 return 0;
170}