X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FNetdeviceController.hh;h=e969cda37bf0bd13a1927154b6e23b315f52444a;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=5f8096818bbde58c8f74f065a3d7ed3f8d80d0c8;hpb=560113811e6d51fffb4ca004e7342ec362234cd2;p=senf.git diff --git a/Socket/NetdeviceController.hh b/Socket/NetdeviceController.hh index 5f80968..e969cda 100644 --- a/Socket/NetdeviceController.hh +++ b/Socket/NetdeviceController.hh @@ -29,13 +29,16 @@ // Custom includes #include -#include +#include +#include #include "Protocols/Raw/MACAddress.hh" //#include "NetdeviceController.mpp" ///////////////////////////////hh.p//////////////////////////////////////// +struct ifreq; + namespace senf { /** \brief Netdevice Controller @@ -44,44 +47,62 @@ 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 { public: - NetdeviceController(std::string const & interface_name); + explicit NetdeviceController(std::string const & interface_name); ///< Construct a new controller for the given interface name. - NetdeviceController(int interface_index); + explicit NetdeviceController(int interface_index); ///< Construct a new controller for the given interface index. - virtual ~NetdeviceController(); - 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.*/ + 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. */ + + 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 ptr; + int fd; + SockFd(); + ~SockFd(); + }; + + static SockFd::ptr sockfd(); + private: - void openSocket(); void doIoctl(ifreq& ifr, int request) const; void ifrName(ifreq& ifr) const; - int sockfd_; + SockFd::ptr sockfd_; int ifindex_; };