X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FNetdeviceController.cc;h=07466c69fceaa352b3db4ae30c2658f2ef4a6a82;hb=275e7f8a473a1b04516f2db9ba7cbb81e7fa53b7;hp=771746e5fc0dba74fac105099c0db39a5b93a6f7;hpb=3709bcfb0ddddc278f07ddc5fc21e06b5bce7115;p=senf.git diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc index 771746e..07466c6 100644 --- a/Socket/NetdeviceController.cc +++ b/Socket/NetdeviceController.cc @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Thorsten Horstmann +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ prefix_ senf::NetdeviceController::NetdeviceController(int interface_index) } prefix_ std::string senf::NetdeviceController::interfaceName() + const { struct ifreq ifr; ifrName( ifr); @@ -59,6 +60,7 @@ prefix_ std::string senf::NetdeviceController::interfaceName() } prefix_ senf::MACAddress senf::NetdeviceController::hardwareAddress() + const { struct ifreq ifr; ifrName( ifr); @@ -66,7 +68,16 @@ 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 { struct ifreq ifr; ifrName( ifr); @@ -75,6 +86,7 @@ prefix_ int senf::NetdeviceController::mtu() } prefix_ void senf::NetdeviceController::mtu(int new_mtu) + const { struct ifreq ifr; ifrName( ifr); @@ -83,6 +95,7 @@ prefix_ void senf::NetdeviceController::mtu(int new_mtu) } prefix_ int senf::NetdeviceController::interfaceIndex() + const { return ifindex_; } @@ -96,22 +109,24 @@ prefix_ void senf::NetdeviceController::openSocket() { sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0); if ( sockfd_ < 0) - throwErrno(); + SENF_THROW_SYSTEM_EXCEPTION("Could not open socket for NetdeviceController."); } prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr) + const { ::memset( &ifr, 0, sizeof(ifr)); ifr.ifr_ifindex = ifindex_; if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 ) - throwErrno(); + SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController") + << " could not discover the name of the interface with index " << ifindex_ << "."; } - prefix_ void senf::NetdeviceController::doIoctl(ifreq& ifr, int request) + const { if ( ::ioctl( sockfd_, request, &ifr ) < 0 ) - throwErrno(); + SENF_THROW_SYSTEM_EXCEPTION("NetdeviceController::doIoctl failed."); } ///////////////////////////////cc.e////////////////////////////////////////