summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-04 23:20:06 (UTC)
committer mickeyl <mickeyl>2003-04-04 23:20:06 (UTC)
commite4c19111590664371c359878e5c79428bc7b02c9 (patch) (unidiff)
tree359c86228f9587415e60ffa1f6614e7e2cbc0153
parent998e0da2ba2823f6048f420d69386b2265247e81 (diff)
downloadopie-e4c19111590664371c359878e5c79428bc7b02c9.zip
opie-e4c19111590664371c359878e5c79428bc7b02c9.tar.gz
opie-e4c19111590664371c359878e5c79428bc7b02c9.tar.bz2
fix segfault due to giving a QString as opposed to a char* as the Qbject name
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 6a363d7..f52279a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -34,210 +34,210 @@
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <cerrno> 46#include <cerrno>
47#include <cstring> 47#include <cstring>
48#include <cstdlib> 48#include <cstdlib>
49#include <math.h> 49#include <math.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/socket.h> 51#include <sys/socket.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <linux/sockios.h> 54#include <linux/sockios.h>
55#include <net/if_arp.h> 55#include <net/if_arp.h>
56#include <stdarg.h> 56#include <stdarg.h>
57 57
58using namespace std; 58using namespace std;
59 59
60/*====================================================================================== 60/*======================================================================================
61 * ONetwork 61 * ONetwork
62 *======================================================================================*/ 62 *======================================================================================*/
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, 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, 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( 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()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 173bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 179 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, name() ); 186 strcpy( _ifr.ifr_name, name() );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227OMacAddress ONetworkInterface::macAddress() const 227OMacAddress ONetworkInterface::macAddress() const
228{ 228{
229 if ( ioctl( SIOCGIFHWADDR ) ) 229 if ( ioctl( SIOCGIFHWADDR ) )
230 { 230 {
231 return OMacAddress( _ifr ); 231 return OMacAddress( _ifr );
232 } 232 }
233 else 233 else
234 { 234 {
235 return OMacAddress::unknown; 235 return OMacAddress::unknown;
236 } 236 }
237} 237}
238 238
239 239
240int ONetworkInterface::dataLinkType() const 240int ONetworkInterface::dataLinkType() const
241{ 241{
242 if ( ioctl( SIOCGIFHWADDR ) ) 242 if ( ioctl( SIOCGIFHWADDR ) )
243 { 243 {
@@ -617,131 +617,131 @@ QString OWirelessNetworkInterface::nickName() const
617 } 617 }
618} 618}
619 619
620 620
621void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 621void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
622{ 622{
623 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 623 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
624 if ( !priv ) 624 if ( !priv )
625 { 625 {
626 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 626 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
627 return; 627 return;
628 } 628 }
629 if ( priv->numberSetArgs() != numargs ) 629 if ( priv->numberSetArgs() != numargs )
630 { 630 {
631 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 631 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
632 return; 632 return;
633 } 633 }
634 634
635 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 635 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
636 memset( &_iwr, 0, sizeof _iwr ); 636 memset( &_iwr, 0, sizeof _iwr );
637 va_list argp; 637 va_list argp;
638 va_start( argp, numargs ); 638 va_start( argp, numargs );
639 for ( int i = 0; i < numargs; ++i ) 639 for ( int i = 0; i < numargs; ++i )
640 { 640 {
641 priv->setParameter( i, va_arg( argp, int ) ); 641 priv->setParameter( i, va_arg( argp, int ) );
642 } 642 }
643 va_end( argp ); 643 va_end( argp );
644 priv->invoke(); 644 priv->invoke();
645} 645}
646 646
647 647
648void OWirelessNetworkInterface::getPrivate( const QString& call ) 648void OWirelessNetworkInterface::getPrivate( const QString& call )
649{ 649{
650} 650}
651 651
652 652
653QString OWirelessNetworkInterface::SSID() const 653QString OWirelessNetworkInterface::SSID() const
654{ 654{
655 char str[IW_ESSID_MAX_SIZE]; 655 char str[IW_ESSID_MAX_SIZE];
656 _iwr.u.essid.pointer = &str[0]; 656 _iwr.u.essid.pointer = &str[0];
657 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 657 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
658 if ( !wioctl( SIOCGIWESSID ) ) 658 if ( !wioctl( SIOCGIWESSID ) )
659 { 659 {
660 return "<unknown>"; 660 return "<unknown>";
661 } 661 }
662 else 662 else
663 { 663 {
664 return str; 664 return str;
665 } 665 }
666} 666}
667 667
668 668
669void OWirelessNetworkInterface::setSSID( const QString& ssid ) 669void OWirelessNetworkInterface::setSSID( const QString& ssid )
670{ 670{
671 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 671 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
672 _iwr.u.essid.length = ssid.length(); 672 _iwr.u.essid.length = ssid.length();
673 wioctl( SIOCSIWESSID ); 673 wioctl( SIOCSIWESSID );
674} 674}
675 675
676 676
677bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 677bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
678{ 678{
679 int result = ::ioctl( _sfd, call, &iwreq ); 679 int result = ::ioctl( _sfd, call, &iwreq );
680 if ( result == -1 ) 680 if ( result == -1 )
681 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 681 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
682 else 682 else
683 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 683 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
684 return ( result != -1 ); 684 return ( result != -1 );
685} 685}
686 686
687 687
688bool OWirelessNetworkInterface::wioctl( int call ) const 688bool OWirelessNetworkInterface::wioctl( int call ) const
689{ 689{
690 strcpy( _iwr.ifr_name, name() ); 690 strcpy( _iwr.ifr_name, name() );
691 return wioctl( call, _iwr ); 691 return wioctl( call, _iwr );
692} 692}
693 693
694 694
695/*====================================================================================== 695/*======================================================================================
696 * OMonitoringInterface 696 * OMonitoringInterface
697 *======================================================================================*/ 697 *======================================================================================*/
698 698
699OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 699OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
700 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) 700 :_if( static_cast<OWirelessNetworkInterface*>( iface ) )
701{ 701{
702} 702}
703 703
704 704
705OMonitoringInterface::~OMonitoringInterface() 705OMonitoringInterface::~OMonitoringInterface()
706{ 706{
707} 707}
708 708
709 709
710void OMonitoringInterface::setChannel( int c ) 710void OMonitoringInterface::setChannel( int c )
711{ 711{
712 // use standard WE channel switching protocol 712 // use standard WE channel switching protocol
713 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 713 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
714 _if->_iwr.u.freq.m = c; 714 _if->_iwr.u.freq.m = c;
715 _if->_iwr.u.freq.e = 0; 715 _if->_iwr.u.freq.e = 0;
716 _if->wioctl( SIOCSIWFREQ ); 716 _if->wioctl( SIOCSIWFREQ );
717} 717}
718 718
719 719
720bool OMonitoringInterface::enabled() const 720bool OMonitoringInterface::enabled() const
721{ 721{
722 return _if->monitorMode(); 722 return _if->monitorMode();
723} 723}
724 724
725 725
726void OMonitoringInterface::setEnabled( bool b ) 726void OMonitoringInterface::setEnabled( bool b )
727{ 727{
728} 728}
729 729
730 730
731/*====================================================================================== 731/*======================================================================================
732 * OCiscoMonitoringInterface 732 * OCiscoMonitoringInterface
733 *======================================================================================*/ 733 *======================================================================================*/
734 734
735OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 735OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
736 :OMonitoringInterface( iface ) 736 :OMonitoringInterface( iface )
737{ 737{
738 iface->setMonitoring( this ); 738 iface->setMonitoring( this );
739} 739}
740 740
741 741
742OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 742OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
743{ 743{
744} 744}
745 745
746 746
747void OCiscoMonitoringInterface::setEnabled( bool b ) 747void OCiscoMonitoringInterface::setEnabled( bool b )