summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 915814d..e5b091f 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -99,96 +99,107 @@ void ONetwork::synchronize()
99 odebug << "ONetwork: found interface '" << str << "'" << oendl; 99 odebug << "ONetwork: found interface '" << str << "'" << oendl;
100 ONetworkInterface* iface; 100 ONetworkInterface* iface;
101 if ( isWirelessInterface( str ) ) 101 if ( isWirelessInterface( str ) )
102 { 102 {
103 iface = new OWirelessNetworkInterface( this, (const char*) str ); 103 iface = new OWirelessNetworkInterface( this, (const char*) str );
104 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; 104 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
105 } 105 }
106 else 106 else
107 { 107 {
108 iface = new ONetworkInterface( this, (const char*) str ); 108 iface = new ONetworkInterface( this, (const char*) str );
109 } 109 }
110 _interfaces.insert( str, iface ); 110 _interfaces.insert( str, iface );
111 s.readLine(); 111 s.readLine();
112 } 112 }
113} 113}
114 114
115 115
116short ONetwork::wirelessExtensionVersion() 116short ONetwork::wirelessExtensionVersion()
117{ 117{
118 return WIRELESS_EXT; 118 return WIRELESS_EXT;
119} 119}
120 120
121 121
122int ONetwork::count() const 122int ONetwork::count() const
123{ 123{
124 return _interfaces.count(); 124 return _interfaces.count();
125} 125}
126 126
127 127
128ONetworkInterface* ONetwork::interface( const QString& iface ) const 128ONetworkInterface* ONetwork::interface( const QString& iface ) const
129{ 129{
130 return _interfaces[iface]; 130 return _interfaces[iface];
131} 131}
132 132
133 133
134ONetwork* ONetwork::instance() 134ONetwork* ONetwork::instance()
135{ 135{
136 if ( !_instance ) _instance = new ONetwork(); 136 if ( !_instance ) _instance = new ONetwork();
137 return _instance; 137 return _instance;
138} 138}
139 139
140 140
141ONetwork::InterfaceIterator ONetwork::iterator() const 141ONetwork::InterfaceIterator ONetwork::iterator() const
142{ 142{
143 return ONetwork::InterfaceIterator( _interfaces ); 143 return ONetwork::InterfaceIterator( _interfaces );
144} 144}
145 145
146 146
147bool ONetwork::isPresent( const char* name ) const
148{
149 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
150 struct ifreq ifr;
151 memset( &ifr, 0, sizeof( struct ifreq ) );
152 strcpy( (char*) &ifr.ifr_name, name );
153 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
154 return result != -1;
155}
156
157
147bool ONetwork::isWirelessInterface( const char* name ) const 158bool ONetwork::isWirelessInterface( const char* name ) const
148{ 159{
149 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 160 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
150 struct iwreq iwr; 161 struct iwreq iwr;
151 memset( &iwr, 0, sizeof( struct iwreq ) ); 162 memset( &iwr, 0, sizeof( struct iwreq ) );
152 strcpy( (char*) &iwr.ifr_name, name ); 163 strcpy( (char*) &iwr.ifr_name, name );
153 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 164 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
154 return result != -1; 165 return result != -1;
155} 166}
156 167
157/*====================================================================================== 168/*======================================================================================
158 * ONetworkInterface 169 * ONetworkInterface
159 *======================================================================================*/ 170 *======================================================================================*/
160 171
161ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 172ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
162 :QObject( parent, name ), 173 :QObject( parent, name ),
163 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 174 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
164{ 175{
165 odebug << "ONetworkInterface::ONetworkInterface()" << oendl; 176 odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
166 init(); 177 init();
167} 178}
168 179
169 180
170struct ifreq& ONetworkInterface::ifr() const 181struct ifreq& ONetworkInterface::ifr() const
171{ 182{
172 return _ifr; 183 return _ifr;
173} 184}
174 185
175 186
176void ONetworkInterface::init() 187void ONetworkInterface::init()
177{ 188{
178 odebug << "ONetworkInterface::init()" << oendl; 189 odebug << "ONetworkInterface::init()" << oendl;
179 190
180 memset( &_ifr, 0, sizeof( struct ifreq ) ); 191 memset( &_ifr, 0, sizeof( struct ifreq ) );
181 192
182 if ( _sfd == -1 ) 193 if ( _sfd == -1 )
183 { 194 {
184 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; 195 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
185 return; 196 return;
186 } 197 }
187} 198}
188 199
189 200
190bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 201bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
191{ 202{
192 #ifndef NODEBUG 203 #ifndef NODEBUG
193 int result = ::ioctl( _sfd, call, &ifreq ); 204 int result = ::ioctl( _sfd, call, &ifreq );
194 if ( result == -1 ) 205 if ( result == -1 )