4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief EUI64 public header */
31 #ifndef HH_SENF_Socket_Protocols_Raw_EUI64_
32 #define HH_SENF_Socket_Protocols_Raw_EUI64_ 1
36 #include <boost/cstdint.hpp>
37 #include <boost/array.hpp>
38 #include <senf/Utils/Tags.hh>
39 #include <senf/Utils/safe_bool.hh>
41 //#include "EUI64.mpp"
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 /** \brief EUI-64 data type
50 An EUI-64 is a 64 bit (8 octet) id. The id is represented as an 8 byte sequence in network
51 byte order. An EUI64 can be converted from/to several other representations
54 <tr><td><tt>boost::uint64_t</tt></td>
55 <td><tt>senf::EUI64(0x1a2b3c4d5f607182ull)</tt><br/>
56 <i>eui64</i><tt>.uint64()</tt></td></tr>
57 <tr><td><tt>std::string</tt></td>
58 <td><tt>senf::EUI64::from_string("1a:2b:3c:4d-5f:60:71:82")</tt><br/>
59 <tt>senf::str(</tt><i>eui64</i><tt>)</tt></td></tr>
60 <tr><td><i>raw data</i><br/> (8 bytes)</td>
61 <td><tt>senf::EUI64::from_data(</tt><i>iterator</i><tt>)</tt><br/>
62 <i>eui64</i><tt>.begin()</tt></td></tr>
63 <tr><td>senf::MACAddress<br/> (aka EUI-48)</td>
64 <td><tt>senf::EUI64::from_mac(</tt><i>mac-address</i><tt>)</tt><br/>
65 <tt>senf::MACAddress::from_eui64(</tt><i>eui64</i><tt>)</tt></td></tr>
68 Since senf::EUI64 is based on \c boost::array, you can access the raw data bytes of the
69 address using \c begin(), \c end() or \c operator[]:
71 senf::EUI64 eui64 (...);
72 std::vector<char> data;
74 std::copy(eui64.begin(), eui64.end(), data.begin()); // Copy 8 bytes
77 \see <a href="http://tools.ietf.org/html/rfc4291">RFC 4291</a>
82 : public boost::array<boost::uint8_t,8>,
83 public senf::comparable_safe_bool<EUI64>
86 //-////////////////////////////////////////////////////////////////////////
87 ///\name Structors and default members
90 static EUI64 const None; ///< The empty (0) address
92 // default copy constructor
93 // default copy assignment
95 // no conversion constructors
97 explicit EUI64(boost::uint64_t v=0u); ///< Construct EUI-64
98 explicit EUI64(senf::NoInit_t); ///< Construct <em>uninitialized</em> EUI-64
100 static EUI64 from_mac(MACAddress const & mac);
101 ///< Construct EUI-64 from senf::MACAddress
102 static EUI64 from_string(std::string const & s);
103 ///< Construct EUI-64 from string representation
104 /**< The string representation consists of 8 octets in
105 hexadecimal notation separated by ':' or '-'
106 \throws senf::AddressSyntaxException */
107 template <class InputIterator>
108 static EUI64 from_data(InputIterator i);
109 ///< Construct EUI-64 from 8 data octets
110 /**< The iterator \a i must point to a sequence of 8
111 octets in network byte order. */
114 //-////////////////////////////////////////////////////////////////////////
116 bool isMACCompatible() const; ///< \c true, if EUI64 is MAC compatible, \c false otherwise
117 /**< An EUI64 is MAC compatible if bytes 4th and 5th byte
118 (in network byte order) are 0xfffe. */
119 bool local() const; ///< \c true if the \e local bit is set, \c false otherwise
120 /**< The \e local bit is the second least significant bit of
121 the first octet (bit 6 in standard RFC bit numbering).
123 bool group() const; ///< \c true if the \e group bit is set, \c false otherwise
124 /**< The \e group bit is the least significant bit of the
125 first octet (bit 7 in standard RFC bit numbering). */
126 bool boolean_test() const; ///< \c true, if EUI64 is != 0, \c false otherwise
127 boost::uint64_t uint64() const; ///< Return EUI64 as integer number
130 /** \brief Write out EUI64 in it's string representation to stream
133 std::ostream & operator<<(std::ostream & os, EUI64 const & v);
135 /** \brief Read EUI64 string representation from stream
138 std::istream & operator>>(std::istream & is, EUI64 & v);
142 //-/////////////////////////////////////////////////////////////////////////////////////////////////
144 //#include "EUI64.ct"
152 // comment-column: 40
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"