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.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index f0094c7..be2736a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -105,12 +105,18 @@ void ONetwork::synchronize()
105 _interfaces.insert( str, iface ); 105 _interfaces.insert( str, iface );
106 s.readLine(); 106 s.readLine();
107 } 107 }
108} 108}
109 109
110 110
111int ONetwork::count() const
112{
113 return _interfaces.count();
114}
115
116
111ONetworkInterface* ONetwork::interface( const QString& iface ) const 117ONetworkInterface* ONetwork::interface( const QString& iface ) const
112{ 118{
113 return _interfaces[iface]; 119 return _interfaces[iface];
114} 120}
115 121
116 122
@@ -208,17 +214,27 @@ bool ONetworkInterface::isUp() const
208{ 214{
209 ioctl( SIOCGIFFLAGS ); 215 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 216 return _ifr.ifr_flags & IFF_UP;
211} 217}
212 218
213 219
220void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
221{
222 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
223 sa->sin_family = AF_INET;
224 sa->sin_port = 0;
225 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
226 ioctl( SIOCSIFADDR );
227}
228
229
214QString ONetworkInterface::ipV4Address() const 230QString ONetworkInterface::ipV4Address() const
215{ 231{
216 if ( ioctl( SIOCGIFADDR ) ) 232 if ( ioctl( SIOCGIFADDR ) )
217 { 233 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 234 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 235 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 236 return QString( inet_ntoa( sa->sin_addr ) );
221 } 237 }
222 else 238 else
223 return "<unknown>"; 239 return "<unknown>";
224} 240}
@@ -242,12 +258,35 @@ OMacAddress ONetworkInterface::macAddress() const
242 { 258 {
243 return OMacAddress::unknown; 259 return OMacAddress::unknown;
244 } 260 }
245} 261}
246 262
247 263
264void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
265{
266 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
267 sa->sin_family = AF_INET;
268 sa->sin_port = 0;
269 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
270 ioctl( SIOCSIFNETMASK );
271}
272
273
274QString ONetworkInterface::ipV4Netmask() const
275{
276 if ( ioctl( SIOCGIFNETMASK ) )
277 {
278 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
279 //FIXME: Use QHostAddress here
280 return QString( inet_ntoa( sa->sin_addr ) );
281 }
282 else
283 return "<unknown>";
284}
285
286
248int ONetworkInterface::dataLinkType() const 287int ONetworkInterface::dataLinkType() const
249{ 288{
250 if ( ioctl( SIOCGIFHWADDR ) ) 289 if ( ioctl( SIOCGIFHWADDR ) )
251 { 290 {
252 return _ifr.ifr_hwaddr.sa_family; 291 return _ifr.ifr_hwaddr.sa_family;
253 } 292 }