X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FTunTapSocketHandle.cc;h=704944769f1db77770a86fa36d509d9678bc3d3d;hb=6f50bf49e282c0528f51faa0a245bbfa2b867399;hp=cd46920309434146de72f0bd321ad8399d6eb77e;hpb=90ba247d06107cff657ad3e6310f8dde7c808c95;p=senf.git diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index cd46920..7049447 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -1,9 +1,9 @@ -// $Id: PacketSocketHandle.cc 358 2007-07-27 12:14:51Z g0dil $ +// $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // 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 @@ -48,36 +48,46 @@ prefix_ void senf::TapProtocol::init_client() prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, bool const NO_PI) const { - int fd; - if ( (fd = ::open("/dev/net/tun", O_RDWR)) < 0 ) - throw SystemException(errno); + int f; + if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 ) + throwErrno(); struct ifreq ifr; ::memset( &ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP; if (NO_PI) ifr.ifr_flags |= IFF_NO_PI; interface_name.copy( ifr.ifr_name, IFNAMSIZ); - if (::ioctl(fd, TUNSETIFF, (void *) &ifr) < 0 ) - throw SystemException(errno); - body().fd(fd); + if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 ) + throwErrno(); + fd(f); } -prefix_ std::auto_ptr senf::TapProtocol::clone() - const +prefix_ unsigned senf::TapProtocol::available() + const { - return std::auto_ptr(new TapProtocol()); + if (! fh().readable()) + return 0; + ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); + if (l < 0) + //throwErrno(); + return 1588; + return l; } +/* +#include // for SIOCINQ / SIOCOUTQ + prefix_ unsigned senf::TapProtocol::available() - const + const { - if (! body().readable()) - return 0; - ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC); - if (l < 0) - throw SystemException(errno); - return l; + if (! body().readable()) + return 0; + int n; + if (::ioctl(body().fd(),SIOCINQ,&n) < 0) + throwErrno(); + return n; } +*/ prefix_ bool senf::TapProtocol::eof() const