summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (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
{
return _interfaces.count();
}
ONetworkInterface* ONetwork::interface( const QString& iface ) const
{
return _interfaces[iface];
}
ONetwork* ONetwork::instance()
{
if ( !_instance ) _instance = new ONetwork();
return _instance;
}
ONetwork::InterfaceIterator ONetwork::iterator() const
{
return ONetwork::InterfaceIterator( _interfaces );
}
+bool ONetwork::isPresent( const char* name ) const
+{
+ int sfd = socket( AF_INET, SOCK_STREAM, 0 );
+ struct ifreq ifr;
+ memset( &ifr, 0, sizeof( struct ifreq ) );
+ strcpy( (char*) &ifr.ifr_name, name );
+ int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
+ return result != -1;
+}
+
+
bool ONetwork::isWirelessInterface( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct iwreq iwr;
memset( &iwr, 0, sizeof( struct iwreq ) );
strcpy( (char*) &iwr.ifr_name, name );
int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
return result != -1;
}
/*======================================================================================
* ONetworkInterface
*======================================================================================*/
ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
:QObject( parent, name ),
_sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
{
odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
init();
}
struct 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;
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class ONetwork : public QObject
{
Q_OBJECT
public:
typedef QDict<ONetworkInterface> InterfaceMap;
typedef QDictIterator<ONetworkInterface> InterfaceIterator;
public:
/**
* @returns the number of available interfaces
*/
int count() const;
/**
* @returns a pointer to the (one and only) @ref ONetwork instance.
*/
static ONetwork* instance();
/**
* @returns an iterator usable for iterating through all network interfaces.
*/
InterfaceIterator iterator() const;
/**
+ * @returns true, if the @a interface is present.
+ */
+ bool isPresent( const char* interface ) const;
+ /**
* @returns true, if the @a interface supports the wireless extension protocol.
*/
bool isWirelessInterface( const char* interface ) const;
/**
* @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found.
* @see ONetworkInterface
*/
ONetworkInterface* interface( const QString& interface ) const;
/**
* @internal Rebuild the internal interface database
* @note Sometimes it might be useful to call this from client code,
* e.g. after issuing a cardctl insert
*/
void synchronize();
/**
* @returns the wireless extension version used at compile time.
**/
static short wirelessExtensionVersion();
protected:
ONetwork();
private:
static ONetwork* _instance;