Skip to content
Snippets Groups Projects
Commit 94c321f1 authored by g0dil's avatar g0dil
Browse files

Socket/Protocols/INet: Add CheckINet4Address akin to CheckINet6Address

Socket/Protocols/INet: More complete CheckINet6Address documentation
parent 9c1f3049
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
// $Id$
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <g0dil@berlios.de>
//
// 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 <boost/integer/integer_mask.hpp>
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::CheckINet4Network<address,prefix_len>
template <boost::uint32_t address, unsigned prefix_len>
prefix_ bool senf::CheckINet4Network<address,prefix_len>::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:
......@@ -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 (<tt>from_</tt> members)
instead of ordinarily overloaded constructors for one simple reason: <tt>char *</tt>
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 ""
<tt>senf::CheckINet4Network<</tt> <i>addr</i> <tt>,</tt> <i>prefix-len</i> <tt>></tt>
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 <tt>match(</tt> <i>addr</i> <tt>)</tt> 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 <boost::uint32_t address, unsigned prefix_len>
class CheckINet4Network
{
public:
static bool match(INet4Address const & addr);
};
}
///////////////////////////////hh.e////////////////////////////////////////
#include "INet4Address.cci"
#include "INet4Address.ct"
//#include "INet4Address.cti"
#include "INet4Address.cti"
#endif
......
......@@ -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 ""
<tt>senf::CheckINet6Network<</tt> <i>addr_1</i> <tt>,</tt> <i>addr_2</i> <tt>,</tt>
... <tt>,</tt> <i>prefix_len</i> <tt>></tt>
represents the network
\par ""
<i>addr_1</i> <tt>:</tt> <i>addr_2</i> <tt>:</tt> ... <tt>::/</tt> <i>prefix_len</i> .
The class exposes a single static member <tt>match(</tt> <i>addr</i> <tt>)</tt> 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 <unsigned a0, unsigned a1, unsigned a2=0u, unsigned a3=0u, unsigned a4=0u,
unsigned a5=0u, unsigned a6=0u, unsigned a7=0u, unsigned a8=0u>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment