Socket: Fix copying of in-valid() handles
g0dil [Wed, 8 Apr 2009 07:50:42 +0000 (07:50 +0000)]
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

PPI/IOEvent.cti
Socket/Protocols/INet/INet6Address.cci
Socket/Protocols/INet/INet6Address.hh
Socket/Protocols/INet/INetAddressing.test.cc
Socket/Protocols/Raw/LLAddressing.cc
Socket/Protocols/Raw/LLAddressing.cci
Socket/SocketHandle.cti

index 7372e36..1b160e0 100644 (file)
 
 template <class Handle>
 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_
index 93ab3c0..9a71c7b 100644 (file)
@@ -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
 {
index 953bc49..3eb7094 100644 (file)
@@ -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
+                                             <tt>fe80::xxxx:xxff:fexx:xxxx</tt>. */
+        
         in6_addr toin6_addr() const;    ///< get the linux in6_addr struct (convinience only)
 
         ///@}
index 0dd2d95..3fcb053 100644 (file)
@@ -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 );
index 97316c9..faec193 100644 (file)
@@ -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"
index 411e7b9..374840b 100644 (file)
@@ -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_
 
index acdf0dc..310dfdd 100644 (file)
@@ -68,7 +68,7 @@ prefix_ senf::SocketHandle<SPolicy>::SocketHandle(FileHandle other, bool isCheck
     : FileHandle(other)
 {
     SENF_ASSERT( isChecked );
-    SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+    SENF_ASSERT( ! valid() || dynamic_cast<SocketBody *>(&FileHandle::body()) );
 }
 
 template <class SPolicy>