X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FMACAddress.hh;h=cc4a6bad361a95fbd6d0fcd7f50f1f954f0c1995;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=3b1e94c8615b27e0a66e5ca4c0f9d331c3bd662b;hpb=4004cfae8ca0e03a40385560e14bba730a801464;p=senf.git
diff --git a/Socket/Protocols/Raw/MACAddress.hh b/Socket/Protocols/Raw/MACAddress.hh
index 3b1e94c..cc4a6ba 100644
--- a/Socket/Protocols/Raw/MACAddress.hh
+++ b/Socket/Protocols/Raw/MACAddress.hh
@@ -41,39 +41,35 @@
namespace senf {
+ class EUI64;
+
/** \brief Ethernet MAC address
-
- The Ethernet MAC is modelled as a fixed-size container/sequence of 6 bytes.
- The following statements all create the same MAC address 00:1A:2B:3C:4D:5F
- \code
- // Used to construct constant MAC addresses
- MACAddress(0x001A2B3C4D5Flu)
-
- // Construct a MAC address from it's string representation:
- MACAddress::from_string("00:1a:2b:3c:4d:5f") // case is ignored
- MACAddress::from_string("00-1A-2B-3C-4D-5F") // '-' as separator is allowed too
-
- // Construct a MAC address from raw data. 'from_data' takes an arbitrary iterator (e.g. a
- // pointer) as argument. Here we use a fixed array but normally you will need this to build
- // a MAC address in a packet parser
- char rawBytes[] = { 0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5F };
- MACAddress::from_data(rawBytes)
-
- // Construct a MAC from the EUID64 as used by INet6 interfaces. The eui64 will come from an
- // INet6 address:
- MACAddress::from_eui64(0x001A2BFFFE3C4D5Ful)
- MACAddress::from_eui64(
- INet6Address(0x2001u,0xDB8u,0x1u,0x0u,0x001Au,0x2BFFu,0xFE3Cu,0x3D5Fu).id())
- \endcode
+ The Ethernet MAC is modelled as a fixed-size container/sequence of 6 bytes. A MACAddress can
+ be converted from/to the following representations
+
+
+ boost::uint64_t |
+ senf::MACAddress(0x112233445566ull)
+ mac.uint64() |
+ std::string |
+ senf::MACAddress::from_string("11:22:33:44:55:66")
+ senf::str(mac) |
+ raw data (6 bytes) |
+ senf::MACAddress::from_data(iterator)
+ mac.begin() |
+ senf::EUI64 |
+ senf::MACAddress::from_eui64(eui64)
+ senf::EUI64::from_mac(mac) |
+
Since MACAddress is based on \c boost::array, you can access the raw data bytes of the
address using \c begin(), \c end() or \c operator[]:
\code
- MACAddress mac = ...;
- Packet::iterator i = ...;
-
- std::copy(mac.begin(), mac.end(), i); // Copies 6 bytes
+ senf::MACAddress mac (...);
+ std::vector data;
+ data.resize(6);
+ std::copy(mac.begin(), mac.end(), data.begin()); // Copy 6 bytes
\endcode
\implementation We awkwardly need to use static named constructors (from_ members)
@@ -85,7 +81,7 @@ namespace senf {
\ingroup addr_group
*/
struct MACAddress
- : public boost::array,
+ : public boost::array,
public comparable_safe_bool
{
static MACAddress const Broadcast; ///< The broadcast address
@@ -103,14 +99,14 @@ namespace senf {
accepted as a delimiter.
\throws AddressSyntaxException */
- template
+ template
static MACAddress from_data(InputIterator i);
///< Construct address from raw data
/**< Copies the data from \a i into the MAC address.
\pre The input range at \a i must have a size of at
least 6 elements. */
- static MACAddress from_eui64(boost::uint64_t v);
+ static MACAddress from_eui64(senf::EUI64 const & eui);
///< Construct address from EUI-64
/**< This constructor takes an EUI-64 value and converts it
to a MAC address. This conversion is only possible, if
@@ -120,23 +116,27 @@ namespace senf {
compatible EUI-64. */
bool local() const; ///< \c true, if address is locally administered
- bool multicast() 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 not the zero address
boost::uint32_t oui() const; ///< Return first 3 bytes of the address
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
+ boost::uint64_t eui64() const; ///< Build EUI-64 from the MAC address
+ boost::uint64_t uint64() const; ///< Return MAC address as uint64 value
};
- /** \brief Write MAC address
+ /** \brief Output MAC instance as it's string representation
\related MACAddress
*/
std::ostream & operator<<(std::ostream & os, MACAddress const & mac);
+ /** \brief Try to initialize MACAddress instance from a string representation
+ sets std::ios::failbit on the stream if an error occurred
+ \see MACAddress from_string()
+ \related MACAddress
+ */
+ std::istream & operator>>(std::istream & os, MACAddress & mac);
}
@@ -146,7 +146,7 @@ namespace senf {
//#include "MACAddress.cti"
#endif
-
+
// Local Variables:
// mode: c++
// fill-column: 100