PPI: Add missing TargetDgramWriter doku
[senf.git] / Socket / Protocols / Raw / LLAddressing.cc
index 13038c3..71addad 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// 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
 // it under the terms of the GNU General Public License as published by
@@ -34,7 +34,8 @@
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/finder.hpp>
 
-#include "Utils/Exception.hh"
+#include "../../../Utils/Exception.hh"
+#include "../AddressExceptions.hh"
 
 //#include "LLAddressing.mpp"
 #define prefix_
@@ -46,22 +47,39 @@ prefix_ std::string senf::LLSocketAddress::interface()
     if (addr_.sll_ifindex == 0)
         return std::string();
     char name[IFNAMSIZ];
+    ::bzero(name, IFNAMSIZ);
     if (! ::if_indextoname(addr_.sll_ifindex, name))
-        throw InvalidLLSocketAddressException();
+        throw AddressSyntaxException();
     return std::string(name);
 }
 
-prefix_ void senf::LLSocketAddress::interface(std::string iface)
+prefix_ void senf::LLSocketAddress::interface(std::string const & iface)
 {
     if (iface.empty()) 
         addr_.sll_ifindex = 0;
     else {
         addr_.sll_ifindex = if_nametoindex(iface.c_str());
         if (addr_.sll_ifindex == 0)
-            throw InvalidLLSocketAddressException();
+            throw AddressSyntaxException();
     }
 }
 
+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"