From: g0dil Date: Mon, 6 Aug 2007 12:44:21 +0000 (+0000) Subject: Socket/Protocols/INet: Add CheckINet4Address akin to CheckINet6Address X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=08c52f7433157c8ac0a74c1cdf0f145453b77f04;p=senf.git Socket/Protocols/INet: Add CheckINet4Address akin to CheckINet6Address Socket/Protocols/INet: More complete CheckINet6Address documentation git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@378 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Mainpage.dox b/Socket/Mainpage.dox index 4802f4a..cf04807 100644 --- a/Socket/Mainpage.dox +++ b/Socket/Mainpage.dox @@ -16,13 +16,15 @@ namespace senf { functions (like reading and writing) and the inheritance hierarchy provides convenient access to the multitude of special and protocol dependent options. - \see \ref structure \n - \ref usage \n - \ref handle_group \n - \ref policy_group \n - \ref protocol_group \n - \ref extend \n - \ref implementation + \see + \ref structure \n + \ref usage \n + \ref handle_group \n + \ref policy_group \n + \ref protocol_group \n + \ref addr_group \n + \ref extend \n + \ref implementation */ /** \page structure Overview of the Socket Library Structure diff --git a/Socket/Protocols/INet/INet4Address.cti b/Socket/Protocols/INet/INet4Address.cti new file mode 100644 index 0000000..d731ce3 --- /dev/null +++ b/Socket/Protocols/INet/INet4Address.cti @@ -0,0 +1,56 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 +// 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. + +/** \file + \brief INet4Address inline template implementation */ + +//#include "INet4Address.ih" + +// Custom includes +#include + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////// +// senf::CheckINet4Network + +template +prefix_ bool senf::CheckINet4Network::match(INet4Address const & addr) +{ + return (addr.address() & ~boost::uint32_t(boost::low_bits_mask_t<32-prefix_len>::sig_bits)) == + (address & ~boost::uint32_t(boost::low_bits_mask_t<32-prefix_len>::sig_bits)); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/Socket/Protocols/INet/INet4Address.hh b/Socket/Protocols/INet/INet4Address.hh index f40b6dc..1ed57e8 100644 --- a/Socket/Protocols/INet/INet4Address.hh +++ b/Socket/Protocols/INet/INet4Address.hh @@ -44,6 +44,8 @@ namespace senf { INet4Address represents a simple IP address. It is modelled as a fixed-size container/sequence of 4 bytes. + \see CheckINet4Network + \implementation We awkwardly need to use static named constructors (from_ members) instead of ordinarily overloaded constructors for one simple reason: char * doubles as string literal and as arbitrary data iterator. The iterator constructor can @@ -158,14 +160,47 @@ namespace senf { inaddr_type iref() const; }; + /** \brief Output INet4Address instance as it's string representation + \related INet4Address + */ std::ostream & operator<<(std::ostream & os, INet4Address const & addr); + /** \brief CHeck INet4Address against a fixed network prefix + + This helper allows to easily and efficiently check an INet4Address against an arbitrary but + constant network prefix. The network prefix is represented by + + \par "" + senf::CheckINet4Network< addr , prefix-len > + + Where \a addr is the v4 Internet address as a 32-bit unsigned integer number in host byte + order and \a prefix_len is the length of the network prefix. The class exposes a single + static member match( addr ) which matches the INet4Address \a addr + against the prefix: + + \code + if (senf::CheckINet4Network<0x7F000000u,8u>::match(addr)) { + // 'addr' is within the 127.0.0.0/8 loopback network + ... + } + \endcode + + \implementation This is implemented the way it is so the syntax is identical to the + CheckINet6Network syntax. + */ + template + class CheckINet4Network + { + public: + static bool match(INet4Address const & addr); + }; + } ///////////////////////////////hh.e//////////////////////////////////////// #include "INet4Address.cci" #include "INet4Address.ct" -//#include "INet4Address.cti" +#include "INet4Address.cti" #endif diff --git a/Socket/Protocols/INet/INet6Address.hh b/Socket/Protocols/INet/INet6Address.hh index 808e6b6..4ef43e7 100644 --- a/Socket/Protocols/INet/INet6Address.hh +++ b/Socket/Protocols/INet/INet6Address.hh @@ -269,10 +269,24 @@ namespace senf { */ std::ostream & operator<<(std::ostream & os, INet6Address const & addr); - /** \brief Check address against a fixed network prefix + /** \brief Check INet6Address against a fixed network prefix + + This helper allows to easily and efficiently check an INet6Address against an arbitrary but + constant network prefix. It takes from 1 to 8 arguments for the network address and an + additional last argument providing the prefix length. So + + \par "" + senf::CheckINet6Network< addr_1 , addr_2 , + ... , prefix_len > + + represents the network + + \par "" + addr_1 : addr_2 : ... ::/ prefix_len . + + The class exposes a single static member match( addr ) which + matches the INet6Address \a addr against the prefix: - This helper allows to easily and efficiently check an address against an arbitrary network - prefix: \code if (senf::CheckINet6Network<0x2000u,0xDB8u,32u>::match(addr)) { // 'addr' is within in the 2001:db8::/32 documentation-only network @@ -280,10 +294,7 @@ namespace senf { } \endcode - The code generated by this call is highly optimized and as probably as efficient as it can - get. - - \related INet6Address + The code generated by this call is highly optimized and probably as efficient as it can get. */ template