switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / NetdeviceController.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief NetdeviceController public header
30  */
31
32 #ifndef HH_SENF_Socket_NetdeviceController_
33 #define HH_SENF_Socket_NetdeviceController_ 1
34
35 // Custom includes
36 #include <string>
37 #include <boost/shared_ptr.hpp>
38
39 //#include "NetdeviceController.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 struct ifreq;
43
44 namespace senf {
45
46     class MACAddress;
47
48
49     /** \brief Netdevice Controller
50
51         This controller provides an interface which can be used to configure network
52         devices. Note, that some setting members are privileged operations.
53
54         \see manual page netdevice(7) for more informations.
55      */
56     class NetdeviceController
57     {
58     public:
59         explicit NetdeviceController(std::string const & interface_name);
60                                         ///< Construct a new controller for the given interface name.
61         explicit NetdeviceController(int interface_index);
62                                         ///< Construct a new controller for the given interface index.
63         int interfaceIndex() const;     ///< return the interface index
64         MACAddress hardwareAddress() const;
65                                         ///< return hardware address
66         void hardwareAddress(MACAddress const & newAddress);
67                                         ///< set hardware address
68                                         /**< Changes the hardware address of the interface.
69                                              Note, that setting the hardware address is a privileged
70                                              operation. It is only allowed when the interface is not
71                                              up. If the interface is up, this call will cause an
72                                              SystemException to be thrown. */
73         std::string interfaceName() const;
74                                         ///< return interface name
75         void interfaceName(std::string const & newName);
76                                         ///< set interface name
77                                         /**< Changes the name of the interface.
78                                              Note, that setting the name is a privileged operation.
79                                              It is only allowed when the interface is not up. If
80                                              the interface is up, this call will cause an
81                                              SystemException to be thrown. */
82
83         int mtu() const;                ///< return the Maximum Transmission Unit
84         void mtu(int new_mtu);          ///< set the Maximum Transmission Unit
85                                         /**< Set the MTU (Maximum Transfer Unit) of the device.
86                                              Note, that this is a privileged operation.
87                                              Setting the MTU to too small values may cause kernel
88                                              crashes. */
89
90         int txqueuelen() const;         ///< return the Tx Queue Length
91         void txqueuelen(int new_mtu);   ///< set the Tx Queue Length
92                                         /**< Set the Tx Queue Length (in Packets) MTU of the device.
93                                              Note, that this is a privileged operation. */
94
95
96         bool promisc() const;           ///< return \c true if interface is in promiscuous mode
97         void promisc(bool mode);        ///< enable/disable promiscuous mode of the interface
98                                         /**< Note, that this is a privileged operation. */
99
100         bool isUp() const;              ///< return \c true if interface is up
101         void up();                      ///< ifconfig up interface
102         void down();                    ///< ifconfig down interface
103
104         struct SockFd {
105             typedef boost::shared_ptr<SockFd> ptr;
106             int fd;
107             SockFd();
108             ~SockFd();
109         };
110
111         static SockFd::ptr sockfd();
112
113     private:
114         void ifrName(ifreq & ifr) const;
115         SockFd::ptr sockfd_;
116         int ifindex_;
117     };
118
119 }
120
121 //-/////////////////////////////////////////////////////////////////////////////////////////////////
122 //#include "NetdeviceController.cci"
123 //#include "NetdeviceController.ct"
124 //#include "NetdeviceController.cti"
125 //#include "NetdeviceController.mpp"
126 #endif
127
128 \f
129 // Local Variables:
130 // mode: c++
131 // fill-column: 100
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // comment-column: 40
137 // End: