add InetSocketAddress::IsMatchingType and use it
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 30 Jul 2007 13:55:28 +0200
changeset 1172 2e5b994330c7
parent 1171 335886fe4ddd
child 1173 06e382cadbbb
add InetSocketAddress::IsMatchingType and use it
src/internet-node/udp-socket.cc
src/node/inet-socket-address.cc
src/node/inet-socket-address.h
src/node/socket.h
--- a/src/internet-node/udp-socket.cc	Mon Jul 30 13:29:36 2007 +0200
+++ b/src/internet-node/udp-socket.cc	Mon Jul 30 13:55:28 2007 +0200
@@ -91,6 +91,10 @@
 int 
 UdpSocket::Bind (const Address &address)
 {
+  if (!InetSocketAddress::IsMatchingType (address))
+    {
+      return ERROR_INVAL;
+    }
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
   uint16_t port = transport.GetPort ();
--- a/src/node/inet-socket-address.cc	Mon Jul 30 13:29:36 2007 +0200
+++ b/src/node/inet-socket-address.cc	Mon Jul 30 13:55:28 2007 +0200
@@ -45,6 +45,12 @@
   m_ipv4 = address;
 }
 
+bool 
+InetSocketAddress::IsMatchingType (const Address &address)
+{
+  return address.CheckCompatible (GetType (), 6);
+}
+
 Address 
 InetSocketAddress::ConvertTo (void) const
 {
--- a/src/node/inet-socket-address.h	Mon Jul 30 13:29:36 2007 +0200
+++ b/src/node/inet-socket-address.h	Mon Jul 30 13:55:28 2007 +0200
@@ -64,6 +64,8 @@
    */
   void SetIpv4 (Ipv4Address address);
 
+  static bool IsMatchingType (const Address &address);
+
   /**
    * \returns an Address instance which represents this
    * InetSocketAddress instance.
--- a/src/node/socket.h	Mon Jul 30 13:29:36 2007 +0200
+++ b/src/node/socket.h	Mon Jul 30 13:55:28 2007 +0200
@@ -52,6 +52,7 @@
     ERROR_AGAIN,
     ERROR_SHUTDOWN,
     ERROR_OPNOTSUPP,
+    ERROR_INVAL,
     SOCKET_ERRNO_LAST
   };