return senf::MACAddress::from_data( ifr.ifr_hwaddr.sa_data);
}
+prefix_ void senf::NetdeviceController::hardwareAddress(const MACAddress &newAddress) {
+ struct ifreq ifr;
+ ifrName( ifr);
+ ifr.ifr_hwaddr.sa_family = 1; // TODO: lookup named constant; PF_LOCAL ???
+ std::copy(newAddress.begin(), newAddress.end(), ifr.ifr_hwaddr.sa_data);
+ doIoctl( ifr, SIOCSIFHWADDR);
+}
+
prefix_ int senf::NetdeviceController::mtu()
const
{
NetdeviceController(int interface_index);
virtual ~NetdeviceController();
- MACAddress hardwareAddress() const;
- std::string interfaceName() const;
- int interfaceIndex() const; ///< return the interface index of the interface
- int mtu() const;
- void mtu(int new_mtu) const;
+ int interfaceIndex() const; ///< return the interface index
+ MACAddress hardwareAddress() const; ///< return hardware address
+ void hardwareAddress(const MACAddress &newAddress); ///< set hardware address
+
+ std::string interfaceName() const; ///< return interface name
+ void interfaceName(const std::string &newName) const; ///< set interface name
+
+ int mtu() const; ///< return the Maximum Transmission Unit
+ void mtu(int new_mtu) const; //< set the Maximum Transmission Unit
+
private:
void openSocket();
void doIoctl(ifreq& ifr, int request) const;
// Custom includes
#include "NetdeviceController.hh"
+#include "Protocols/Raw/MACAddress.hh"
#include "../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-BOOST_AUTO_UNIT_TEST(NetdeviceController)
-{
-// senf::NetdeviceController ctrl ("eth0");
-// std::cout << ctrl.hardwareAddress() << "\n";
+BOOST_AUTO_UNIT_TEST(NetdeviceController) {
+
+ senf::NetdeviceController ctrl ("wlan0");
+ std::cout << "name: " << ctrl.interfaceName() << "\n";
+
+ senf::MACAddress oldAddr(ctrl.hardwareAddress());
+ int oldMTU = ctrl.mtu();
+
+ std::cout << "hw addr: " << oldAddr << "\n";
+ std::cout << "mtu: " << oldMTU << "\n";
+
+ if (getuid() != 0) {
+ BOOST_WARN_MESSAGE(false, "Cannot run some tests of senf::NetdeviceController as non-root user");
+ return;
+ }
+
+ ctrl.mtu(oldMTU - 16);
+ std::cout << "new mtu: " << ctrl.mtu() << "\n";
+ ctrl.mtu(oldMTU);
+
+ senf::MACAddress newAddr(senf::MACAddress::from_string("00:18:de:2e:ec:00"));
+ ctrl.hardwareAddress(newAddr);
+ std::cout << "new hw addr: " << ctrl.hardwareAddress() << "\n";
+ ctrl.hardwareAddress(oldAddr);
}
///////////////////////////////cc.e////////////////////////////////////////