diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index 020076cb5..bc83c942c 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -91,6 +91,10 @@ UdpSocket::Bind (void) 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 (); diff --git a/src/node/inet-socket-address.cc b/src/node/inet-socket-address.cc index b8d0e10cf..232e9215f 100644 --- a/src/node/inet-socket-address.cc +++ b/src/node/inet-socket-address.cc @@ -45,6 +45,12 @@ InetSocketAddress::SetIpv4 (Ipv4Address address) m_ipv4 = address; } +bool +InetSocketAddress::IsMatchingType (const Address &address) +{ + return address.CheckCompatible (GetType (), 6); +} + Address InetSocketAddress::ConvertTo (void) const { diff --git a/src/node/inet-socket-address.h b/src/node/inet-socket-address.h index 35fe52863..bb91d0ff5 100644 --- a/src/node/inet-socket-address.h +++ b/src/node/inet-socket-address.h @@ -64,6 +64,8 @@ public: */ void SetIpv4 (Ipv4Address address); + static bool IsMatchingType (const Address &address); + /** * \returns an Address instance which represents this * InetSocketAddress instance. diff --git a/src/node/socket.h b/src/node/socket.h index 3cba7fd59..547ed4320 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -52,6 +52,7 @@ public: ERROR_AGAIN, ERROR_SHUTDOWN, ERROR_OPNOTSUPP, + ERROR_INVAL, SOCKET_ERRNO_LAST };