*/
#include "LLAddressing.hh"
-#include "LLAddressing.ih"
+//#include "LLAddressing.ih"
// Custom includes
#include <net/if.h>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-prefix_ unsigned char senf::detail::hexnibble(char c)
-{
- if (c>='0' && c<='9')
- return c - '0';
- if (c>='A' && c<='F')
- return c - 'A' + 10;
- if (c>='a' && c<='f')
- return c - 'a' + 10;
- throw InvalidLLSocketAddressException();
-}
-
prefix_ std::string senf::LLSocketAddress::interface()
const
{
return std::string(name);
}
-/*
-{
- if (addr_.sll_halen == 0)
- return std::string();
- std::stringstream s;
-
- unsigned char const * i = &addr_.sll_addr[0];
- while (1) {
- s << std::hex << std::setw(2) << std::setfill('0') << unsigned(*i);
- ++i;
- if (i == &addr_.sll_addr[addr_.sll_halen]) break;
- s << '-';
- }
- return s.str();
-}
-*/
-
-
-/*
-prefix_ void senf::LLSocketAddress::address(std::string address)
-{
- typedef boost::split_iterator<std::string::iterator> StringSplitIterator;
- StringSplitIterator i = boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
- unsigned char * j = &addr_.sll_addr[0];
- for (; ! i.eof() && addr_.sll_halen<8; ++i, ++j, ++addr_.sll_halen) {
- if ( i->size() != 2 || ! boost::all(*i, boost::is_xdigit()) )
- throw InvalidLLSocketAddressException();
- *j = hex(*i);
- }
- if (! i.eof())
- throw InvalidLLSocketAddressException();
-}
-*/
-
-prefix_ void senf::LLSocketAddress::interface(std::string interface)
+prefix_ void senf::LLSocketAddress::interface(std::string iface)
{
- if (! interface.empty()) {
- addr_.sll_ifindex = if_nametoindex(interface.c_str());
+ if (iface.empty())
+ addr_.sll_ifindex = 0;
+ else {
+ addr_.sll_ifindex = if_nametoindex(iface.c_str());
if (addr_.sll_ifindex == 0)
throw InvalidLLSocketAddressException();
}
}
-
-prefix_ senf::detail::LLAddressFromStringRange
-senf::llAddress(std::string address)
-{
- detail::StringSplitIterator i =
- boost::make_split_iterator(address, boost::token_finder(boost::is_any_of("-: ")));
- detail::StringSplitIterator i_end;
-
- detail::HexSplitIterator j (i,detail::HexConverter());
- detail::HexSplitIterator j_end (i_end);
-
- return detail::LLAddressFromStringRange(j,j_end);
-}
-
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "LLAddressing.mpp"
clear();
}
-prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned protocol, std::string interface)
+prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned prot, std::string const & iface)
{
clear();
- this->protocol(protocol);
- this->interface(interface);
+ protocol(prot);
+ interface(iface);
}
-prefix_ senf::LLSocketAddress::LLSocketAddress(std::string interface)
+prefix_ senf::LLSocketAddress::LLSocketAddress(std::string const &iface)
{
clear();
- this->interface(interface);
+ interface(iface);
+}
+
+prefix_ senf::LLSocketAddress::LLSocketAddress(MACAddress const & addr,
+ std::string const & iface)
+{
+ clear();
+ address(addr);
+ interface(iface);
}
prefix_ void senf::LLSocketAddress::clear()
prefix_ unsigned senf::LLSocketAddress::arptype()
const
{
- /** \todo make sure, that the value really is in network byte
- order */
return ntohs(addr_.sll_hatype);
}
-prefix_ unsigned senf::LLSocketAddress::pkttype()
+prefix_ senf::LLSocketAddress::PktType senf::LLSocketAddress::pkttype()
const
{
- /** \todo make sure, that the value really is in network byte
- order */
- return ntohs(addr_.sll_pkttype);
+ return PktType(ntohs(addr_.sll_pkttype));
}
-prefix_ senf::LLSocketAddress::LLAddress senf::LLSocketAddress::address()
+prefix_ senf::MACAddress senf::LLSocketAddress::address()
const
{
- return LLAddress(&addr_.sll_addr[0], &addr_.sll_addr[addr_.sll_halen]);
+ return MACAddress::from_data(&addr_.sll_addr[0]);
+}
+
+prefix_ void senf::LLSocketAddress::address(MACAddress const & addr)
+{
+ std::copy(addr.begin(), addr.end(),&addr_.sll_addr[0]);
}
-prefix_ void senf::LLSocketAddress::protocol(unsigned protocol)
+prefix_ void senf::LLSocketAddress::protocol(unsigned prot)
{
- addr_.sll_protocol = htons(protocol);
+ addr_.sll_protocol = htons(prot);
}
prefix_ struct sockaddr * senf::LLSocketAddress::sockaddr_p()
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 LLSocketAddress and LLAddressingPolicy non-inline template implementation
- */
-
-#include "LLAddressing.ih"
-
-// Custom includes
-#include <sstream>
-#include <iomanip>
-#include <string.h>
-
-#define prefix_
-///////////////////////////////ct.p////////////////////////////////////////
-
-template <class ForwardRange>
-prefix_ void senf::LLSocketAddress::address(ForwardRange const & address)
-{
- if (boost::size(address) > sizeof(addr_.sll_addr))
- throw InvalidLLSocketAddressException();
- typename boost::range_const_iterator<ForwardRange>::type i (boost::begin(address));
- ::memset(&addr_.sll_addr[0],sizeof(addr_.sll_addr),0);
- addr_.sll_halen = 0;
- for (; i != boost::end(address) && addr_.sll_halen<8; ++i, ++addr_.sll_halen)
- addr_.sll_addr[addr_.sll_halen] = *i;
- if (i != boost::end(address))
- throw InvalidLLSocketAddressException();
-}
-
-template <class ForwardRange>
-prefix_ std::string
-senf::llAddress(ForwardRange const & address,
- typename boost::enable_if< boost::is_class<ForwardRange> >::type *)
-{
- if (boost::empty(address))
- return std::string();
- std::stringstream s;
- typename boost::range_const_iterator< ForwardRange >::type i (boost::begin(address));
- while (1) {
- s << std::hex << std::setw(2) << std::setfill('0') << unsigned(*i);
- ++ i;
- if (i == boost::end(address))
- break;
- s << '-';
- }
- return s.str();
-}
-
-template <class ForwardRange>
-prefix_ unsigned char senf::detail::HexConverter::operator()(ForwardRange const & v)
- const
-{
- if (boost::size(v) != 2)
- throw InvalidLLSocketAddressException();
- typename boost::range_iterator< ForwardRange >::type i (boost::begin(v));
- unsigned char n1 = hexnibble(*i) << 4;
- return n1 + hexnibble(*(++i));
-}
-
-///////////////////////////////ct.e////////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 LLSocketAddress and LLAddressingPolicy inline template implementation
- */
-
-#include "LLAddressing.ih"
-
-// Custom includes
-#include <algorithm> // for std::copy
-
-#define prefix_ inline
-///////////////////////////////cti.p///////////////////////////////////////
-
-#ifndef DOXYGEN
-template <class ForwardRange>
-prefix_ senf::LLSocketAddress::
-LLSocketAddress(ForwardRange const & address, std::string interface,
- typename boost::enable_if_c<! boost::is_integral<ForwardRange>::value >::type *)
-{
- clear();
- this->address(address);
- this->interface(interface);
-}
-#else
-template <class ForwardRange>
-prefix_ senf::LLSocketAddress::
-LLSocketAddress(ForwardRange const & address, std::string interface)
-{}
-#endif
-
-///////////////////////////////cti.e///////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
#define HH_LLAddressing_ 1
// Custom includes
-#include <boost/range/iterator_range.hpp>
-#include <boost/utility/enable_if.hpp>
-#include <boost/type_traits.hpp>
-
#include <sys/socket.h>
#include <netpacket/packet.h>
-
#include "Socket/SocketPolicy.hh"
#include "Socket/FileHandle.hh"
#include "Socket/Protocols/GenericAddressingPolicy.hh"
+#include "MACAddress.hh"
//#include "LLAddressing.mpp"
-#include "LLAddressing.ih"
+//#include "LLAddressing.ih"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
/** \brief Link local address
- LLSocketAddress wraps the standard sockaddr_ll datatype.
-
- \todo I don't think the current implementation is
- sensible. I'll have to reimplement this class probably
- from scratch.
-
- \implementation The class relies uses a very flexible
- 'ForwardRange' representation for a raw ll
- address (See <a
- href="http://www.boost.org/libs/range/index.html">Boost.Range</a>).
- This representation allows zero-copy implementations of
- many operations, however it is probably not worth the
- effort since the ll address is restricted to a max of 8
- bytes. Therefore this will be changed and the concrete
- implementation is not documented very well ...
+ LLSocketAddress wraps the standard sockaddr_ll data type. An LLSocketAddress provides quite
+ some information, only part of which is necessary for sending packets. The LLSocketAddress
+ class only allows changing those fields which need to be changed. The other fields are
+ read-only. They are filled by the operating system when receiving a packet
+
*/
class LLSocketAddress
{
public:
- // Right now we use an arbitrary ForwardRange (see Boost.Range)
- // as the representation for a hardware address. The restrictions
- // for the range are:
- // a) the range must never be larger than 8 elements
- // b) the value_type must be convertible to unsigned char
- // and really we need only a single-pass range.
- //
- // Since a hardware address is so short (a maximum of 8
- // bytes), in the aftermath I think a simple container holding
- // a maximum of 8 unsigned chars (e.g. Boost.Array with
- // additional length parameter) will be much simpler and
- // probably even more efficient. This should have a conversion
- // constructor from an arbitrary ForwardRange to make it
- // compatible e.g. with the Packet library.
- //
- // However, since I have implemented it already as it is now,
- // I'll leave it as it is ...
-
- typedef boost::iterator_range<unsigned char const *> LLAddress;
-
- LLSocketAddress();
- // And this is for bind
- explicit LLSocketAddress(unsigned protocol, std::string interface="");
- explicit LLSocketAddress(std::string interface);
- // This is for sending packets ..
- // We must use enable_if here, so this constructor will not hide
- // above constructor if passed a plain int or short argument
-# ifndef DOXYGEN
- template <class ForwardRange>
- explicit LLSocketAddress(ForwardRange const & address, std::string interface="",
- typename boost::enable_if_c<! boost::is_integral<ForwardRange>::value >::type * = 0);
-# else
- template <class ForwardRange>
- explicit LLSocketAddress(ForwardRange const & address, std::string interface="");
-# endif
-
- void clear();
-
- unsigned protocol() const;
- std::string interface() const;
- unsigned arptype() const;
- unsigned pkttype() const;
- LLAddress address() const;
+ /** \brief Valid pkttype() values
+
+ These are the possible values returned by arptype()
+ */
+ enum PktType { Undefined = 0
+ , Host = PACKET_HOST /**< Packet destined for this host */
+ , Broadcast = PACKET_BROADCAST /**< Packet sent to the broadcast address */
+ , Multicast = PACKET_MULTICAST /**< Packet sent to a (link local) multicast
+ address */
+ , OtherHost = PACKET_OTHERHOST /**< Packet sent to another host (promisc) */
+ , Outgoing = PACKET_OUTGOING /**< Packet sent out from this host */
+ };
+
+ LLSocketAddress(); ///< Create empty address
+ explicit LLSocketAddress(unsigned proto, std::string const & iface="");
+ ///< Create address for \c bind()
+ /**< This constructs an LLSocketAddress valid for calling
+ PacketSocketHandle::bind() with.
+ \param[in] prot Protocol (Ethertype) to listen for
+ \param[in] iface Interface name to bind to */
+ explicit LLSocketAddress(std::string const &iface);
+ ///< Create address for \c bind()
+ /**< This constructs an LLSocketAddress valid for calling
+ \c PacketSocketHandle::bind() with.
+ \param[in] iface Interface name to bind to */
+
+ // This constructor is for sending packets
+ explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
+ ///< Create address valid to send raw packets
+ /**< Addresses created with this constructor are valid for
+ use with \c PacketSocketHandle::sendto() on a \c
+ SOCK_DGRAM packet socket.
+ \param addr Address to send data to
+ \param iface Interface to send packet from */
+
+ void clear(); ///< Clear the address
+
+ unsigned protocol() const; ///< Return address protocol (ethertype)
+ std::string interface() const; ///< Return interface name
+ unsigned arptype() const; ///< Return the hatype field (ARP hardware type)
+ PktType pkttype() const; ///< Return type of packet
+ MACAddress address() const; ///< Return address
// The mutating interface is purposely restricted to allow only
// changing those members, which are sensible to be changed.
- template <class ForwardRange>
- void address(ForwardRange const & address);
- void interface(std::string interface);
- void protocol(unsigned protocol);
+ void address(MACAddress const & addr); ///< Change address
+ void interface(std::string iface); ///< Change interface
+ void protocol(unsigned prot); ///< Change protocol
+
+ ///\name Generic SocketAddress interface
+ ///@{
struct sockaddr * sockaddr_p();
struct sockaddr const * sockaddr_p() const;
unsigned sockaddr_len() const;
+ ///@}
+
private:
struct ::sockaddr_ll addr_;
};
- /** \brief
- \related LLSocketAddress
- */
- detail::LLAddressFromStringRange llAddress(std::string address);
-
- // The enable_if condition here allows only for classes as range.
- // However, excluding zero-terminated strings (which we want to
- // pass to above) I cannot think of a non-class ForwardRange
- // except for academic cases
- // STOP: ... how about std::vector<...>::iterator ?? isn't that a ..pointer ?
- /** \brief Convert raw link-local address into printable form
- \related LLSocketAddress
- */
- template <class ForwardRange>
- std::string llAddress(ForwardRange const & address,
- typename boost::enable_if< boost::is_class<ForwardRange> >::type * = 0);
-
/** \brief Signal invalid link local address syntax
\related LLSocketAddress
*/
///////////////////////////////hh.e////////////////////////////////////////
#include "LLAddressing.cci"
-#include "LLAddressing.ct"
-#include "LLAddressing.cti"
+//#include "LLAddressing.ct"
+//#include "LLAddressing.cti"
//#include "LLAddressing.mpp"
#endif
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 LLSocketAddress and LLAddressingPolicy internal header
- */
-#ifndef IH_LLAddressing_
-#define IH_LLAddressing_ 1
-
-// Custom includes
-#include <boost/algorithm/string/split.hpp>
-
-///////////////////////////////ih.p////////////////////////////////////////
-
-namespace senf {
-
-namespace detail {
-
- /** \brief Convert two-char hexbyte representation to numeric value
- \internal
- */
- struct HexConverter {
- typedef unsigned char result_type;
- template <class ForwardRange>
- result_type operator()(ForwardRange const & v) const;
- };
-
- typedef boost::split_iterator<std::string::iterator> StringSplitIterator;
- typedef boost::transform_iterator< HexConverter, StringSplitIterator > HexSplitIterator;
- typedef boost::iterator_range<HexSplitIterator> LLAddressFromStringRange;
-
- /** \brief convert single hex digit to numeric value
- \internal
- */
- unsigned char hexnibble(char c);
-
-}}
-
-///////////////////////////////ih.e////////////////////////////////////////
-#endif
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
//#include "LLAddressing.test.ih"
// Custom includes
+#include <boost/lexical_cast.hpp>
#include "LLAddressing.hh"
#include <boost/test/auto_unit_test.hpp>
BOOST_CHECK_EQUAL( a.protocol(), 0u );
BOOST_CHECK_EQUAL( a.interface(), "" );
BOOST_CHECK_EQUAL( a.arptype(), 0u );
- BOOST_CHECK_EQUAL( a.pkttype(), 0u );
- BOOST_CHECK_EQUAL( a.address(), "" );
+ BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
+ BOOST_CHECK( ! a.address() );
- a.address(senf::llAddress("05-10-1A-2f-25-30"));
- BOOST_CHECK_EQUAL( senf::llAddress(a.address()), "05-10-1a-2f-25-30" );
+ a.address(senf::MACAddress::from_string("05-10-1A-2f-25-30"));
+ BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(a.address()), "05:10:1a:2f:25:30" );
a.interface("lo");
BOOST_CHECK_EQUAL( a.interface(), "lo" );
a.protocol(123);
{
senf::LLSocketAddress a (
- senf::llAddress("11-12-13-14-15-16"), "lo");
+ senf::MACAddress::from_string("11-12-13-14-15-16"), "lo");
BOOST_CHECK_EQUAL( a.protocol(), 0u );
BOOST_CHECK_EQUAL( a.interface(), "lo" );
BOOST_CHECK_EQUAL( a.arptype(), 0u );
- BOOST_CHECK_EQUAL( a.pkttype(), 0u );
- BOOST_CHECK_EQUAL( senf::llAddress(a.address()), "11-12-13-14-15-16" );
+ BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
+ BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(a.address()), "11:12:13:14:15:16" );
}
{
BOOST_CHECK_EQUAL( a.interface(), "lo" );
BOOST_CHECK_EQUAL( a.arptype(), 0u );
BOOST_CHECK_EQUAL( a.pkttype(), 0u );
- BOOST_CHECK_EQUAL( senf::llAddress(a.address()), "" );
+ BOOST_CHECK( ! a.address() );
}
}
/** \brief Ethernet MAC address
The Ethernet MAC is modelled as a fixed-size container/sequence of 6 bytes.
+
+ \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
+ therefore not be distinguished from initialization with a string literal. Therefore we
+ need to disambiguate using the named constructors.
*/
struct MACAddress
: public boost::array<boost::uint8_t,6>,
*/
#include "PacketSocketHandle.hh"
-#include "PacketSocketHandle.ih"
+//#include "PacketSocketHandle.ih"
// Custom includes
#include <sys/types.h>
return false;
}
-prefix_ void senf::PacketProtocol::do_mc_i(std::string interface,
- detail::LLAddressCopier const & copier, bool add)
+namespace {
+
+ void do_mc(int fd, std::string interface, senf::MACAddress address, bool add)
+ {
+ struct packet_mreq mreq;
+ mreq.mr_ifindex = ::if_nametoindex(interface.c_str());
+ if (mreq.mr_ifindex == 0)
+ throw senf::SystemException(EINVAL);
+ mreq.mr_type = PACKET_MR_MULTICAST;
+ mreq.mr_alen = 6;
+ std::copy(address.begin(), address.end(), &mreq.mr_address[0]);
+ if (::setsockopt(fd, SOL_PACKET,
+ add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
+ &mreq, sizeof(mreq)) < 0)
+ throw senf::SystemException(errno);
+ }
+
+}
+
+prefix_ void senf::PacketProtocol::mcAdd(std::string const & interface,
+ MACAddress const & address)
const
{
- struct packet_mreq mreq;
- mreq.mr_ifindex = ::if_nametoindex(interface.c_str());
- if (mreq.mr_ifindex == 0)
- throw SystemException(EINVAL);
- mreq.mr_type = PACKET_MR_MULTICAST;
- mreq.mr_alen = copier(&mreq.mr_address[0]);
- if (::setsockopt(body().fd(),SOL_PACKET,
- add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP,
- &mreq, sizeof(mreq)) < 0)
- throw SystemException(errno);
+ do_mc(body().fd(),interface,address,true);
+}
+
+prefix_ void senf::PacketProtocol::mcDrop(std::string const & interface,
+ MACAddress const & address)
+ const
+{
+ do_mc(body().fd(),interface,address,false);
}
///////////////////////////////cc.e////////////////////////////////////////
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 PacketProtocol and PacketSocketHandle non-inline template implementation
- */
-
-#include "PacketSocketHandle.ih"
-
-// Custom includes
-
-#define prefix_
-///////////////////////////////ct.p////////////////////////////////////////
-
-template <class ForwardRange>
-prefix_ unsigned
-senf::detail::Range_LLAddressCopier<ForwardRange>::operator()(unsigned char * target)
- const
-{
- std::size_t len (0);
- typename boost::range_const_iterator<ForwardRange>::type i (boost::begin(range_));
- for (; i != boost::end(range_) && len<8; ++i, ++len, ++target)
- *target = *i;
- if (i != boost::end(range_))
- throw InvalidLLSocketAddressException();
- return len;
-}
-
-///////////////////////////////ct.e////////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 PacketProtocol and PacketSocketHandle inline template implementation
- */
-
-#include "PacketSocketHandle.ih"
-
-// Custom includes
-
-#define prefix_ inline
-///////////////////////////////cti.p///////////////////////////////////////
-
-template <class ForwardRange>
-prefix_ void senf::PacketProtocol::mcAdd(std::string interface,
- ForwardRange const & address)
- const
-{
- do_mc(interface,address,true);
-}
-
-template <class ForwardRange>
-prefix_ void senf::PacketProtocol::mcDrop(std::string interface,
- ForwardRange const & address)
- const
-{
- do_mc(interface,address,false);
-}
-
-template <class ForwardRange>
-prefix_ senf::detail::Range_LLAddressCopier<ForwardRange>::
-Range_LLAddressCopier(ForwardRange const & range)
- : range_ (range)
-{}
-
-template <class ForwardRange>
-prefix_ void senf::PacketProtocol::do_mc(std::string interface,
- ForwardRange const & address, bool add)
- const
-{
- detail::Range_LLAddressCopier<ForwardRange> copier (address);
- do_mc_i(interface, copier, add);
-}
-
-///////////////////////////////cti.e///////////////////////////////////////
-#undef prefix_
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
#include "LLAddressing.hh"
//#include "PacketSocketHandle.mpp"
-#include "PacketSocketHandle.ih"
+//#include "PacketSocketHandle.ih"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
///\name Protocol Interface
///@{
- // See LLSocketAddress for a discussion/rationale for ForwardRange here
- template <class ForwardRange>
- void mcAdd(std::string interface, ForwardRange const & address) const;
+ void mcAdd(std::string const & interface, MACAddress const & address) const;
///< Enable reception of a multicast group
- /**< mcAdd will join a new multicast group. The address
- parameter is specified as an arbitrary forward range
- (see <a
- href="http://www.boost.org/libs/range/index.html">Boost.Range</a>)
- of up to 8 bytes. This allows to initialize the
- address from an arbitrary sources without excessive
- copying.
+ /**< mcAdd will join a new multicast group.
\param[in] interface interface with which to join
\param[in] address multicast address to join
\see \ref LLSocketAddress */
- template <class ForwardRange>
- void mcDrop(std::string interface, ForwardRange const & address) const;
+ void mcDrop(std::string const & interface, MACAddress const & address) const;
///< Disable reception of a multicast group
/**< \see \ref mcAdd() */
///@}
bool eof() const;
///@}
-
- private:
- template<class ForwardRange>
- void do_mc(std::string interface, ForwardRange const & address, bool add) const;
- void do_mc_i(std::string interface, detail::LLAddressCopier const & copier, bool add) const;
};
typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
///////////////////////////////hh.e////////////////////////////////////////
//#include "PacketSocketHandle.cci"
-#include "PacketSocketHandle.ct"
-#include "PacketSocketHandle.cti"
+//#include "PacketSocketHandle.ct"
+//#include "PacketSocketHandle.cti"
//#include "PacketSocketHandle.mpp"
#endif
+++ /dev/null
-// $Id$
-//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.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 PacketProtocol and PacketSocketHandle internal header
- */
-
-#ifndef IH_PacketSocketHandle_
-#define IH_PacketSocketHandle_ 1
-
-// Custom includes
-
-///////////////////////////////ih.p////////////////////////////////////////
-
-namespace senf {
-
-namespace detail {
-
- /** \brief Abstract address copier
- \internal
-
- This class provides the abstract interface to copy a
- link-local address to a destination address.
- */
- struct LLAddressCopier
- {
- virtual ~LLAddressCopier() {}
- virtual unsigned operator()(unsigned char * target) const = 0;
- };
-
- /** \brief Implementation of LLAddressCopier to copy arbitrary Range
- \internal
-
- This implementation of the LLAddressCopier interface will copy
- an arbitrary range to the target address. This class is used,
- to convert the compile-time polymorphism of templates
- (provided by the \c ForwardRange template argument) into
- runtime polymorphism (provided by the abstract LLAddressCopier
- interface).
- */
- template <class ForwardRange>
- struct Range_LLAddressCopier
- : public LLAddressCopier
- {
- Range_LLAddressCopier(ForwardRange const & range);
-
- unsigned operator()(unsigned char * target) const;
-
- ForwardRange const & range_;
- };
-
-}}
-
-///////////////////////////////ih.e////////////////////////////////////////
-#endif
-
-\f
-// Local Variables:
-// mode: c++
-// fill-column: 100
-// c-file-style: "senf"
-// indent-tabs-mode: nil
-// ispell-local-dictionary: "american"
-// compile-command: "scons -u test"
-// comment-column: 40
-// End:
// How am I supposed to test read and write .. grmpf ..
BOOST_CHECK_NO_THROW( sock.protocol().mcAdd(
- "eth0",senf::llAddress("01-02-03-04-05-06")) );
+ "eth0",senf::MACAddress::from_string("01-02-03-04-05-06")) );
BOOST_CHECK_NO_THROW( sock.protocol().mcDrop(
- "eth0",senf::llAddress("01-02-03-04-05-06")) );
+ "eth0",senf::MACAddress::from_string("01-02-03-04-05-06")) );
BOOST_CHECK_NO_THROW( sock.protocol().available() );
BOOST_CHECK( ! sock.eof() );
For addressable protocols (AddressingPolicy is not NoAddressingPolicy), bind() will set
the local address of the socket.
- \param[in] addr Local socket address to asign
+ \param[in] addr Local socket address to assign
\throws senf::SystemException
*/
This variant ...
\returns handle of new client connection
+
+ \fixme Make this accept()-variant work with unspecified addressing policy
*/
ClientSocketHandle
accept ();
+acceptfrom
accessor
+addr
+AddressingPolicy
+AddressingPolicyBase
addtogroup
aListCollection
alloc
callbacks
cerr
cfi
+ClientSocketHandle
+CommunicationPolicy
+CommunicationPolicyBase
ConcretePacket
+ConnectedCommunicationPolicy
const
createAfter
createBefore
FileHandle
findNext
findPrev
+fixme
fokus
FooParser
fraunhofer
fuer
hh
hideinitializer
+Hmm
href
+htm
html
http
ih
nextPacketKey
nextPacketRange
nextPacketType
+NoAddressingPolicy
noinit
nothrow
offene
SatCom
Satelitenkommunikation
senf
+ServerSocketHandle
setBegin
setEnd
setFromPosition
SimpleVectorSizer
SizeParser
skipline
+SocketHandle
someField
someOtherField
SomePacket
structors
SyntaxException
SystemException
+td
templated
todo
+tr
TruncatedPacketException
tt
ttl