5f8096818bbde58c8f74f065a3d7ed3f8d80d0c8
[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         \todo Add 'promisc' member to enable/disable promiscuous mode
49      */
50     class NetdeviceController
51     {
52     public:
53         NetdeviceController(std::string const & interface_name);
54                                         ///< Construct a new controller for the given interface name.
55         NetdeviceController(int interface_index);
56                                         ///< Construct a new controller for the given interface index.
57         virtual ~NetdeviceController();
58
59         int interfaceIndex() const;     ///< return the interface index
60         MACAddress hardwareAddress() const;
61                                         ///< return hardware address
62         void hardwareAddress(const MACAddress &newAddress);
63                                         ///< set hardware address
64                                         /**< Changes the hardware address of the interface.
65                                              Note, that setting the hardware address is a privileged operation. It is only allowed when the interface
66                                              is not up. If the interface is up, this call will cause an 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. It is only allowed when the interface
73                                              is not up. If the interface is up, this call will cause an SystemException to be thrown.*/
74
75         int mtu() const;                ///< return the Maximum Transmission Unit
76         void mtu(int new_mtu);          ///< set the Maximum Transmission Unit
77                                         /**< Set the MTU (Maximum Transfer Unit) of the device.
78                                              Note, that this is a privileged operation.
79                                              Setting the MTU to too small values may cause kernel crashes. */
80     private:
81         void openSocket();
82         void doIoctl(ifreq& ifr, int request) const;
83         void ifrName(ifreq& ifr) const;
84         int sockfd_;
85         int ifindex_;
86     };
87
88 }
89
90 ///////////////////////////////hh.e////////////////////////////////////////
91 //#include "NetdeviceController.cci"
92 //#include "NetdeviceController.ct"
93 //#include "NetdeviceController.cti"
94 //#include "NetdeviceController.mpp"
95 #endif
96
97
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40
106 // End: