Skip to content
Snippets Groups Projects
Commit e0139e03 authored by jkaeber's avatar jkaeber
Browse files

Implemented void hardwareAddress(const MACAddress &newAddress)

parent 8bc82c36
No related branches found
No related tags found
No related merge requests found
......@@ -68,6 +68,14 @@ prefix_ senf::MACAddress senf::NetdeviceController::hardwareAddress()
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
{
......
......@@ -50,12 +50,17 @@ namespace senf {
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;
......
......@@ -27,6 +27,7 @@
// Custom includes
#include "NetdeviceController.hh"
#include "Protocols/Raw/MACAddress.hh"
#include "../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
......@@ -34,10 +35,30 @@
#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////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment