From 01129d02b3863f92c0f94b29e9600153b743f967 Mon Sep 17 00:00:00 2001
From: Adam Ierymenko <adam.ierymenko@gmail.com>
Date: Wed, 28 Sep 2016 13:45:25 -0700
Subject: [PATCH] hashCode() for InetAddress

---
 node/InetAddress.hpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp
index 2cd4dbd3d..6f070fbf5 100644
--- a/node/InetAddress.hpp
+++ b/node/InetAddress.hpp
@@ -414,6 +414,25 @@ struct InetAddress : public sockaddr_storage
 		return false;
 	}
 
+	inline unsigned long hashCode() const
+	{
+		if (ss_family == AF_INET) {
+			return ((unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr + (unsigned long)reinterpret_cast<const struct sockaddr_in *>(this)->sin_port);
+		} else if (ss_family == AF_INET6) {
+			unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
+			const uint8_t *a = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
+			for(long i=0;i<16;++i)
+				reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
+			return tmp;
+		} else {
+			unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
+			const uint8_t *a = reinterpret_cast<const uint8_t *>(this);
+			for(long i=0;i<sizeof(InetAddress);++i)
+				reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
+			return tmp;
+		}
+	}
+
 	/**
 	 * Set to null/zero
 	 */