summaryrefslogtreecommitdiff
path: root/node/InetAddress.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'node/InetAddress.hpp')
-rw-r--r--node/InetAddress.hpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp
index e03deb71..b97e2ca6 100644
--- a/node/InetAddress.hpp
+++ b/node/InetAddress.hpp
@@ -356,7 +356,6 @@ struct InetAddress : public sockaddr_storage
* @return pointer to raw address bytes or NULL if not available
*/
inline const void *rawIpData() const
- throw()
{
switch(ss_family) {
case AF_INET: return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
@@ -366,6 +365,25 @@ struct InetAddress : public sockaddr_storage
}
/**
+ * @return InetAddress containing only the IP portion of this address and a zero port, or NULL if not IPv4 or IPv6
+ */
+ inline InetAddress ipOnly() const
+ {
+ InetAddress r;
+ switch(ss_family) {
+ case AF_INET:
+ r.ss_family = AF_INET;
+ reinterpret_cast<struct sockaddr_in *>(&r)->sin_addr.s_addr = reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr;
+ break;
+ case AF_INET6:
+ r.ss_family = AF_INET6;
+ memcpy(reinterpret_cast<struct sockaddr_in6 *>(&r)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,16);
+ break;
+ }
+ return r;
+ }
+
+ /**
* Performs an IP-only comparison or, if that is impossible, a memcmp()
*
* @param a InetAddress to compare again