--- /dev/null
+// 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 non-inline non-template implementation */
+
+#include "INet4Address.hh"
+//#include "INet4Address.ih"
+
+// Custom includes
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#ifdef _REENTRANT
+#include <boost/thread/mutex.hpp>
+#endif
+
+//#include "INet4Address.mpp"
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::INet4Address::INet4Address
+
+prefix_ senf::INet4Address::INet4Address(address_type value)
+ : addr_(htonl(value))
+{}
+
+prefix_ senf::INet4Address senf::INet4Address::from_string(std::string const & s)
+{
+ ::in_addr ina;
+ if (::inet_pton(AF_INET,s.c_str(),&ina) > 0)
+ return senf::INet4Address::from_inaddr(ina.s_addr);
+# ifdef _REENTRANT
+ static boost::mutex mutex;
+ boost::mutex::scoped_lock lock(mutex);
+# endif
+ ::hostent * ent (::gethostbyname(s.c_str()));
+ if (!ent)
+ ///\fixme Need to give better exception here
+ throw SyntaxException();
+ if (ent->h_addrtype != AF_INET)
+ throw SyntaxException();
+ // We are only interested in the first address ...
+ return senf::INet4Address::from_inaddr(
+ reinterpret_cast<in_addr*>(*(ent->h_addr_list))->s_addr);
+}
+
+prefix_ bool senf::INet4Address::local()
+ const
+{
+ address_type l (ntohl(addr_));
+ return
+ (l & 0xFF000000u) == 0x0A000000u ||
+ (l & 0xFFF00000u) == 0xAC100000u ||
+ (l & 0xFFFF0000u) == 0xA9FE0000u ||
+ (l & 0xFFFF0000u) == 0xC0A80000u;
+}
+
+prefix_ bool senf::INet4Address::loopback()
+ const
+{
+ return (ntohl(addr_) & 0xFF000000u) == 0x7F000000u;
+}
+
+prefix_ bool senf::INet4Address::multicast()
+ const
+{
+ return (ntohl(addr_) & 0xF0000000u) == 0xE0000000u;
+}
+
+senf::INet4Address const senf::INet4Address::None;
+senf::INet4Address const senf::INet4Address::Loopback = senf::INet4Address(0x7F000001u);
+senf::INet4Address const senf::INet4Address::Broadcast = senf::INet4Address(0xFFFFFFFFu);
+
+
+///////////////////////////////////////////////////////////////////////////
+// namespace members
+
+prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const & addr)
+{
+ ::in_addr ina;
+ char buffer[16];
+ ina.s_addr = addr.raw();
+ ::inet_ntop(AF_INET,&ina,buffer,16);
+ buffer[15] = 0;
+ os << buffer;
+ return os;
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+//#include "INet4Address.mpp"
+
+\f
+// 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:
--- /dev/null
+// 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 non-template implementation */
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cci.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::INet4Address
+
+prefix_ senf::INet4Address::INet4Address()
+ : addr_()
+{}
+
+prefix_ senf::INet4Address senf::INet4Address::from_inaddr(unsigned long v)
+{
+ INet4Address addr;
+ addr.addr_ = v;
+ return addr;
+}
+
+prefix_ bool senf::INet4Address::broadcast()
+ const
+{
+ return addr_ == 0xFFFFFFFFu;
+}
+
+prefix_ bool senf::INet4Address::boolean_test()
+ const
+{
+ return addr_;
+}
+
+prefix_ unsigned long senf::INet4Address::raw()
+ const
+{
+ return addr_;
+}
+
+///////////////////////////////cci.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// 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:
--- /dev/null
+// 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
+
+#define prefix_ inline
+///////////////////////////////cti.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::INet4Address
+
+template <class InputIterator>
+prefix_ senf::INet4Address senf::INet4Address::from_data(InputIterator i)
+{
+ address_type v ((address_type(*i)&0xFF) << 24);
+ v |= (address_type(*++i)&0xFF) << 16;
+ v |= (address_type(*++i)&0xFF) << 8;
+ v |= (address_type(*++i)&0xFF);
+ return senf::INet4Address(v);
+}
+
+///////////////////////////////cti.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// 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:
--- /dev/null
+// 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 public header */
+
+#ifndef HH_INet4Address_
+#define HH_INet4Address_ 1
+
+// Custom includes
+#include <iostream>
+#include <string>
+#include <boost/cstdint.hpp>
+#include "Utils/SafeBool.hh"
+
+//#include "INet4Address.mpp"
+///////////////////////////////hh.p////////////////////////////////////////
+
+namespace senf {
+
+ /** \brief
+ */
+ class INet4Address
+ : public ComparableSafeBool<INet4Address>
+ {
+ public:
+ typedef uint32_t address_type;
+
+ static INet4Address const None;
+ static INet4Address const Loopback;
+ static INet4Address const Broadcast;
+
+ INet4Address();
+ explicit INet4Address(address_type value);
+
+ static INet4Address from_string(std::string const & s);
+ template <class InputIterator>
+ static INet4Address from_data(InputIterator i);
+ static INet4Address from_inaddr(unsigned long v);
+
+ bool local() const;
+ bool loopback() const;
+ bool multicast() const;
+ bool broadcast() const;
+ bool boolean_test() const;
+
+ unsigned long raw() const;
+
+ struct SyntaxException : public std::exception
+ { virtual char const * what() const throw() { return "invalid INet4 address syntax"; } };
+
+ private:
+ // Hmm ... address_type or unsigned long? I'd use address_type but the man pages for in_addr
+ // have sa_addr as unsigned long
+ unsigned long addr_;
+ };
+
+ std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
+
+}
+
+///////////////////////////////hh.e////////////////////////////////////////
+#include "INet4Address.cci"
+//#include "INet4Address.ct"
+#include "INet4Address.cti"
+#endif
+
+\f
+// 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:
--- /dev/null
+// 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.test unit tests */
+
+//#include "INet4Address.test.hh"
+//#include "INet4Address.test.ih"
+
+// Custom includes
+#include <arpa/inet.h>
+#include <sstream>
+#include "INet4Address.hh"
+
+#include <boost/test/auto_unit_test.hpp>
+#include <boost/test/test_tools.hpp>
+
+#define prefix_
+///////////////////////////////cc.p////////////////////////////////////////
+
+BOOST_AUTO_UNIT_TEST(inet4Address)
+{
+ senf::INet4Address addr (senf::INet4Address::from_string("127.0.0.1"));
+ BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
+
+ addr = senf::INet4Address::from_string("localhost");
+ BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback );
+ BOOST_CHECK( addr.loopback() );
+
+ char data[] = { 128, 129, 130, 131 };
+ addr = senf::INet4Address::from_data(data);
+ BOOST_CHECK_EQUAL( addr, senf::INet4Address::from_string("128.129.130.131") );
+ BOOST_CHECK_EQUAL( addr.raw(), htonl(0x80818283u) );
+
+ BOOST_CHECK( ! addr.loopback() );
+ BOOST_CHECK( ! addr.local() );
+ BOOST_CHECK( senf::INet4Address::from_string("192.168.1.2").local() );
+ BOOST_CHECK( ! addr.multicast() );
+ BOOST_CHECK( senf::INet4Address::from_string("224.1.2.3").multicast() );
+ BOOST_CHECK( ! addr.broadcast() );
+ BOOST_CHECK( senf::INet4Address::from_string("255.255.255.255").broadcast() );
+ BOOST_CHECK( addr );
+ BOOST_CHECK( ! senf::INet4Address() );
+
+ std::stringstream str;
+ str << addr;
+ BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
+}
+
+///////////////////////////////cc.e////////////////////////////////////////
+#undef prefix_
+
+\f
+// 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:
///////////////////////////////////////////////////////////////////////////
// senf::INet4Address
-prefix_ senf::INet4Address::INet4Address(std::string host, unsigned port)
+prefix_ senf::INet4SocketAddress::INet4SocketAddress(std::string host, unsigned port)
{
clear();
/** \todo gethostbyname support */
addr_.sin_port = htons(port);
}
-prefix_ std::string senf::INet4Address::str()
+prefix_ std::string senf::INet4SocketAddress::str()
const
{
std::stringstream s;
return s.str();
}
-prefix_ void senf::INet4Address::clear()
+prefix_ void senf::INet4SocketAddress::clear()
{
::memset(&addr_,0,sizeof(addr_));
addr_.sin_family = AF_INET;
}
-prefix_ void senf::INet4Address::assignString(std::string address)
+prefix_ void senf::INet4SocketAddress::assignString(std::string address)
{
clear();
unsigned i = address.find(':');
///////////////////////////////////////////////////////////////////////////
// senf::INet4Address
-prefix_ senf::INet4Address::INet4Address()
+prefix_ senf::INet4SocketAddress::INet4SocketAddress()
{
clear();
}
-prefix_ senf::INet4Address::INet4Address(char const * address)
+prefix_ senf::INet4SocketAddress::INet4SocketAddress(char const * address)
{
assignString(address);
}
-prefix_ senf::INet4Address::INet4Address(std::string address)
+prefix_ senf::INet4SocketAddress::INet4SocketAddress(std::string address)
{
assignString(address);
}
-prefix_ bool senf::INet4Address::operator==(INet4Address const & other)
+prefix_ bool senf::INet4SocketAddress::operator==(INet4SocketAddress const & other)
const
{
return addr_.sin_port == other.addr_.sin_port &&
addr_.sin_addr.s_addr == other.addr_.sin_addr.s_addr;
}
-prefix_ std::string senf::INet4Address::host()
+prefix_ std::string senf::INet4SocketAddress::host()
const
{
char buffer[128];
return std::string(::inet_ntop(AF_INET,&addr_.sin_addr,buffer,128));
}
-prefix_ unsigned senf::INet4Address::port()
+prefix_ unsigned senf::INet4SocketAddress::port()
const
{
return ntohs(addr_.sin_port);
}
-prefix_ struct sockaddr * senf::INet4Address::sockaddr_p()
+prefix_ struct sockaddr * senf::INet4SocketAddress::sockaddr_p()
{
return reinterpret_cast<struct sockaddr *>(&addr_);
}
-prefix_ struct sockaddr const * senf::INet4Address::sockaddr_p()
+prefix_ struct sockaddr const * senf::INet4SocketAddress::sockaddr_p()
const
{
return reinterpret_cast<struct sockaddr const *>(&addr_);
}
-prefix_ unsigned senf::INet4Address::sockaddr_len()
+prefix_ unsigned senf::INet4SocketAddress::sockaddr_len()
const
{
return sizeof(addr_);
}
-prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const & addr)
+prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4SocketAddress const & addr)
{
os << addr.str();
return os;
\todo Implement more complete interface
\todo gethostbyname support ?
*/
- class INet4Address
+ class INet4SocketAddress
{
public:
- INet4Address();
- INet4Address(char const * address); ///< Set address and port
- /**< See INet4Address(std::string)
+ INet4SocketAddress();
+ INet4SocketAddress(char const * address); ///< Set address and port
+ /**< See INet4SocketAddress(std::string)
\throws InvalidINetAddressException */
- INet4Address(std::string address); ///< Set address and port
+ INet4SocketAddress(std::string address); ///< Set address and port
/**< This constructor expects a string of the form
'xxx.xxx.xxx.xxx:pppp'. The constructor will use this
value to initialize the host and port members. This
not hostnames
\param[in] address Address and port
\throws InvalidINetAddressException */
- INet4Address(std::string host, unsigned port); ///< Set address and port explicitly
+ INet4SocketAddress(std::string host, unsigned port); ///< Set address and port explicitly
/**< \param[in] host ip address in dotted-quad notation
\param[in] port port number
\throws InvalidINetAddressException */
- bool operator==(INet4Address const & other) const; ///< Check INet4Address for equality
+ bool operator==(INet4SocketAddress const & other) const;
+ ///< Check INet4SocketAddress for equality
std::string str() const; ///< Return "address:port" string
std::string host() const; ///< Return address in doted quad notation
\related INet4Address
*/
- std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
+ std::ostream & operator<<(std::ostream & os, INet4SocketAddress const & addr);
/** \brief IPv6 network address
*/
struct INet4AddressingPolicy
: public AddressingPolicyBase,
- private GenericAddressingPolicy<INet4Address>
+ private GenericAddressingPolicy<INet4SocketAddress>
{
- typedef INet4Address Address;
+ typedef INet4SocketAddress Address;
- using GenericAddressingPolicy<INet4Address>::peer;
- using GenericAddressingPolicy<INet4Address>::local;
- using GenericAddressingPolicy<INet4Address>::connect;
- using GenericAddressingPolicy<INet4Address>::bind;
+ using GenericAddressingPolicy<INet4SocketAddress>::peer;
+ using GenericAddressingPolicy<INet4SocketAddress>::local;
+ using GenericAddressingPolicy<INet4SocketAddress>::connect;
+ using GenericAddressingPolicy<INet4SocketAddress>::bind;
};
/** \brief Addressing policy supporting IPv6 addressing
BOOST_AUTO_UNIT_TEST(inet4Address)
{
- using senf::INet4Address;
+ using senf::INet4SocketAddress;
using senf::InvalidINetAddressException;
{
- INet4Address addr;
+ INet4SocketAddress addr;
addr = "127.0.0.1:12345";
}
{
- INet4Address addr1("127.0.0.1:12345");
- INet4Address addr2(std::string("127.0.0.1:12345"));
- INet4Address addr3("127.0.0.1",12345);
+ INet4SocketAddress addr1("127.0.0.1:12345");
+ INet4SocketAddress addr2(std::string("127.0.0.1:12345"));
+ INet4SocketAddress addr3("127.0.0.1",12345);
}
- BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345"), INet4Address("127.0.0.1",12345) );
+ BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345"), INet4SocketAddress("127.0.0.1",12345) );
- BOOST_CHECK_THROW( INet4Address("127.0.0.1"), InvalidINetAddressException );
- BOOST_CHECK_THROW( INet4Address("foo@bar:12345"), InvalidINetAddressException );
- BOOST_CHECK_THROW( INet4Address("127.0.0.1:1234a"), InvalidINetAddressException );
- BOOST_CHECK_THROW( INet4Address("foo@bar",12345), InvalidINetAddressException );
+ BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1"), InvalidINetAddressException );
+ BOOST_CHECK_THROW( INet4SocketAddress("foo@bar:12345"), InvalidINetAddressException );
+ BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1:1234a"), InvalidINetAddressException );
+ BOOST_CHECK_THROW( INet4SocketAddress("foo@bar",12345), InvalidINetAddressException );
- BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").host(), "127.0.0.1" );
- BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").port(), 12345u );
- BOOST_CHECK_EQUAL( INet4Address("127.0.0.1:12345").str(), "127.0.0.1:12345" );
+ BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").host(), "127.0.0.1" );
+ BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").port(), 12345u );
+ BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").str(), "127.0.0.1:12345" );
{
- INet4Address addr("127.0.0.1:12345");
+ INet4SocketAddress addr("127.0.0.1:12345");
BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_port,
htons(12345) );
BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_addr.s_addr,
///////////////////////////////////////////////////////////////////////////
// senf::IPv4Protocol
-prefix_ void senf::IPv4Protocol::connect(INet4Address const & address)
+prefix_ void senf::IPv4Protocol::connect(INet4SocketAddress const & address)
const
{
if (::connect(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
throw SystemException(errno);
}
-prefix_ void senf::IPv4Protocol::bind(INet4Address const & address)
+prefix_ void senf::IPv4Protocol::bind(INet4SocketAddress const & address)
const
{
if (::bind(body().fd(),address.sockaddr_p(), address.sockaddr_len()) < 0)
: public virtual SocketProtocol
{
public:
- void connect(INet4Address const & address) const; ///< Connect to remote address
+ void connect(INet4SocketAddress const & address) const; ///< Connect to remote address
/**< \todo make this obsolete by allowing access to the
ClientSocketHandle from ConcreateSocketProtocol
\param[in] address Address to connect to */
- void bind(INet4Address const & address) const; ///< Set local socket address
+ void bind(INet4SocketAddress const & address) const; ///< Set local socket address
/**< \todo make this obsolete by allowing access to the
ClientSocketHandle from ConcreateSocketProtocol
\param[in] address Address to set */
}
prefix_ void
-senf::TCPv4SocketProtocol::init_client(INet4Address const & address)
+senf::TCPv4SocketProtocol::init_client(INet4SocketAddress const & address)
const
{
init_client();
body().fd(sock);
}
-prefix_ void senf::TCPv4SocketProtocol::init_server(INet4Address const & address,
+prefix_ void senf::TCPv4SocketProtocol::init_server(INet4SocketAddress const & address,
unsigned backlog)
const
{
/**< \note This member is implicitly called from the
ProtocolClientSocketHandle::ProtocolClientSocketHandle()
constructor */
- void init_client(INet4Address const & address) const;
+ void init_client(INet4SocketAddress const & address) const;
///< Create client socket and connect
/**< Creates a new client socket and connects to the given
address.
/**< \note This member is implicitly called from the
ProtocolServerSocketHandle::ProtocolServerSocketHandle()
constructor */
- void init_server(INet4Address const & address, unsigned backlog=1) const;
+ void init_server(INet4SocketAddress const & address, unsigned backlog=1) const;
///< Create server socket and listen
/**< Creates a new server socket, binds to \a address end
starts listening for new connections with a backlog of
{
senf::TCPv4ClientSocketHandle sock;
- BOOST_CHECK_THROW( sock.connect(senf::INet4Address("127.0.0.1:12345")), senf::SystemException );
+ BOOST_CHECK_THROW( sock.connect(senf::INet4SocketAddress("127.0.0.1:12345")), senf::SystemException );
BOOST_CHECK_THROW( sock.protocol().connect("127.0.0.1:12345"), senf::SystemException );
}
throw SystemException(errno);
}
-prefix_ void senf::UDPProtocol::mcAddMembership(INet4Address const & mcAddr)
+prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAddr)
const
{
struct ip_mreqn mreqn;
throw SystemException(errno);
}
-prefix_ void senf::UDPProtocol::mcAddMembership(INet4Address const & mcAddr,
- INet4Address const & localAddr)
+prefix_ void senf::UDPProtocol::mcAddMembership(INet4SocketAddress const & mcAddr,
+ INet4SocketAddress const & localAddr)
const
{
struct ip_mreqn mreqn;
throw SystemException(errno);
}
-prefix_ void senf::UDPProtocol::mcDropMembership(INet4Address const & mcAddr)
+prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAddr)
const
{
struct ip_mreqn mreqn;
throw SystemException(errno);
}
-prefix_ void senf::UDPProtocol::mcDropMembership(INet4Address const & mcAddr,
- INet4Address const & localAddr)
+prefix_ void senf::UDPProtocol::mcDropMembership(INet4SocketAddress const & mcAddr,
+ INet4SocketAddress const & localAddr)
const
{
struct ip_mreqn mreqn;
bool mcLoop() const; ///< Return current multicast loopback state
void mcLoop(bool value) const; ///< Set multicast loopback state
- void mcAddMembership(INet4Address const & mcAddr) const;
+ void mcAddMembership(INet4SocketAddress const & mcAddr) const;
///< Join multicast group
/**< This member will add \a mcAddr to the list of multicast
groups received. The group is joined on the default
\param[in] mcAddr address of group to join
\todo fix this as soon as we have a real address class
(different from the sockaddress class */
- void mcAddMembership(INet4Address const & mcAddr, INet4Address const & localAddr) const;
+ void mcAddMembership(INet4SocketAddress const & mcAddr, INet4SocketAddress const & localAddr) const;
///< join multicast group on a specific address/interface
/**< This member will add \a mcAddr to the list of multicast
groups received. The group is joined on the interface
\todo fix this as soon as we have a real address class
(different from the sockaddress class */
- void mcDropMembership(INet4Address const & mcAddr) const;
+ void mcDropMembership(INet4SocketAddress const & mcAddr) const;
///< Leave multicast group
/**< This member will remove \a mcAddr from the list of
multicast groups received. The group is left from the
\param[in] mcAddr address of group to leave
\todo fix this as soon as we have a real address class
(different from the sockaddress class */
- void mcDropMembership(INet4Address const & mcAddr, INet4Address const & localAddr) const;
+ void mcDropMembership(INet4SocketAddress const & mcAddr, INet4SocketAddress const & localAddr) const;
///< leave multicast group on a specific address/interface
/**< This member will remove \a mcAddr from the list of
multicast groups received. The group is left from the
}
prefix_ void
-senf::UDPv4SocketProtocol::init_client(INet4Address const & address)
+senf::UDPv4SocketProtocol::init_client(INet4SocketAddress const & address)
const
{
init_client();
/**< \note This member is implicitly called from the
ProtocolClientSocketHandle::ProtocolClientSocketHandle()
constructor */
- void init_client(INet4Address const & address) const;
+ void init_client(INet4SocketAddress const & address) const;
///< Create client socket and connect
/**< Creates a new client socket and connects to the given
address.
BOOST_CHECK_EQUAL( a.protocol(), 123u );
BOOST_CHECK_EQUAL( a.interface(), "lo" );
BOOST_CHECK_EQUAL( a.arptype(), 0u );
- BOOST_CHECK_EQUAL( a.pkttype(), 0u );
+ BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
BOOST_CHECK( ! a.address() );
}
}
return mac;
}
+senf::MACAddress const senf::MACAddress::Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull);
+senf::MACAddress const senf::MACAddress::None;
+
///////////////////////////////////////////////////////////////////////////
// namespace members
prefix_ senf::MACAddress::MACAddress(NoInit_t)
{}
+prefix_ senf::MACAddress::MACAddress(boost::uint64_t v)
+{
+ (*this)[0] = boost::uint8_t( v>>40 );
+ (*this)[1] = boost::uint8_t( v>>32 );
+ (*this)[2] = boost::uint8_t( v>>24 );
+ (*this)[3] = boost::uint8_t( v>>16 );
+ (*this)[4] = boost::uint8_t( v>> 8 );
+ (*this)[5] = boost::uint8_t( v );
+}
+
prefix_ bool senf::MACAddress::local()
const
{
return (*this)[0] & 0x02;
}
-prefix_ bool senf::MACAddress::group()
+prefix_ bool senf::MACAddress::multicast()
const
{
return (*this)[0] & 0x01;
: public boost::array<boost::uint8_t,6>,
public ComparableSafeBool<MACAddress>
{
+ static MACAddress const Broadcast; ///< The broadcast address
+ static MACAddress const None; ///< The empty (0) address
+
enum NoInit_t { noinit };
MACAddress(); ///< Construct zero-initialized address
MACAddress(NoInit_t); ///< Construct uninitialized (!) address
+ explicit MACAddress(boost::uint64_t v); ///< Construct MACAddress constants
static MACAddress from_string(std::string const & s);
///< Construct address from string representation
EUI-64. */
bool local() const; ///< \c true, if address is locally administered
- bool group() const; ///< \c true, if address is a group/multicast address
+ bool multicast() const; ///< \c true, if address is a group/multicast address
bool broadcast() const; ///< \c true, if address is the broadcast address
bool boolean_test() const; ///< \c true, if address is the zero address
BOOST_AUTO_UNIT_TEST(macAddress)
{
senf::MACAddress mac (senf::MACAddress::from_string("A1-b2-C3:d4:E5:f6"));
+
+ BOOST_CHECK_EQUAL( mac[0], 0xA1u );
+ BOOST_CHECK_EQUAL( mac[1], 0xB2u );
+ BOOST_CHECK_EQUAL( mac[2], 0xC3u );
+ BOOST_CHECK_EQUAL( mac[3], 0xD4u );
+ BOOST_CHECK_EQUAL( mac[4], 0xE5u );
+ BOOST_CHECK_EQUAL( mac[5], 0xF6u );
+
std::stringstream str;
str << mac;
BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
BOOST_CHECK( ! mac.local() );
- BOOST_CHECK( mac.group() );
+ BOOST_CHECK( mac.multicast() );
BOOST_CHECK( ! mac.broadcast() );
BOOST_CHECK( mac );
BOOST_CHECK_EQUAL( mac.oui(), 0xa1b2c3u );
BOOST_CHECK( ! mac2 );
mac2 = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff");
BOOST_CHECK( mac2.broadcast() );
+ BOOST_CHECK_EQUAL( mac2, senf::MACAddress::Broadcast );
char data[] = { 0x01,0x02,0x03,0x04,0x05,0x06 };
mac2 = senf::MACAddress::from_data(data);
BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(mac2), "01:02:03:04:05:06" );