X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FNetdeviceController.cc;h=fc43cc1ddfdd770c4f98b8dc589e5a81ee08a666;hb=63f4ccfd1186c135b54d3f8d8679c18118dda946;hp=57e43fd1e2f0b7e7712f4228e124ed761ce17c21;hpb=b72c25d581c908c9ed8217d03f7f628f1fcc7702;p=senf.git diff --git a/Socket/NetdeviceController.cc b/Socket/NetdeviceController.cc index 57e43fd..fc43cc1 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 @@ -30,7 +30,6 @@ // Custom includes #include #include -#include #include "../Utils/Exception.hh" #define prefix_ @@ -53,36 +52,42 @@ prefix_ senf::NetdeviceController::NetdeviceController(int interface_index) } prefix_ std::string senf::NetdeviceController::interfaceName() + const { struct ifreq ifr; - ifr_name( ifr); + ifrName( ifr); return std::string( ifr.ifr_name); } prefix_ senf::MACAddress senf::NetdeviceController::hardwareAddress() + const { struct ifreq ifr; + ifrName( ifr); doIoctl( ifr, SIOCGIFHWADDR); return senf::MACAddress::from_data( ifr.ifr_hwaddr.sa_data); } prefix_ int senf::NetdeviceController::mtu() + const { struct ifreq ifr; - ifr_name(ifr); + ifrName( ifr); doIoctl( ifr, SIOCGIFMTU); return ifr.ifr_mtu; } prefix_ void senf::NetdeviceController::mtu(int new_mtu) + const { struct ifreq ifr; - ifr_name( ifr); + ifrName( ifr); ifr.ifr_mtu = new_mtu; doIoctl( ifr, SIOCSIFMTU); } prefix_ int senf::NetdeviceController::interfaceIndex() + const { return ifindex_; } @@ -96,22 +101,24 @@ prefix_ void senf::NetdeviceController::openSocket() { sockfd_ = ::socket( PF_INET, SOCK_DGRAM, 0); if ( sockfd_ < 0) - throwErrno(); + throw SystemException( "Could not open socket for NetdeviceController"); } -prefix_ void senf::NetdeviceController::ifr_name(ifreq& ifr) +prefix_ void senf::NetdeviceController::ifrName(ifreq& ifr) + const { ::memset( &ifr, 0, sizeof(ifr)); ifr.ifr_ifindex = ifindex_; if ( ::ioctl( sockfd_, SIOCGIFNAME, &ifr ) < 0 ) - throwErrno(); + throw SystemException( + "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(); + throw SystemException(); } ///////////////////////////////cc.e////////////////////////////////////////