doIoctl( ifr, SIOCSIFMTU);
}
+prefix_ bool senf::NetdeviceController::promisc()
+ const
+{
+ struct ifreq ifr;
+ ifrName( ifr);
+ doIoctl( ifr, SIOCGIFFLAGS);
+ return ifr.ifr_flags & IFF_PROMISC;
+}
+
+prefix_ void senf::NetdeviceController::promisc(bool mode)
+{
+ struct ifreq ifr;
+ ifrName( ifr);
+ doIoctl( ifr, SIOCGIFFLAGS);
+ if (mode)
+ ifr.ifr_flags |= IFF_PROMISC;
+ else
+ ifr.ifr_flags &= ~IFF_PROMISC;
+ doIoctl( ifr, SIOCSIFFLAGS);
+}
+
prefix_ int senf::NetdeviceController::interfaceIndex()
const
{
devices. Note, that some setting members are privileged operations.
\see manual page netdevice(7) for more informations.
-
- \todo Add 'promisc' member to enable/disable promiscuous mode
*/
class NetdeviceController
{
void hardwareAddress(const MACAddress &newAddress);
///< set hardware address
/**< Changes the hardware address of the interface.
- Note, that setting the hardware address is a privileged operation. It is only allowed when the interface
- is not up. If the interface is up, this call will cause an SystemException to be thrown.*/
+ Note, that setting the hardware address is a privileged
+ operation. It is only allowed when the interface is not
+ up. If the interface is up, this call will cause an
+ SystemException to be thrown. */
std::string interfaceName() const;
///< return interface name
void interfaceName(const std::string &newName);
///< set interface name
/**< Changes the name of the interface.
- Note, that setting the name is a privileged operation. It is only allowed when the interface
- is not up. If the interface is up, this call will cause an SystemException to be thrown.*/
+ Note, that setting the name is a privileged operation.
+ It is only allowed when the interface is not up. If
+ the interface is up, this call will cause an
+ SystemException to be thrown. */
int mtu() const; ///< return the Maximum Transmission Unit
void mtu(int new_mtu); ///< set the Maximum Transmission Unit
/**< Set the MTU (Maximum Transfer Unit) of the device.
Note, that this is a privileged operation.
- Setting the MTU to too small values may cause kernel crashes. */
+ Setting the MTU to too small values may cause kernel
+ crashes. */
+
+ bool promisc() const; ///< return \c true if interface is in promiscuous mode
+ void promisc(bool mode); ///< enable/disable promiscuous mode of the interface
+ /**< Note, that this is a privileged operation. */
+
private:
void openSocket();
void doIoctl(ifreq& ifr, int request) const;
int oldMTU;
SENF_CHECK_NO_THROW( oldMTU = ctrl.mtu());
+
+ bool promisc;
+ SENF_CHECK_NO_THROW( promisc = ctrl.promisc());
if (getuid() != 0) {
BOOST_WARN_MESSAGE(false, "Cannot run some tests of senf::NetdeviceController as non-root user");
SENF_CHECK_NO_THROW( ctrl.mtu(oldMTU));
BOOST_CHECK_EQUAL( ctrl.mtu(), oldMTU);
+ SENF_CHECK_NO_THROW( ctrl.promisc( !promisc));
+ BOOST_CHECK_EQUAL( ctrl.promisc(), !promisc);
+ SENF_CHECK_NO_THROW( ctrl.promisc( promisc));
+ BOOST_CHECK_EQUAL( ctrl.promisc(), promisc);
}
///////////////////////////////cc.e////////////////////////////////////////
/** \brief %Daemon process
- %senf::Daemon provides simple management for daemon processes. Specifically, the %Daemon class
- implements
+ The %Daemon class provides simple management for daemon processes. Specifically, it implements
\li <i>Safe startup.</i> If the startup fails, the foreground process which launches the
daemon will terminate with an appropriate error exit code.
\li <i>Straight forward application initialization.</i> The daemon process is forked before