From: g0dil Date: Wed, 8 Apr 2009 07:50:42 +0000 (+0000) Subject: Socket: Fix copying of in-valid() handles X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=63798e5079a247de387d94b980bd87dc22968414;p=senf.git Socket: Fix copying of in-valid() handles PPI: Allow IOEvents to be constructed with an in-valid() handle Socket/Protocols/INet: Implement INet6Address::from_mac() Socket/Protocols/Raw: Implement LLSocketAddress output streaming git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1183 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/IOEvent.cti b/PPI/IOEvent.cti index 7372e36..1b160e0 100644 --- a/PPI/IOEvent.cti +++ b/PPI/IOEvent.cti @@ -36,9 +36,10 @@ template prefix_ senf::ppi::IOEvent::IOEvent(Handle handle, unsigned events) - : fd_ (senf::scheduler::get_descriptor(handle)), - event_ ("senf::ppi::IOEvent", boost::bind(&IOEvent::cb,this,_1), fd_, events, false) -{} + : fd_ (-1), event_ ("senf::ppi::IOEvent", boost::bind(&IOEvent::cb,this,_1)) +{ + set(handle,events); +} ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/Protocols/INet/INet6Address.cci b/Socket/Protocols/INet/INet6Address.cci index 93ab3c0..9a71c7b 100644 --- a/Socket/Protocols/INet/INet6Address.cci +++ b/Socket/Protocols/INet/INet6Address.cci @@ -72,6 +72,22 @@ prefix_ senf::INet6Address senf::INet6Address::from_inet4address(INet4Address co return addr; } +prefix_ senf::INet6Address senf::INet6Address::from_mac(senf::MACAddress const & mac) +{ + INet6Address addr; + addr[0] = 0xfe; + addr[1] = 0x80; + addr[8] = mac[0]; + addr[9] = mac[1]; + addr[10] = mac[2]; + addr[11] = 0xff; + addr[12] = 0xfe; + addr[13] = mac[3]; + addr[14] = mac[4]; + addr[15] = mac[5]; + return addr; +} + prefix_ boost::uint64_t senf::INet6Address::network() const { diff --git a/Socket/Protocols/INet/INet6Address.hh b/Socket/Protocols/INet/INet6Address.hh index 953bc49..3eb7094 100644 --- a/Socket/Protocols/INet/INet6Address.hh +++ b/Socket/Protocols/INet/INet6Address.hh @@ -37,6 +37,7 @@ #include "../../../Utils/Tags.hh" #include "INet4Address.hh" #include "../AddressExceptions.hh" +#include "../Raw/MACAddress.hh" //#include "INet6Address.mpp" #include "INet6Address.ih" @@ -203,6 +204,11 @@ namespace senf { \par INet4 compatible INet6 addresses are not directly supported, they are deprecated in the RFC. */ + static INet6Address from_mac(senf::MACAddress const & mac); + ///< Construct a link-local INet6 address + /**< This will construct a link local address of the form + fe80::xxxx:xxff:fexx:xxxx. */ + in6_addr toin6_addr() const; ///< get the linux in6_addr struct (convinience only) ///@} diff --git a/Socket/Protocols/INet/INetAddressing.test.cc b/Socket/Protocols/INet/INetAddressing.test.cc index 0dd2d95..3fcb053 100644 --- a/Socket/Protocols/INet/INetAddressing.test.cc +++ b/Socket/Protocols/INet/INetAddressing.test.cc @@ -61,7 +61,7 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress) BOOST_CHECK_THROW( INet4SocketAddress(":12345"), AddressSyntaxException ); BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1:1234a"), AddressSyntaxException ); - BOOST_CHECK_EQUAL( INet4SocketAddress(12345).port(), 12345 ); + BOOST_CHECK_EQUAL( INet4SocketAddress(12345).port(), 12345u ); BOOST_CHECK_EQUAL( INet4SocketAddress(12345).address(), INet4Address::None ); BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").address(), INet4Address::Loopback ); BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").port(), 12345u ); diff --git a/Socket/Protocols/Raw/LLAddressing.cc b/Socket/Protocols/Raw/LLAddressing.cc index 97316c9..faec193 100644 --- a/Socket/Protocols/Raw/LLAddressing.cc +++ b/Socket/Protocols/Raw/LLAddressing.cc @@ -63,6 +63,22 @@ prefix_ void senf::LLSocketAddress::interface(std::string const & iface) } } +prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr) +{ + os << "[" << llAddr.address() + << '%' << llAddr.interface() + << ' ' << llAddr.protocol() + << ' ' << llAddr.arptype() + << ( llAddr.pkttype() == senf::LLSocketAddress::Host ? " Host" : + llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? " Broadcast" : + llAddr.pkttype() == senf::LLSocketAddress::Multicast ? " Multicast" : + llAddr.pkttype() == senf::LLSocketAddress::OtherHost ? " OtherHost" : + llAddr.pkttype() == senf::LLSocketAddress::Outgoing ? " Outgoing" : + llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? "Broadcast" : "" ) + << "]"; + return os; +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "LLAddressing.mpp" diff --git a/Socket/Protocols/Raw/LLAddressing.cci b/Socket/Protocols/Raw/LLAddressing.cci index 411e7b9..374840b 100644 --- a/Socket/Protocols/Raw/LLAddressing.cci +++ b/Socket/Protocols/Raw/LLAddressing.cci @@ -100,13 +100,6 @@ prefix_ senf::MACAddress senf::LLSocketAddress::address() return MACAddress::from_data(&addr_.sll_addr[0]); } -prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr) -{ - // TODO: expose more bytes from sockaddr_ll addr_ - os << "[some LLSocketAddress]"; - return os; -} - ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/SocketHandle.cti b/Socket/SocketHandle.cti index acdf0dc..310dfdd 100644 --- a/Socket/SocketHandle.cti +++ b/Socket/SocketHandle.cti @@ -68,7 +68,7 @@ prefix_ senf::SocketHandle::SocketHandle(FileHandle other, bool isCheck : FileHandle(other) { SENF_ASSERT( isChecked ); - SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( ! valid() || dynamic_cast(&FileHandle::body()) ); } template