From: dw6 Date: Tue, 11 Dec 2007 11:10:57 +0000 (+0000) Subject: add support of connected RawV4/6 sockets X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=c60b9e4e61d31352a52fd82dcbc2dab3ccc3a5e3;p=senf.git add support of connected RawV4/6 sockets git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@552 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc b/Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc new file mode 100644 index 0000000..3963ccd --- /dev/null +++ b/Socket/Protocols/INet/ConnectedRawInetSocketHandle.cc @@ -0,0 +1,100 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum NETwork research (NET) +// David Wagner +// +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "ConnectedRawInetSocketHandle.hh" + +// Custom includes +#include +#include +#include + +#include "../../../Utils/Exception.hh" + +//#include "UDPSocketHandle.mpp" +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::ConnectedRawV4SocketProtocol + +prefix_ void senf::ConnectedRawV4SocketProtocol::init_client() + const +{ + init_client(IPPROTO_RAW); +} + +prefix_ void +senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol) + const +{ + int sock = ::socket(PF_INET, SOCK_RAW, protocol); + if (sock < 0) + throwErrno(); + body().fd(sock); +} + +prefix_ void +senf::ConnectedRawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress const & address) + const +{ + init_client(protocol); + connect(address); +} + +prefix_ std::auto_ptr senf::ConnectedRawV4SocketProtocol::clone() + const +{ + return std::auto_ptr(new ConnectedRawV4SocketProtocol()); +} + +/////////////////////////////////////////////////////////////////////////// +// senf::UDPv6SocketProtocol:: + +prefix_ void senf::ConnectedRawV6SocketProtocol::init_client() + const +{ + init_client(IPPROTO_RAW); +} + +prefix_ void senf::ConnectedRawV6SocketProtocol::init_client(int const & protocol) + const +{ + int sock = ::socket(PF_INET6,SOCK_RAW,protocol); + if (sock < 0) + throwErrno(); + body().fd(sock); +} + +prefix_ void +senf::ConnectedRawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress const & address) + const +{ + init_client(protocol); + connect(address); +} + +prefix_ std::auto_ptr senf::ConnectedRawV6SocketProtocol::clone() + const +{ + return std::auto_ptr(new ConnectedRawV6SocketProtocol()); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ diff --git a/Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh b/Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh new file mode 100644 index 0000000..e0279c9 --- /dev/null +++ b/Socket/Protocols/INet/ConnectedRawInetSocketHandle.hh @@ -0,0 +1,198 @@ +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum NETwork research (NET) +// David Wagner +// +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef CONNECTEDRAWINETSOCKETHANDLE_HH_ +#define CONNECTEDRAWINETSOCKETHANDLE_HH_ + +// Custom includes +#include "INetProtocol.hh" +#include "RawInetProtocol.hh" +#include "../../../Socket/Protocols/BSDSocketProtocol.hh" +#include "../../../Socket/FramingPolicy.hh" +#include "../../../Socket/CommunicationPolicy.hh" +#include "../../../Socket/ReadWritePolicy.hh" +#include "../../../Socket/BufferingPolicy.hh" +#include "../../../Socket/ProtocolClientSocketHandle.hh" + + +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + /// \addtogroup concrete_protocol_group + /// @{ + + typedef MakeSocketPolicy< + INet4AddressingPolicy, + DatagramFramingPolicy, + ConnectedCommunicationPolicy, + ReadablePolicy, + WriteablePolicy, + SocketBufferingPolicy + >::policy ConnectedRawV4Socket_Policy; ///< Socket Policy of the Connected RawV4 Protocol + + /** \brief IPv4 RAW Socket Protocol, connected + + \par Socket Handle typedefs: + \ref ConnectedRawV4ClientSocketHandle (ProtocolClientSocketHandle) + + \par Policy Interface: + ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), + ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + + \par Address Type: + INet4Address + + ConnectedRawV4SocketProtocol provides an internet protocol raw socket based on IPv4 addressing. + This socket will put data written to it onto the IPv4 layer: if you call writeto don't inlude the header! + On the other hand `read` will return the packet data including the IP header. + This behaviour is strange and differs from the behaviour of IPv6 RAW sockets and should be changed in the future. + + This class is utilized as the protocol class of the ProtocolClientSocketHandle + via the Socket Handle typedefs above. + + \see ConnectedRawV6SocketProtocol + \see RawV4SocketProtocol + \see RawV6SocketProtocol + */ + class ConnectedRawV4SocketProtocol + : public ConcreteSocketProtocol, + public IPv4Protocol, + public RawInetProtocol, + public BSDSocketProtocol, + public AddressableBSDSocketProtocol//, +// public senf::pool_alloc_mixin + { + public: + /////////////////////////////////////////////////////////////////////////// + // internal interface + + ///\name Constructors + ///@{ + + void init_client() const; ///< Create unconnected client socket for IPPROTO_RAW + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + void init_client(int const & protocol) const; ///< Create unconnected client socket for protocol + + void init_client(int const & protocol, INet4SocketAddress const & address) const; + ///< Create client socket and connect + /**< Creates a new client socket for the given protocol and connects to the given + address. + \param[in] protocol Layer 4 protocol to filter for / to send + \param[in] address local address to connect to */ + + ///@} + ///\name Abstract Interface Implementation + + std::auto_ptr clone() const; + + ///@} + }; + + typedef ProtocolClientSocketHandle ConnectedRawV4ClientSocketHandle; + + + + +//////////////////////////////////////////////////////////////////// Raw IPv6 Socket ////////////////////////////////////// + typedef MakeSocketPolicy< + INet6AddressingPolicy, + DatagramFramingPolicy, + ConnectedCommunicationPolicy, + ReadablePolicy, + WriteablePolicy, + SocketBufferingPolicy + >::policy ConnectedRawV6Socket_Policy; ///< Socket Policy of the RawV6 Protocol + + /** \brief IPv6 RAW Socket Protocol, connected + + \par Socket Handle typedefs: + \ref ConnectedRawV6ClientSocketHandle (ProtocolClientSocketHandle) + + \par Policy Interface: + ClientSocketHandle::read(), ClientSocketHandle::write(), ClientSocketHandle::bind(), + ClientSocketHandle::local(), ClientSocketHandle::connect(), ClientSocketHandle::peer(), + ClientSocketHandle::rcvbuf(), ClientSocketHandle::sndbuf() + + \par Address Type: + INet6Address + + ConnectedRawV6SocketProtocol provides an internet protocol raw socket based on IPv6 addressing which is connected to certain peer. + This socket will put data written to it onto the IPv6 layer: if you call writeto don't inlude the header! + On the other hand `read` will return the packet data on top of the IPv6 layer, excluding the IP header. + Note: This behaviour is differs from the behaviour of IPv4 RAW sockets. + + This class is utilized as the protocol class of the ProtocolClientSocketHandle + via the Socket Handle typedefs above. + + \see ConnectedRawV4SocketProtocol + \see RawV4SocketProtocol + \see RawV6SocketProtocol + */ + class ConnectedRawV6SocketProtocol + : public ConcreteSocketProtocol, + public IPv6Protocol, + public RawInetProtocol, + public BSDSocketProtocol, + public AddressableBSDSocketProtocol//, +// public senf::pool_alloc_mixin + { + public: + /////////////////////////////////////////////////////////////////////////// + // internal interface + + ///\name Constructors + ///@{ + + void init_client() const; ///< Create unconnected client socket for IPPROTO_RAW + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor */ + + void init_client(int const & protocol) const; ///< Create unconnected client socket for protocol + + void init_client(int const & protocol, INet6SocketAddress const & address) const; + ///< Create client socket and connect + /**< Creates a new client socket for the given protocol and connects to the given + address. + \param[in] protocol Layer 4 protocol to filter for / to send + \param[in] address local address to connect to */ + /**< \note This member is implicitly called from the + ProtocolClientSocketHandle::ProtocolClientSocketHandle() + constructor (??) */ + + ///@} + ///\name Abstract Interface Implementation + + std::auto_ptr clone() const; + + ///@} + }; + + typedef ProtocolClientSocketHandle ConnectedRawV6ClientSocketHandle; + + /// @} + +} + +#endif /*CONNECTEDRAWINETSOCKETHANDLE_HH_*/