X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FTunTapSocketHandle.cc;h=80d72bcc2522efa92b35de848bd65905b136bbd4;hb=1ad3873b372da6187b1fbc645bf276287d2efb54;hp=c2ab043385ea5e13a22bf2073bbc7dacd7a7a78e;hpb=05aff4588889ff615efebd1dd0d3fff494399f80;p=senf.git diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.cc b/Socket/Protocols/Raw/TunTapSocketHandle.cc index c2ab043..80d72bc 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.cc @@ -1,4 +1,4 @@ -// $Id: PacketSocketHandle.cc 358 2007-07-27 12:14:51Z g0dil $ +// $Id$ // // Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) @@ -48,8 +48,8 @@ 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 ) + int f; + if ( (f = ::open("/dev/net/tun", O_RDWR)) < 0 ) throwErrno(); struct ifreq ifr; ::memset( &ifr, 0, sizeof(ifr)); @@ -57,9 +57,9 @@ prefix_ void senf::TapProtocol::init_client(std::string const & interface_name, if (NO_PI) ifr.ifr_flags |= IFF_NO_PI; interface_name.copy( ifr.ifr_name, IFNAMSIZ); - if (::ioctl(fd, TUNSETIFF, (void *) &ifr) < 0 ) + if (::ioctl(f, TUNSETIFF, (void *) &ifr) < 0 ) throwErrno(); - body().fd(fd); + fd(f); } prefix_ std::auto_ptr senf::TapProtocol::clone() @@ -69,15 +69,31 @@ prefix_ std::auto_ptr senf::TapProtocol::clone() } 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) - throwErrno(); - return l; + 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 +{ + if (! body().readable()) + return 0; + int n; + if (::ioctl(body().fd(),SIOCINQ,&n) < 0) + throwErrno(); + return n; } +*/ prefix_ bool senf::TapProtocol::eof() const