X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FTunTapSocketHandle.cc;h=f2be6452c6200eb089a60936e11517799f810773;hb=81f84badf27b66dbadec9890646ca1193e998505;hp=58170a0ffba696209a01803897331fe796607f03;hpb=034f9bec0a66d26314fb6ebc83dedf1618a2c19d;p=senf.git diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index 58170a0..f2be645 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund +// 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 @@ -21,8 +21,8 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief - + \brief + */ #include "TunTapSocketHandle.hh" @@ -39,13 +39,13 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ void senf::TapSocketProtocol::init_client() +prefix_ void senf::TapSocketProtocol::init_client() const { init_client(std::string()); } -prefix_ void senf::TapSocketProtocol::init_client(std::string const & interface_name, bool const NO_PI) +prefix_ void senf::TapSocketProtocol::init_client(std::string const & interface_name, bool NO_PI) const { int f; @@ -59,19 +59,20 @@ prefix_ void senf::TapSocketProtocol::init_client(std::string const & interface_ interface_name.copy( ifr.ifr_name, IFNAMSIZ); if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 ) SENF_THROW_SYSTEM_EXCEPTION( "Could not create tap device: ") << ifr.ifr_name << "."; + ifaceIndex_ = if_nametoindex(ifr.ifr_name); fd(f); } prefix_ unsigned senf::TapSocketProtocol::available() const { - if (! fh().readable()) - return 0; - ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); - if (l < 0) - //SENF_THROW_SYSTEM_EXCEPTION(""); - return 1588; - return l; + if (!fh().readable()) + return 0; + ssize_t l = ::recv(fd(), 0, 0, MSG_PEEK | MSG_TRUNC); + if (l < 0) + //SENF_THROW_SYSTEM_EXCEPTION(""); + return 1588; + return l; } /* @@ -95,11 +96,25 @@ prefix_ bool senf::TapSocketProtocol::eof() return false; } +prefix_ unsigned int senf::TapSocketProtocol::ifaceIndex() + const +{ + return ifaceIndex_; +} + +prefix_ std::string senf::TapSocketProtocol::ifaceName() + const +{ + char buf[IF_NAMESIZE]; + if_indextoname(ifaceIndex_, buf); + return std::string(buf); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "TunTapSocketHandle.mpp" - + // Local Variables: // mode: c++ // fill-column: 100