docu fix for Packet.as<>()
[senf.git] / Packets / DefaultBundle / EthernetPacket.cc
index 9926efc..b3ba75b 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -51,45 +51,42 @@ prefix_ void senf::EthernetPacketType::dump(packet p, std::ostream & os)
         os << "Ethernet II (DIX)";
     else
         os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
-    os << ": \n"
-       << "  destination : " << p->destination() << "\n"
-       << "  source      : " << p->source() << "\n"
-       << "  type/length : 0x" 
-       << std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n";
+    os <<     ": \n"
+       <<     "  destination             : " << p->destination() << "\n"
+       <<     "  source                  : " << p->source() << "\n"
+       <<     "  type/length             : 0x" 
+       <<     std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n";
 }
 
 prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p)
 {
-    if (p->type_length() >= 1536) {
-        PkReg_Entry const * e;
-        e = PacketRegistry<senf::EtherTypes>::lookup( p->type_length(), nothrow );
-        return e ? e->factory() : no_factory();
-    }
-    if (p->type_length() <= 1500)
-        return LlcSnapPacket::factory();
-    return no_factory();
+    if      (p->type_length() >= 1536) return lookup(p->type_length());
+    else if (p->type_length() <= 1500) return LlcSnapPacket::factory();
+    else                               return no_factory();
 }
 
 prefix_ void senf::EthernetPacketType::finalize(packet p)
 {
-    optional_registry_key_t k = key(p.next(nothrow));
-    if (k)
-        p->type_length() << k;
-    else
-        if (p.next().is<LlcSnapPacket>())
-            p->type_length() << p.next().data().size();
+    Packet n (p.next(nothrow));
+    if (n) {
+        optional_key_t k (key(n));
+        if (k)
+            p->type_length() << k;
+        else if (n.is<LlcSnapPacket>())
+            p->type_length() << n.data().size();
+    }
     // Do NOT reset type_length if the type is not known ... doing this will destroy read packets
 }
 
 prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os)
 {
     boost::io::ios_all_saver ias(os);
-    os << "Ethernet 802.1q (VLAN):\n"
-       << "  priority      : " << p->priority() << "\n"
-       << "  cfi           : " << p->cfi() << "\n"
-       << "  vlan-ID       : " << p->vlanId() << "\n"
-       << "  ethertype     : 0x" 
-       << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n";
+    os <<     "Ethernet 802.1q (VLAN):\n"
+       <<     "  priority                : " << p->priority() << "\n"
+       <<     "  cfi                     : " << p->cfi() << "\n"
+       <<     "  vlan-ID                 : " << p->vlanId() << "\n"
+       <<     "  ethertype               : 0x" 
+       <<     std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n";
 }
 
 prefix_ void senf::EthVLanPacketType::finalize(packet p)