From: dw6 Date: Fri, 27 Jun 2008 13:18:35 +0000 (+0000) Subject: adding MACAddress::toString() X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=0cb9d9525b4e6362bd32429bf053df4cd4ee8011;p=senf.git adding MACAddress::toString() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@885 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Protocols/Raw/MACAddress.cc b/Socket/Protocols/Raw/MACAddress.cc index 4ab2e3f..c12b0ed 100644 --- a/Socket/Protocols/Raw/MACAddress.cc +++ b/Socket/Protocols/Raw/MACAddress.cc @@ -28,6 +28,8 @@ // Custom includes #include +#include +#include #include #include #include @@ -105,6 +107,12 @@ prefix_ senf::MACAddress senf::MACAddress::from_eui64(boost::uint64_t v) senf::MACAddress const senf::MACAddress::Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull); senf::MACAddress const senf::MACAddress::None; +prefix_ std::string senf::MACAddress::toString() const { + std::ostringstream tmp; + tmp << (*this); + return tmp.str(); +} + /////////////////////////////////////////////////////////////////////////// // namespace members diff --git a/Socket/Protocols/Raw/MACAddress.hh b/Socket/Protocols/Raw/MACAddress.hh index 9165c05..de52a30 100644 --- a/Socket/Protocols/Raw/MACAddress.hh +++ b/Socket/Protocols/Raw/MACAddress.hh @@ -67,7 +67,14 @@ namespace senf { INet6Address(0x2001u,0xDB8u,0x1u,0x0u,0x001Au,0x2BFFu,0xFE3Cu,0x3D5Fu).id()) \endcode - Since MACAddress is based on \c boost::array, you can access the raw data bytes of the + Since MACAddress is based on \c boo Ziel, aber nur ein paar davon sind standardkomform. + +Der aktuelle C++ Standard unterstützt drei verschiedene Möglichkeiten eine Zahl in einen String umzuwandeln. Diese Möglichkeiten sind: + + * sprintf + * std::strstream + * std::stringstream + st::array, you can access the raw data bytes of the address using \c begin(), \c end() or \c operator[]: \code MACAddress mac = ...; @@ -128,6 +135,8 @@ namespace senf { boost::uint32_t nic() const; ///< Return last 3 bytes of the address boost::uint64_t eui64() const; ///< Build EUI-64 from the MAC address + + std::string toString() const; ///< Return string representation of MAC address like 12:34:56:78:90:ab }; diff --git a/Socket/Protocols/Raw/MACAddress.test.cc b/Socket/Protocols/Raw/MACAddress.test.cc index d4126e0..df256c9 100644 --- a/Socket/Protocols/Raw/MACAddress.test.cc +++ b/Socket/Protocols/Raw/MACAddress.test.cc @@ -39,7 +39,8 @@ BOOST_AUTO_UNIT_TEST(macAddress) { - senf::MACAddress mac (senf::MACAddress::from_string("A1-b2-C3:d4:E5:f6")); + std::string test ("A1-b2-C3:d4:E5:f6"); + senf::MACAddress mac (senf::MACAddress::from_string(test)); BOOST_CHECK_EQUAL( mac[0], 0xA1u ); BOOST_CHECK_EQUAL( mac[1], 0xB2u ); @@ -51,7 +52,8 @@ BOOST_AUTO_UNIT_TEST(macAddress) std::stringstream str; str << mac; BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" ); - + BOOST_CHECK_EQUAL (mac.toString(), "a1:b2:c3:d4:e5:f6"); + BOOST_CHECK( ! mac.local() ); BOOST_CHECK( mac.multicast() ); BOOST_CHECK( ! mac.broadcast() );