Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 41 |
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 @@ -110,2 +110,8 @@ void ONetwork::synchronize() +int ONetwork::count() const +{ + return _interfaces.count(); +} + + ONetworkInterface* ONetwork::interface( const QString& iface ) const @@ -213,2 +219,12 @@ bool ONetworkInterface::isUp() const +void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) +{ + struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; + sa->sin_family = AF_INET; + sa->sin_port = 0; + sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); + ioctl( SIOCSIFADDR ); +} + + QString ONetworkInterface::ipV4Address() const @@ -217,3 +233,3 @@ QString ONetworkInterface::ipV4Address() const { - struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; + struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; //FIXME: Use QHostAddress here @@ -247,2 +263,25 @@ OMacAddress ONetworkInterface::macAddress() const +void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) +{ + struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; + sa->sin_family = AF_INET; + sa->sin_port = 0; + sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); + ioctl( SIOCSIFNETMASK ); +} + + +QString ONetworkInterface::ipV4Netmask() const +{ + if ( ioctl( SIOCGIFNETMASK ) ) + { + struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; + //FIXME: Use QHostAddress here + return QString( inet_ntoa( sa->sin_addr ) ); + } + else + return "<unknown>"; +} + + int ONetworkInterface::dataLinkType() const |