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.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1deb051..0649ca2 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,10 +1,9 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =.
5 .=l. 4 .=l.
6           .>+-= 5           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
@@ -82,16 +81,12 @@ ONetwork::ONetwork()
82 synchronize(); 81 synchronize();
83} 82}
84 83
85void ONetwork::synchronize() 84void ONetwork::synchronize()
86{ 85{
87 // gather available interfaces by inspecting /proc/net/dev 86 // gather available interfaces by inspecting /proc/net/dev
88 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
89 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
90 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
91
92 _interfaces.clear(); 87 _interfaces.clear();
93 QString str; 88 QString str;
94 QFile f( "/proc/net/dev" ); 89 QFile f( "/proc/net/dev" );
95 bool hasFile = f.open( IO_ReadOnly ); 90 bool hasFile = f.open( IO_ReadOnly );
96 if ( !hasFile ) 91 if ( !hasFile )
97 { 92 {
@@ -199,13 +194,12 @@ struct ifreq& ONetworkInterface::ifr() const
199} 194}
200 195
201 196
202void ONetworkInterface::init() 197void ONetworkInterface::init()
203{ 198{
204 odebug << "ONetworkInterface::init()" << oendl; 199 odebug << "ONetworkInterface::init()" << oendl;
205
206 memset( &_ifr, 0, sizeof( struct ifreq ) ); 200 memset( &_ifr, 0, sizeof( struct ifreq ) );
207 201
208 if ( _sfd == -1 ) 202 if ( _sfd == -1 )
209 { 203 {
210 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; 204 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
211 return; 205 return;
@@ -267,23 +261,16 @@ void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
267 sa->sin_port = 0; 261 sa->sin_port = 0;
268 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 262 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
269 ioctl( SIOCSIFADDR ); 263 ioctl( SIOCSIFADDR );
270} 264}
271 265
272 266
273QString ONetworkInterface::ipV4Address() const 267OHostAddress ONetworkInterface::ipV4Address() const
274{ 268{
275 if ( ioctl( SIOCGIFADDR ) ) 269 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
276 { 270 return ioctl( SIOCGIFADDR ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
277 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
278 //FIXME: Use QHostAddress here
279 return QString( inet_ntoa( sa->sin_addr ) );
280 }
281 else
282 return "<unknown>";
283
284} 271}
285 272
286 273
287void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 274void ONetworkInterface::setMacAddress( const OMacAddress& addr )
288{ 275{
289 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 276 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
@@ -312,22 +299,16 @@ void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
312 sa->sin_port = 0; 299 sa->sin_port = 0;
313 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 300 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
314 ioctl( SIOCSIFNETMASK ); 301 ioctl( SIOCSIFNETMASK );
315} 302}
316 303
317 304
318QString ONetworkInterface::ipV4Netmask() const 305OHostAddress ONetworkInterface::ipV4Netmask() const
319{ 306{
320 if ( ioctl( SIOCGIFNETMASK ) ) 307 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
321 { 308 return ioctl( SIOCGIFNETMASK ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
322 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
323 //FIXME: Use QHostAddress here
324 return QString( inet_ntoa( sa->sin_addr ) );
325 }
326 else
327 return "<unknown>";
328} 309}
329 310
330 311
331int ONetworkInterface::dataLinkType() const 312int ONetworkInterface::dataLinkType() const
332{ 313{
333 if ( ioctl( SIOCGIFHWADDR ) ) 314 if ( ioctl( SIOCGIFHWADDR ) )
@@ -544,13 +525,21 @@ void OWirelessNetworkInterface::buildInformation()
544 memset( buffer, 0, len ); 525 memset( buffer, 0, len );
545 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 526 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
546 wrq.u.data.pointer = (caddr_t) buffer; 527 wrq.u.data.pointer = (caddr_t) buffer;
547 wrq.u.data.length = sizeof buffer; 528 wrq.u.data.length = sizeof buffer;
548 wrq.u.data.flags = 0; 529 wrq.u.data.flags = 0;
549 530
550 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 531 int result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
532 if ( result == -1 )
533 {
534 owarn << "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (" << strerror( errno ) << ") - retrying with smaller buffer..." << oendl;
535 wrq.u.data.length = sizeof( struct iw_range );
536 result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
537 }
538
539 if ( result == -1 )
551 { 540 {
552 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get driver information (" << strerror( errno ) << ") - using default values." << oendl; 541 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get driver information (" << strerror( errno ) << ") - using default values." << oendl;
553 _channels.insert( 2412, 1 ); // 2.412 GHz 542 _channels.insert( 2412, 1 ); // 2.412 GHz
554 _channels.insert( 2417, 2 ); // 2.417 GHz 543 _channels.insert( 2417, 2 ); // 2.417 GHz
555 _channels.insert( 2422, 3 ); // 2.422 GHz 544 _channels.insert( 2422, 3 ); // 2.422 GHz
556 _channels.insert( 2427, 4 ); // 2.427 GHz 545 _channels.insert( 2427, 4 ); // 2.427 GHz