Utils/Termlib: Extend the completion API
[senf.git] / Socket / NetdeviceController.hh
index 4f2ced0..e969cda 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2007
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Thorsten Horstmann <tho@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
     \brief NetdeviceController public header
  */
 
-#ifndef HH_NetdeviceController_
-#define HH_NetdeviceController_ 1
+#ifndef HH_SENF_Socket_NetdeviceController_
+#define HH_SENF_Socket_NetdeviceController_ 1
 
 // Custom includes
 #include <string>
-#include <net/if.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
 #include "Protocols/Raw/MACAddress.hh"
 
 
 //#include "NetdeviceController.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
 
+struct ifreq;
+
 namespace senf {
 
-    /** \brief NetdeviceController
-     
-        \todo document me
+    /** \brief Netdevice Controller
+
+        This controller provides an interface which can be used to configure network
+        devices. Note, that some setting members are privileged operations.
+
+        \see manual page netdevice(7) for more informations.
      */
     class NetdeviceController
     {
     public:
-        NetdeviceController(std::string const & interface_name);
-        NetdeviceController(int interface_index);
-        virtual ~NetdeviceController();
-        
-        MACAddress hardwareAddress();
-        std::string interfaceName();
-        int interfaceIndex(); ///< return the interface index of the interface
-        int mtu();
-        void mtu(int new_mtu);
-    
+        explicit NetdeviceController(std::string const & interface_name);
+                                        ///< Construct a new controller for the given interface name.
+        explicit NetdeviceController(int interface_index);
+                                        ///< Construct a new controller for the given interface index.
+        int interfaceIndex() const;     ///< return the interface index
+        MACAddress hardwareAddress() const;
+                                        ///< return hardware address
+        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. */
+        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. */
+
+        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. */
+
+        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. */
+
+        bool isUp() const;              ///< return \c true if interface is up
+        void up();                      ///< ifconfig up interface
+        void down();                    ///< ifconfig down interface
+
+        struct SockFd {
+            typedef boost::shared_ptr<SockFd> ptr;
+            int fd;
+            SockFd();
+            ~SockFd();
+        };
+
+        static SockFd::ptr sockfd();
+
     private:
-        void openSocket();
-        void doIoctl(ifreq& ifr, int request);
-        void ifrName(ifreq& ifr);
-        int sockfd_;
+        void doIoctl(ifreq& ifr, int request) const;
+        void ifrName(ifreq& ifr) const;
+        SockFd::ptr sockfd_;
         int ifindex_;
     };
 
@@ -72,7 +115,7 @@ namespace senf {
 //#include "NetdeviceController.mpp"
 #endif
 
-\f
+
 // Local Variables:
 // mode: c++
 // fill-column: 100