summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 73b543b..f0094c7 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -63,97 +63,97 @@ using namespace std;
63 63
64ONetwork* ONetwork::_instance = 0; 64ONetwork* ONetwork::_instance = 0;
65 65
66ONetwork::ONetwork() 66ONetwork::ONetwork()
67{ 67{
68 qDebug( "ONetwork::ONetwork()" ); 68 qDebug( "ONetwork::ONetwork()" );
69 synchronize(); 69 synchronize();
70} 70}
71 71
72void ONetwork::synchronize() 72void ONetwork::synchronize()
73{ 73{
74 // gather available interfaces by inspecting /proc/net/dev 74 // gather available interfaces by inspecting /proc/net/dev
75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
77 77
78 _interfaces.clear(); 78 _interfaces.clear();
79 QString str; 79 QString str;
80 QFile f( "/proc/net/dev" ); 80 QFile f( "/proc/net/dev" );
81 bool hasFile = f.open( IO_ReadOnly ); 81 bool hasFile = f.open( IO_ReadOnly );
82 if ( !hasFile ) 82 if ( !hasFile )
83 { 83 {
84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
85 return; 85 return;
86 } 86 }
87 QTextStream s( &f ); 87 QTextStream s( &f );
88 s.readLine(); 88 s.readLine();
89 s.readLine(); 89 s.readLine();
90 while ( !s.atEnd() ) 90 while ( !s.atEnd() )
91 { 91 {
92 s >> str; 92 s >> str;
93 str.truncate( str.find( ':' ) ); 93 str.truncate( str.find( ':' ) );
94 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 94 qDebug( "ONetwork: found interface '%s'", (const char*) str );
95 ONetworkInterface* iface; 95 ONetworkInterface* iface;
96 if ( isWirelessInterface( str ) ) 96 if ( isWirelessInterface( str ) )
97 { 97 {
98 iface = new OWirelessNetworkInterface( this, (const char*) str ); 98 iface = new OWirelessNetworkInterface( this, (const char*) str );
99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
100 } 100 }
101 else 101 else
102 { 102 {
103 iface = new ONetworkInterface( this, (const char*) str ); 103 iface = new ONetworkInterface( this, (const char*) str );
104 } 104 }
105 _interfaces.insert( str, iface ); 105 _interfaces.insert( str, iface );
106 s.readLine(); 106 s.readLine();
107 } 107 }
108} 108}
109 109
110 110
111ONetworkInterface* ONetwork::interface( QString iface ) const 111ONetworkInterface* ONetwork::interface( const QString& iface ) const
112{ 112{
113 return _interfaces[iface]; 113 return _interfaces[iface];
114} 114}
115 115
116 116
117ONetwork* ONetwork::instance() 117ONetwork* ONetwork::instance()
118{ 118{
119 if ( !_instance ) _instance = new ONetwork(); 119 if ( !_instance ) _instance = new ONetwork();
120 return _instance; 120 return _instance;
121} 121}
122 122
123 123
124ONetwork::InterfaceIterator ONetwork::iterator() const 124ONetwork::InterfaceIterator ONetwork::iterator() const
125{ 125{
126 return ONetwork::InterfaceIterator( _interfaces ); 126 return ONetwork::InterfaceIterator( _interfaces );
127} 127}
128 128
129 129
130bool ONetwork::isWirelessInterface( const char* name ) const 130bool ONetwork::isWirelessInterface( const char* name ) const
131{ 131{
132 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 132 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
133 struct iwreq iwr; 133 struct iwreq iwr;
134 memset( &iwr, 0, sizeof( struct iwreq ) ); 134 memset( &iwr, 0, sizeof( struct iwreq ) );
135 strcpy( (char*) &iwr.ifr_name, name ); 135 strcpy( (char*) &iwr.ifr_name, name );
136 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 136 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
137 return result != -1; 137 return result != -1;
138} 138}
139 139
140/*====================================================================================== 140/*======================================================================================
141 * ONetworkInterface 141 * ONetworkInterface
142 *======================================================================================*/ 142 *======================================================================================*/
143 143
144ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 144ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
145 :QObject( parent, name ), 145 :QObject( parent, name ),
146 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153struct ifreq& ONetworkInterface::ifr() const 153struct ifreq& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()