// Custom includes
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <net/if.h>
#include "../Utils/Exception.hh"
#define prefix_
return std::string( ifr.ifr_name);
}
+prefix_ void senf::NetdeviceController::interfaceName(const std::string & newname)
+{
+ if (sizeof(newname) <= IFNAMSIZ) {
+ struct ifreq ifr;
+ ifrName(ifr);
+ strncpy(ifr. ifr_newname, newname.c_str(), IFNAMSIZ);
+ try {
+ doIoctl(ifr, SIOCSIFNAME);
+ } catch (senf::SystemException e) {
+ e << "Could not change the interface name. Is the interface really down?";
+ throw ;
+ }
+ }
+ return;
+}
+
prefix_ senf::MACAddress senf::NetdeviceController::hardwareAddress()
const
{
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);
+ try {
+ doIoctl(ifr, SIOCSIFHWADDR);
+ } catch (senf::SystemException e) {
+ e << "Could not change the interface MAC address. Is the interface really down?";
+ throw ;
+ }
}
prefix_ int senf::NetdeviceController::mtu()
}
prefix_ void senf::NetdeviceController::mtu(int new_mtu)
- const
{
struct ifreq ifr;
ifrName( ifr);
{
sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0);
if ( sockfd_ < 0)
- throw SystemException("Could not open socket for NetdeviceController.");
+ SENF_THROW_SYSTEM_EXCEPTION("Could not open socket for NetdeviceController.");
}
prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr)
::memset( &ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = ifindex_;
if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 )
- throw SystemException("NetdeviceController")
+ SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController")
<< " could not discover the name of the interface with index " << ifindex_ << ".";
}
const
{
if ( ::ioctl( sockfd_, request, &ifr ) < 0 )
- throw SystemException("NetdeviceController::doIoctl failed.");
+ SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController::doIoctl failed.");
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "NetdeviceController.mpp"
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100