summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
committer mickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
commitd2ae68c413873e234b34f733818427902e738948 (patch) (unidiff)
treef5748014d7b1785302c167c6f43fbd0622bf1019 /libopie2
parentcce15d6b9a27880df72ea2638f9295900ea6c21e (diff)
downloadopie-d2ae68c413873e234b34f733818427902e738948.zip
opie-d2ae68c413873e234b34f733818427902e738948.tar.gz
opie-d2ae68c413873e234b34f733818427902e738948.tar.bz2
libopienet API cleanups
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp19
-rw-r--r--libopie2/opienet/onetutils.h8
-rw-r--r--libopie2/opienet/onetwork.cpp43
-rw-r--r--libopie2/opienet/onetwork.h7
4 files changed, 39 insertions, 38 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index c8c494a..9c3e650 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,8 +1,6 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3 =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
5 =.
6 .=l. 4 .=l.
7           .>+-= 5           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
@@ -136,6 +134,21 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
136 * OHostAddress 134 * OHostAddress
137 *======================================================================================*/ 135 *======================================================================================*/
138 136
137OHostAddress::OHostAddress()
138 :QHostAddress()
139{
140}
141
142
143OHostAddress::OHostAddress( Q_UINT32 ip4Addr )
144 :QHostAddress( ip4Addr )
145{
146}
147
148
149OHostAddress::~OHostAddress()
150{
151}
139 152
140/*====================================================================================== 153/*======================================================================================
141 * OPrivateIOCTL 154 * OPrivateIOCTL
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 25c9238..f08738c 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,7 +1,6 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2003-2005 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
@@ -89,10 +88,11 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
89 88
90class OHostAddress : public QHostAddress 89class OHostAddress : public QHostAddress
91{ 90{
92 /*public: 91 public:
93 OHostAddress(); 92 OHostAddress();
93 OHostAddress( Q_UINT32 ip4Addr );
94 ~OHostAddress(); 94 ~OHostAddress();
95 */ 95
96 private: 96 private:
97 class Private; 97 class Private;
98 Private *d; 98 Private *d;
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,7 +1,6 @@
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
@@ -85,10 +84,6 @@ ONetwork::ONetwork()
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" );
@@ -202,7 +197,6 @@ struct ifreq& ONetworkInterface::ifr() const
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 )
@@ -270,17 +264,10 @@ void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
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
@@ -315,16 +302,10 @@ void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
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
@@ -547,7 +528,15 @@ void OWirelessNetworkInterface::buildInformation()
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
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f0c4450..b13c7a3 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,7 +1,6 @@
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
@@ -198,7 +197,7 @@ class ONetworkInterface : public QObject
198 /** 197 /**
199 * @returns the IPv4 address associated with the interface. 198 * @returns the IPv4 address associated with the interface.
200 */ 199 */
201 QString ipV4Address() const; //TODO: make this return an OHostAddress 200 OHostAddress ipV4Address() const;
202 /** 201 /**
203 * Associate the MAC address @a addr with the interface. 202 * Associate the MAC address @a addr with the interface.
204 * @note It can be necessary to shut down the interface prior to calling this method. 203 * @note It can be necessary to shut down the interface prior to calling this method.
@@ -217,7 +216,7 @@ class ONetworkInterface : public QObject
217 /** 216 /**
218 * @returns the IPv4 netmask associated with the interface. 217 * @returns the IPv4 netmask associated with the interface.
219 */ 218 */
220 QString ipV4Netmask() const; //TODO: make this return an OHostAddress 219 OHostAddress ipV4Netmask() const;
221 /** 220 /**
222 * @returns the data link type currently associated with the interface. 221 * @returns the data link type currently associated with the interface.
223 * @see #include <net/if_arp.h> for possible values. 222 * @see #include <net/if_arp.h> for possible values.