summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp11
-rw-r--r--libopie2/opienet/onetwork.h4
2 files changed, 15 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
@@ -123,48 +123,59 @@ int 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
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 0a51108..93b129f 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -73,48 +73,52 @@ class OMonitoringInterface;
73 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 73 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
74 */ 74 */
75class ONetwork : public QObject 75class ONetwork : public QObject
76{ 76{
77 Q_OBJECT 77 Q_OBJECT
78 78
79 public: 79 public:
80 typedef QDict<ONetworkInterface> InterfaceMap; 80 typedef QDict<ONetworkInterface> InterfaceMap;
81 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 81 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
82 82
83 public: 83 public:
84 /** 84 /**
85 * @returns the number of available interfaces 85 * @returns the number of available interfaces
86 */ 86 */
87 int count() const; 87 int count() const;
88 /** 88 /**
89 * @returns a pointer to the (one and only) @ref ONetwork instance. 89 * @returns a pointer to the (one and only) @ref ONetwork instance.
90 */ 90 */
91 static ONetwork* instance(); 91 static ONetwork* instance();
92 /** 92 /**
93 * @returns an iterator usable for iterating through all network interfaces. 93 * @returns an iterator usable for iterating through all network interfaces.
94 */ 94 */
95 InterfaceIterator iterator() const; 95 InterfaceIterator iterator() const;
96 /** 96 /**
97 * @returns true, if the @a interface is present.
98 */
99 bool isPresent( const char* interface ) const;
100 /**
97 * @returns true, if the @a interface supports the wireless extension protocol. 101 * @returns true, if the @a interface supports the wireless extension protocol.
98 */ 102 */
99 bool isWirelessInterface( const char* interface ) const; 103 bool isWirelessInterface( const char* interface ) const;
100 /** 104 /**
101 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. 105 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found.
102 * @see ONetworkInterface 106 * @see ONetworkInterface
103 */ 107 */
104 ONetworkInterface* interface( const QString& interface ) const; 108 ONetworkInterface* interface( const QString& interface ) const;
105 /** 109 /**
106 * @internal Rebuild the internal interface database 110 * @internal Rebuild the internal interface database
107 * @note Sometimes it might be useful to call this from client code, 111 * @note Sometimes it might be useful to call this from client code,
108 * e.g. after issuing a cardctl insert 112 * e.g. after issuing a cardctl insert
109 */ 113 */
110 void synchronize(); 114 void synchronize();
111 /** 115 /**
112 * @returns the wireless extension version used at compile time. 116 * @returns the wireless extension version used at compile time.
113 **/ 117 **/
114 static short wirelessExtensionVersion(); 118 static short wirelessExtensionVersion();
115 119
116 protected: 120 protected:
117 ONetwork(); 121 ONetwork();
118 122
119 private: 123 private:
120 static ONetwork* _instance; 124 static ONetwork* _instance;