NetdeviceController.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
18 #ifndef HH_SENF_Socket_NetdeviceController_
19 #define HH_SENF_Socket_NetdeviceController_ 1
20 
21 // Custom includes
22 #include <string>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/filesystem.hpp>
25 
26 
27 //#include "NetdeviceController.mpp"
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 struct ifreq;
31 
32 namespace senf {
33 
34  struct MACAddress;
35 
36 
45  {
46  public:
47  explicit NetdeviceController(std::string const & interface_name);
49  explicit NetdeviceController(int interface_index);
51  void reset(std::string const & interface_name);
53  int interfaceIndex() const;
56  void hardwareAddress(MACAddress const & newAddress);
58 
63  std::string interfaceName() const;
65  void interfaceName(std::string const & newName);
67 
73  int mtu() const;
74  void mtu(int new_mtu);
75 
80  int txqueuelen() const;
81  void txqueuelen(int new_mtu);
82 
86  bool promisc() const;
87  void promisc(bool mode);
88 
90  void addVLAN(std::uint16_t vlanId);
92 
93  void delVLAN(std::uint16_t vlanId);
95 
97  void timestamping(int txType, int rxFilter);
99 
102  bool isUp() const;
103  void up();
104  void down();
105 
106  struct SockFd {
107  typedef boost::shared_ptr<SockFd> ptr;
108  int fd;
109  SockFd();
110  ~SockFd();
111  };
112 
113  static SockFd::ptr sockfd();
114 
115  static std::string macToName(MACAddress const & mac);
116  static MACAddress readMACAddressFromFile(boost::filesystem::path const & path);
117 
118  protected:
119  void ifrName(ifreq & ifr) const;
121  int ifindex_;
122  };
123 
124 }
125 
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
127 //#include "NetdeviceController.cci"
128 //#include "NetdeviceController.ct"
129 //#include "NetdeviceController.cti"
130 //#include "NetdeviceController.mpp"
131 #endif
132 
133 
134 // Local Variables:
135 // mode: c++
136 // fill-column: 100
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // comment-column: 40
142 // End:
int mtu() const
return the Maximum Transmission Unit
void timestamping(int txType, int rxFilter)
configures hw timestamping for RX and/or TX
Netdevice Controller.
void addVLAN(std::uint16_t vlanId)
add a VLAN interface
Ethernet MAC address.
Definition: MACAddress.hh:72
void up()
ifconfig up interface
bool isUp() const
return true if interface is up
void reset(std::string const &interface_name)
reset the ifindex_ from the given iface_name (i.e. after USB Ethernet unplug/plug ...
int txqueuelen() const
return the Tx Queue Length
void ifrName(ifreq &ifr) const
boost::shared_ptr< SockFd > ptr
void down()
ifconfig down interface
bool promisc() const
return true if interface is in promiscuous mode
MACAddress hardwareAddress() const
return hardware address
void delVLAN(std::uint16_t vlanId)
delete a VLAN interface
int interfaceIndex() const
return the interface index
NetdeviceController(std::string const &interface_name)
Construct a new controller for the given interface name.
static MACAddress readMACAddressFromFile(boost::filesystem::path const &path)
std::string interfaceName() const
return interface name
static std::string macToName(MACAddress const &mac)