X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FMACAddress.cc;h=e8fb19bf2cd3f2476bc93704f55e2d3ca2b3f289;hb=81f84badf27b66dbadec9890646ca1193e998505;hp=48d2a1b413b01e5d78e810e8fd6cf4022e8ce18d;hpb=66293acca094b2f29e26e70208691db4af274efb;p=senf.git diff --git a/Socket/Protocols/Raw/MACAddress.cc b/Socket/Protocols/Raw/MACAddress.cc index 48d2a1b..e8fb19b 100644 --- a/Socket/Protocols/Raw/MACAddress.cc +++ b/Socket/Protocols/Raw/MACAddress.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -28,6 +28,8 @@ // Custom includes #include +#include +#include #include #include #include @@ -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 boost::uint8_t hexToByte(Range const & range) { if (boost::size(range) != 2) - throw senf::MACAddress::SyntaxException(); + throw senf::AddressSyntaxException(); typename boost::range_const_iterator::type i (boost::begin(range)); return hexToNibble(i[0])*16+hexToNibble(i[1]); } @@ -84,14 +86,14 @@ 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(); + throw AddressSyntaxException(); MACAddress mac (senf::noinit); mac[0] = boost::uint8_t( v>>56 ); mac[1] = boost::uint8_t( v>>48 ); @@ -105,6 +107,7 @@ 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; + /////////////////////////////////////////////////////////////////////////// // namespace members @@ -120,11 +123,25 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, MACAddress const & ma return os; } +prefix_ std::istream & senf::operator>>(std::istream & is, MACAddress & mac) +{ + std::string s; + if (!(is >> s)) + return is; + try { + mac = MACAddress::from_string(s); + } + catch (AddressException &) { + is.setstate(std::ios::failbit); + } + return is; +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "MACAddress.mpp" - + // Local Variables: // mode: c++ // fill-column: 100