Socket/NetdeviceController: added promisc() methods
[senf.git] / Socket / NetdeviceController.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief NetdeviceController public header
25  */
26
27 #ifndef HH_SENF_Socket_NetdeviceController_
28 #define HH_SENF_Socket_NetdeviceController_ 1
29
30 // Custom includes
31 #include <string>
32 #include <net/if.h>
33 #include "Protocols/Raw/MACAddress.hh"
34
35
36 //#include "NetdeviceController.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     /** \brief Netdevice Controller
42
43         This controller provides an interface which can be used to configure network
44         devices. Note, that some setting members are privileged operations.
45
46         \see manual page netdevice(7) for more informations.
47      */
48     class NetdeviceController
49     {
50     public:
51         NetdeviceController(std::string const & interface_name);
52                                         ///< Construct a new controller for the given interface name.
53         NetdeviceController(int interface_index);
54                                         ///< Construct a new controller for the given interface index.
55         virtual ~NetdeviceController();
56
57         int interfaceIndex() const;     ///< return the interface index
58         MACAddress hardwareAddress() const;
59                                         ///< return hardware address
60         void hardwareAddress(const MACAddress &newAddress);
61                                         ///< set hardware address
62                                         /**< Changes the hardware address of the interface.
63                                              Note, that setting the hardware address is a privileged
64                                              operation. It is only allowed when the interface is not
65                                              up. If the interface is up, this call will cause an
66                                              SystemException to be thrown. */
67         std::string interfaceName() const;
68                                         ///< return interface name
69         void interfaceName(const std::string &newName);
70                                         ///< set interface name
71                                         /**< Changes the name of the interface.
72                                              Note, that setting the name is a privileged operation. 
73                                              It is only allowed when the interface is not up. If 
74                                              the interface is up, this call will cause an 
75                                              SystemException to be thrown. */
76
77         int mtu() const;                ///< return the Maximum Transmission Unit
78         void mtu(int new_mtu);          ///< set the Maximum Transmission Unit
79                                         /**< Set the MTU (Maximum Transfer Unit) of the device.
80                                              Note, that this is a privileged operation.
81                                              Setting the MTU to too small values may cause kernel 
82                                              crashes. */
83
84         bool promisc() const;           ///< return \c true if interface is in promiscuous mode
85         void promisc(bool mode);        ///< enable/disable promiscuous mode of the interface
86                                         /**< Note, that this is a privileged operation. */
87                 
88     private:
89         void openSocket();
90         void doIoctl(ifreq& ifr, int request) const;
91         void ifrName(ifreq& ifr) const;
92         int sockfd_;
93         int ifindex_;
94     };
95
96 }
97
98 ///////////////////////////////hh.e////////////////////////////////////////
99 //#include "NetdeviceController.cci"
100 //#include "NetdeviceController.ct"
101 //#include "NetdeviceController.cti"
102 //#include "NetdeviceController.mpp"
103 #endif
104
105
106 // Local Variables:
107 // mode: c++
108 // fill-column: 100
109 // c-file-style: "senf"
110 // indent-tabs-mode: nil
111 // ispell-local-dictionary: "american"
112 // compile-command: "scons -u test"
113 // comment-column: 40
114 // End: