removed some tabs
[senf.git] / Socket / Protocols / Raw / MACAddress.cc
index 768931f..22b0ca9 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -28,6 +28,8 @@
 
 // Custom includes
 #include <iomanip>
+#include <string>
+#include <sstream>
 #include <boost/tokenizer.hpp>
 #include <boost/io/ios_state.hpp>
 #include <boost/range.hpp>
@@ -41,26 +43,26 @@ namespace {
     boost::uint8_t hexToNibble(char c)
     {
         if (c<'0')
-            throw senf::MACAddress::SyntaxException();
+            throw senf::AddressSyntaxException();
         else if (c<='9')
             return c-'0';
         else if (c<'A')
-            throw senf::MACAddress::SyntaxException();
+            throw senf::AddressSyntaxException();
         else if (c<='F')
             return c-'A'+10;
         else if (c<'a')
-            throw senf::MACAddress::SyntaxException();
+            throw senf::AddressSyntaxException();
         else if (c<='f')
             return c-'a'+10;
         else
-            throw senf::MACAddress::SyntaxException();
+            throw senf::AddressSyntaxException();
     }
     
     template <class Range>
     boost::uint8_t hexToByte(Range const & range)
     {
         if (boost::size(range) != 2)
-            throw senf::MACAddress::SyntaxException();
+            throw senf::AddressSyntaxException();
         typename boost::range_const_iterator<Range>::type i (boost::begin(range));
         return hexToNibble(i[0])*16+hexToNibble(i[1]);
     }
@@ -72,7 +74,7 @@ namespace {
 
 prefix_ senf::MACAddress::MACAddress senf::MACAddress::from_string(std::string const & s)
 {
-    MACAddress mac (MACAddress::noinit);
+    MACAddress mac (senf::noinit);
     typedef boost::char_separator<char> separator;
     typedef boost::tokenizer<separator> tokenizer;
     separator sep (":-");
@@ -84,15 +86,15 @@ prefix_ senf::MACAddress::MACAddress senf::MACAddress::from_string(std::string c
     for (; i!=i_end && j!=j_end; ++i, ++j)
         *j = hexToByte(*i);
     if (i!=i_end || j!=j_end)
-        throw SyntaxException();
+        throw AddressSyntaxException();
     return mac;
 }
 
 prefix_ senf::MACAddress senf::MACAddress::from_eui64(boost::uint64_t v)
 {
     if ( boost::uint16_t(v>>24)  != 0xfffe )
-        throw SyntaxException();
-    MACAddress mac (MACAddress::noinit);
+        throw AddressSyntaxException();
+    MACAddress mac (senf::noinit);
     mac[0] = boost::uint8_t( v>>56 );
     mac[1] = boost::uint8_t( v>>48 );
     mac[2] = boost::uint8_t( v>>40 );
@@ -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