f0796b061792cf535246a9590d577d78d58b1f7a
[senf.git] / senf / 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 <boost/shared_ptr.hpp>
33
34 //#include "NetdeviceController.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 struct ifreq;
38
39 namespace senf {
40
41     class MACAddress;
42
43
44     /** \brief Netdevice Controller
45
46         This controller provides an interface which can be used to configure network
47         devices. Note, that some setting members are privileged operations.
48
49         \see manual page netdevice(7) for more informations.
50      */
51     class NetdeviceController
52     {
53     public:
54         explicit NetdeviceController(std::string const & interface_name);
55                                         ///< Construct a new controller for the given interface name.
56         explicit NetdeviceController(int interface_index);
57                                         ///< Construct a new controller for the given interface index.
58         int interfaceIndex() const;     ///< return the interface index
59         MACAddress hardwareAddress() const;
60                                         ///< return hardware address
61         void hardwareAddress(MACAddress const & newAddress);
62                                         ///< set hardware address
63                                         /**< Changes the hardware address of the interface.
64                                              Note, that setting the hardware address is a privileged
65                                              operation. It is only allowed when the interface is not
66                                              up. If the interface is up, this call will cause an
67                                              SystemException to be thrown. */
68         std::string interfaceName() const;
69                                         ///< return interface name
70         void interfaceName(std::string const & newName);
71                                         ///< set interface name
72                                         /**< Changes the name of the interface.
73                                              Note, that setting the name is a privileged operation.
74                                              It is only allowed when the interface is not up. If
75                                              the interface is up, this call will cause an
76                                              SystemException to be thrown. */
77
78         int mtu() const;                ///< return the Maximum Transmission Unit
79         void mtu(int new_mtu);          ///< set the Maximum Transmission Unit
80                                         /**< Set the MTU (Maximum Transfer Unit) of the device.
81                                              Note, that this is a privileged operation.
82                                              Setting the MTU to too small values may cause kernel
83                                              crashes. */
84
85         int txqueuelen() const;         ///< return the Tx Queue Length
86         void txqueuelen(int new_mtu);   ///< set the Tx Queue Length
87                                         /**< Set the Tx Queue Length (in Packets) MTU of the device.
88                                              Note, that this is a privileged operation. */
89
90
91         bool promisc() const;           ///< return \c true if interface is in promiscuous mode
92         void promisc(bool mode);        ///< enable/disable promiscuous mode of the interface
93                                         /**< Note, that this is a privileged operation. */
94
95         bool isUp() const;              ///< return \c true if interface is up
96         void up();                      ///< ifconfig up interface
97         void down();                    ///< ifconfig down interface
98
99         struct SockFd {
100             typedef boost::shared_ptr<SockFd> ptr;
101             int fd;
102             SockFd();
103             ~SockFd();
104         };
105
106         static SockFd::ptr sockfd();
107
108     private:
109         void ifrName(ifreq & ifr) const;
110         SockFd::ptr sockfd_;
111         int ifindex_;
112     };
113
114 }
115
116 ///////////////////////////////hh.e////////////////////////////////////////
117 //#include "NetdeviceController.cci"
118 //#include "NetdeviceController.ct"
119 //#include "NetdeviceController.cti"
120 //#include "NetdeviceController.mpp"
121 #endif
122
123 \f
124 // Local Variables:
125 // mode: c++
126 // fill-column: 100
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"
131 // comment-column: 40
132 // End: