From 01c477ee15b098377b1768ee31aebfd51bc641ae Mon Sep 17 00:00:00 2001
From: tho <tho@wiback.org>
Date: Thu, 26 Mar 2009 10:32:56 +0000
Subject: [PATCH] Socket/NetdeviceController: added promisc() methods

---
 Makefile                           |  3 +--
 Socket/NetdeviceController.cc      | 21 +++++++++++++++++++++
 Socket/NetdeviceController.hh      | 22 +++++++++++++++-------
 Socket/NetdeviceController.test.cc |  7 +++++++
 Utils/Console/Mainpage.dox         |  2 +-
 Utils/Daemon/Daemon.hh             |  3 +--
 6 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 10a82c96..532d737a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,7 @@
 #----------------------------------------------------------------------
 # Some SCONS shortcuts
 #----------------------------------------------------------------------
-
-CONCURRENCY_LEVEL ?= 2
+CONCURRENCY_LEVEL ?= $(shell grep process /proc/cpuinfo | wc -l)
 
 ifdef final
   SCONS_ARGS += "final="$(final)
diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc
index 7ce1f953..345679b3 100644
--- a/Socket/NetdeviceController.cc
+++ b/Socket/NetdeviceController.cc
@@ -115,6 +115,27 @@ prefix_ void senf::NetdeviceController::mtu(int new_mtu)
     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
 {
diff --git a/Socket/NetdeviceController.hh b/Socket/NetdeviceController.hh
index 5f809681..db7c5cf2 100644
--- a/Socket/NetdeviceController.hh
+++ b/Socket/NetdeviceController.hh
@@ -44,8 +44,6 @@ namespace senf {
         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
     {
@@ -62,21 +60,31 @@ namespace senf {
         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;
diff --git a/Socket/NetdeviceController.test.cc b/Socket/NetdeviceController.test.cc
index dcc8a3bc..24258ee1 100644
--- a/Socket/NetdeviceController.test.cc
+++ b/Socket/NetdeviceController.test.cc
@@ -48,6 +48,9 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) {
     
     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");
@@ -59,6 +62,10 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) {
     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////////////////////////////////////////
diff --git a/Utils/Console/Mainpage.dox b/Utils/Console/Mainpage.dox
index 16e73761..b46ce644 100644
--- a/Utils/Console/Mainpage.dox
+++ b/Utils/Console/Mainpage.dox
@@ -344,7 +344,7 @@
     The first possibility to control this is to change the root node. This is done by 
     \li passing that root node to the helper class or to the parse helper as an additional argument
         (see the respective documentation).
-    \li passing it to the senf:;console::ConfigBundle constructor when parsing multiple sources.
+    \li passing it to the senf::console::ConfigBundle constructor when parsing multiple sources.
     
     for example:
 
diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh
index e38a62c0..f0d3e6b5 100644
--- a/Utils/Daemon/Daemon.hh
+++ b/Utils/Daemon/Daemon.hh
@@ -37,8 +37,7 @@ namespace senf {
 
     /** \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
-- 
GitLab