Socket: added UnknownInterfaceException
tho [Thu, 7 Oct 2010 11:13:38 +0000 (11:13 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1730 270642c3-0616-0410-b53a-bc976706d245

senf/Socket/Protocols/AddressExceptions.hh
senf/Socket/Protocols/Raw/LLAddressing.cc
senf/Socket/Protocols/Raw/LLAddressing.hh
senf/Socket/Protocols/Raw/MACAddress.hh

index fb9e556..87788d3 100644 (file)
@@ -46,7 +46,7 @@ namespace senf {
     struct AddressSyntaxException : public AddressException
     {
         AddressSyntaxException() : AddressException("invalid address syntax") {}
-        AddressSyntaxException(const std::string &addr)
+        AddressSyntaxException(std::string const & addr)
             : AddressException("Invalid address syntax (\"" + addr + "\")") {}
     };
 
@@ -54,10 +54,18 @@ namespace senf {
     struct UnknownHostnameException : public AddressException
     {
         UnknownHostnameException() : AddressException("failed to resolve hostname") {}
-        UnknownHostnameException(const std::string &hostname)
+        UnknownHostnameException(std::string const & hostname)
             : AddressException("Failed to resolve hostname (\"" + hostname + "\")") {}
     };
 
+    /** \brief Unknown interface */
+    struct UnknownInterfaceException : public AddressException
+    {
+        UnknownInterfaceException() : AddressException("Unknown interface") {}
+        UnknownInterfaceException(std::string const & interface)
+            : AddressException("Unknown interface (\"" + interface + "\")") {}
+    };
+
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index 1dac997..8950b6e 100644 (file)
@@ -48,7 +48,7 @@ prefix_ std::string senf::LLSocketAddress::interface()
     char name[IFNAMSIZ];
     ::bzero(name, IFNAMSIZ);
     if (! ::if_indextoname(addr_.sll_ifindex, name))
-        throw AddressSyntaxException();
+        throw UnknownInterfaceException();
     return std::string(name);
 }
 
@@ -59,7 +59,7 @@ prefix_ void senf::LLSocketAddress::interface(std::string const & iface)
     else {
         addr_.sll_ifindex = if_nametoindex(iface.c_str());
         if (addr_.sll_ifindex == 0)
-            throw AddressSyntaxException();
+            throw UnknownInterfaceException(iface);
     }
 }
 
index 4ec1740..d4a9d32 100644 (file)
@@ -82,11 +82,13 @@ namespace senf {
                                              PacketSocketHandle::bind() with.
                                              \param[in] proto Protocol (Ethertype) to listen for
                                              \param[in] iface Interface name to bind to */
-        explicit LLSocketAddress(std::string const &iface);
+        explicit LLSocketAddress(std::string const & iface);
                                         ///< Create address for \c bind()
                                         /**< This constructs an LLSocketAddress valid for calling
                                              \c PacketSocketHandle::bind() with.
-                                             \param[in] iface Interface name to bind to */
+                                             \param[in] iface Interface name to bind to
+                                             \throws UnknownInterfaceException if \a iface is not
+                                                 a valid interface name. */
 
         // This constructor is for sending packets
         explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
@@ -95,7 +97,9 @@ namespace senf {
                                              use with \c PacketSocketHandle::sendto() on a \c
                                              SOCK_DGRAM packet socket.
                                              \param addr Address to send data to
-                                             \param iface Interface to send packet from */
+                                             \param iface Interface to send packet from
+                                             \throws UnknownInterfaceException if \a iface is not
+                                                 a valid interface name. */
 
         LLSocketAddress(const LLSocketAddress& other);
         LLSocketAddress& operator=(const LLSocketAddress& other);
@@ -115,6 +119,8 @@ namespace senf {
 
         void address(MACAddress const & addr); ///< Change address
         void interface(std::string const & iface); ///< Change interface
+                                                   /**< \throws UnknownInterfaceException if \a iface
+                                                             is not a valid interface name. */
         void protocol(unsigned prot);   ///< Change protocol
 
         using BSDSocketAddress::sockaddr_p;
index fa99fa0..648cb69 100644 (file)
@@ -111,7 +111,7 @@ namespace senf {
                                              to a MAC address. This conversion is only possible, if
                                              the EUI-64 is MAC compatible: the 4th/5th byte (in
                                              transmission order) must be 0xFFFE.
-                                             \throws AddressSyntaxException if \a v is not a MAC
+                                             \throws AddressSyntaxException if \a eui is not a MAC
                                                  compatible EUI-64. */
 
         bool local() const;             ///< \c true, if address is locally administered