Sorry 0002 was the wrong one here it goes the complete patch

On Saturday, January 10, 2015 06:25:51 PM Gioacchino Mazzurco wrote:
> Hi!
>
> Here they go two more patches, first one remove a bunch of useless return
> statement, this doesn't change semantic feel free to not merge it
>
> In the second one I have remove the sameLan/sameSubnet logic form the code,
> it is based on flawed assumptions than subnet are all /24, that is not the
> case on modern internet, moreover you cannot know if two ips are in the
> same subnet just from ip, you need to know underlaying network topology
> that RS doesn't know, this is the first real patch on the ipv6 porting
> series, i am sorry i'll have do delete a lot of code as there is a lot of
> ipv6/ipv4 specific things that shouldn't be, for example case
> AF_INET/AF_INET6 should be avoided as much as possible, see you soon, i am
> also on RS develop lobby if you wanna have a chat, as a side effect this
> patch should fix problems on computer with multiple network adapter or
> virtual machines
>
> You can see complete commits on my git repo
> https://github.com/G10h4ck/retroshare
>
> 0004 and 0005 are mainly statick checks fixes
From 9e2d0f478274c99c27bf3c8e20c2ca2321715626 Mon Sep 17 00:00:00 2001
From: Gioacchino Mazzurco <g...@eigenlab.org>
Date: Sat, 10 Jan 2015 18:13:03 +0100
Subject: [PATCH 2/2] Removed flawed logic samenet/samesubnet you cannot
 determine if two ip are in the same subnet just from ips the internet is not
 just a bunch of /24

---
 libretroshare/src/pqi/p3linkmgr.cc        |  81 ++------
 libretroshare/src/pqi/p3linkmgr.h         |   6 +-
 libretroshare/src/pqi/pqinetwork.cc       | 308 ------------------------------
 libretroshare/src/pqi/pqinetwork.h        |   5 +-
 libretroshare/src/pqi/pqissl.cc           |  13 +-
 libretroshare/src/pqi/pqissl.h            |   2 -
 libretroshare/src/tests/pqi/TestNotes.txt |   2 -
 libretroshare/src/tests/pqi/net_test.cc   |   5 -
 libretroshare/src/tests/pqi/net_test1.cc  |  59 ------
 libretroshare/src/util/rsnet.h            |   2 -
 libretroshare/src/util/rsnet_ss.cc        | 112 -----------
 11 files changed, 27 insertions(+), 568 deletions(-)

diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc
index 69110ee..57f2599 100644
--- a/libretroshare/src/pqi/p3linkmgr.cc
+++ b/libretroshare/src/pqi/p3linkmgr.cc
@@ -1683,7 +1683,7 @@ bool   p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id)

 #define MAX_TCP_ADDR_AGE	(3600 * 24 * 14) // two weeks in seconds.

-bool  p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_storage &addr, time_t age)
+bool p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_storage &addr, time_t age)
 {
 #ifdef LINKMGR_DEBUG
 	std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr(";
@@ -1693,9 +1693,9 @@ bool  p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_storage &ad
 #endif

 	/*
-	 * if it is old - quick rejection
+	 * if it is old - quick rejection
 	 */
-	if (age > MAX_TCP_ADDR_AGE)
+	if ( age > MAX_TCP_ADDR_AGE )
 	{
 #ifdef LINKMGR_DEBUG
 		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - TOO OLD";
@@ -1704,13 +1704,8 @@ bool  p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_storage &ad
 		return false;
 	}

-	bool isValid = sockaddr_storage_isValidNet(addr);
-	bool isLoopback = sockaddr_storage_isLoopbackNet(addr);
-	//	bool isPrivate = sockaddr_storage_isPrivateNet(addr);
-	bool isExternal = sockaddr_storage_isExternalNet(addr);
-
 	/* if invalid - quick rejection */
-	if (!isValid)
+	if ( ! sockaddr_storage_isValidNet(addr) )
 	{
 #ifdef LINKMGR_DEBUG
 		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - INVALID";
@@ -1719,77 +1714,41 @@ bool  p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_storage &ad
 		return false;
 	}

-	/* if it is on the ban list - ignore */
-	/* checks - is it the dreaded 1.0.0.0 */
-
-	std::list<struct sockaddr_storage>::const_iterator it;
-	for(it = mBannedIpList.begin(); it != mBannedIpList.end(); ++it)
-	{
-		if (sockaddr_storage_sameip(*it, addr))
-		{
-#ifdef LINKMGR_DEBUG
-			std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - ON BANNED IPLIST";
-			std::cerr << std::endl;
-#endif
-			return false;
-		}
-	}
-
-
-	/* if it is an external address, we'll accept it.
-	 * - even it is meant to be a local address.
-	 */
-	if (isExternal)
+	/* if loopback, then okay - probably proxy connection (or local testing). */
+	if ( sockaddr_storage_isLoopbackNet(addr) )
 	{
 #ifdef LINKMGR_DEBUG
-		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - EXTERNAL";
+		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - LOOPBACK";
 		std::cerr << std::endl;
 #endif
 		return true;
 	}

-
-	/* if loopback, then okay - probably proxy connection (or local testing).
-	 */
-	if (isLoopback)
+	if ( sockaddr_storage_isPrivateNet(addr) )
 	{
 #ifdef LINKMGR_DEBUG
-		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - LOOPBACK";
+		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - PRIVATE";
 		std::cerr << std::endl;
 #endif
 		return true;
 	}

-
-	/* get here, it is private or loopback
-	 *  - can only connect to these addresses if we are on the same subnet.
-	    - check net against our local address.
-	 */
-
-#ifdef LINKMGR_DEBUG
-	std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() Checking sameNet against: ";
-	std::cerr << sockaddr_storage_iptostring(mLocalAddress);
-	std::cerr << ")";
-	std::cerr << std::endl;
-#endif
-
-	if (sockaddr_storage_samenet(mLocalAddress, addr))
+	/* if it is on the ban list  reject it */
+	/* is it the dreaded 1.0.0.0 */
+	std::list<struct sockaddr_storage>::const_iterator it;
+	for(it = mBannedIpList.begin(); it != mBannedIpList.end(); ++it)
 	{
+		if (sockaddr_storage_sameip(*it, addr))
+		{
 #ifdef LINKMGR_DEBUG
-		std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET";
-		std::cerr << std::endl;
+			std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - ON BANNED IPLIST";
+			std::cerr << std::endl;
 #endif
-		return true;
+			return false;
+		}
 	}

-#ifdef LINKMGR_DEBUG
-	std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - PRIVATE & !sameNET";
-	std::cerr << std::endl;
-#endif
-
-	/* else it fails */
-	return false;
-
+	return true;
 }


diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h
index 95bc5a2..e3c439a 100644
--- a/libretroshare/src/pqi/p3linkmgr.h
+++ b/libretroshare/src/pqi/p3linkmgr.h
@@ -336,7 +336,11 @@ private:
 	std::list<RsPeerGroupItem *> groupList;
 	uint32_t lastGroupId;

-	/* relatively static list of banned ip addresses */
+	/* Relatively static list of banned ip addresses
+	 * TODO: We should use a real bad ip lists, and an appropriated
+	 * data structure to access them, list access is linear time while
+	 * constant or at least logaritmic is possible with hashtable or tree
+	 */
 	std::list<struct sockaddr_storage> mBannedIpList;
 };

diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc
index 54a8a72..83007d1 100644
--- a/libretroshare/src/pqi/pqinetwork.cc
+++ b/libretroshare/src/pqi/pqinetwork.cc
@@ -757,311 +757,3 @@ bool getLocalInterfaces(struct sockaddr_storage &existAddr, std::list<struct soc
 	}
 	return false;
 }
-
-
-
-
-bool    sameNet(const struct in_addr *addr, const struct in_addr *addr2)
-{
-#ifdef NET_DEBUG
-	std::cerr << "sameNet: " << rs_inet_ntoa(*addr);
-	std::cerr << " VS " << rs_inet_ntoa(*addr2);
-	std::cerr << std::endl;
-#endif
-	struct in_addr addrnet, addrnet2;
-
-	addrnet.s_addr = inet_netof(*addr);
-	addrnet2.s_addr = inet_netof(*addr2);
-
-#ifdef NET_DEBUG
-	std::cerr << " (" << rs_inet_ntoa(addrnet);
-	std::cerr << " =?= " << rs_inet_ntoa(addrnet2);
-	std::cerr << ")" << std::endl;
-#endif
-
-	in_addr_t address1 = htonl(addr->s_addr);
-	in_addr_t address2 = htonl(addr2->s_addr);
-
-	// handle case for private net: 172.16.0.0/12
-	if (address1>>20 == (172<<4 | 16>>4))
-	{
-		return (address1>>20 == address2>>20);
-	}
-
-	return (inet_netof(*addr) == inet_netof(*addr2));
-}
-
-
-bool 	isSameSubnet(struct in_addr *addr1, struct in_addr *addr2)
-{
-	/*
-	 * check that the (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
-	 */
-
-	unsigned long a1 = ntohl(addr1->s_addr);
-	unsigned long a2 = ntohl(addr2->s_addr);
-
-	return ((a1 & 0xffffff00) == (a2 & 0xffffff00));
-}
-
-/* This just might be portable!!! will see!!!
- * Unfortunately this is usable on winXP+, determined by: (_WIN32_WINNT >= 0x0501)
- * but not older platforms.... which must use gethostbyname.
- *
- * include it for now.....
- */
-
-bool LookupDNSAddr(std::string name, struct sockaddr_in &addr)
-{
-
-#if 1
-	char service[100];
-	struct addrinfo hints_st;
-	struct addrinfo *hints = &hints_st;
-	struct addrinfo *res;
-
-	hints -> ai_flags = 0; // (cygwin don;t like these) AI_ADDRCONFIG | AI_NUMERICSERV;
-	hints -> ai_family = AF_INET;
-	hints -> ai_socktype = 0;
-	hints -> ai_protocol = 0;
-	hints -> ai_addrlen = 0;
-	hints -> ai_addr = NULL;
-	hints -> ai_canonname = NULL;
-	hints -> ai_next = NULL;
-
-	/* get the port number */
-	sprintf(service, "%d", ntohs(addr.sin_port));
-
-	/* set it to IPV4 */
-#ifdef NET_DEBUG
-	std::cerr << "LookupDNSAddr() name: " << name << " service: " << service << std::endl;
-#endif
-
- 	int err = 0;
-	if (0 != (err = getaddrinfo(name.c_str(), service, hints, &res)))
-	{
-#ifdef NET_DEBUG
-		std::cerr << "LookupDNSAddr() getaddrinfo failed!" << std::endl;
-		std::cerr << "Error: " << gai_strerror(err)  << std::endl;
-#endif
-		return false;
-	}
-
-	if ((res) && (res->ai_family == AF_INET))
-	{
-		addr = *((struct sockaddr_in *) res->ai_addr);
-		freeaddrinfo(res);
-
-#ifdef NET_DEBUG
-		std::cerr << "LookupDNSAddr() getaddrinfo found address" << std::endl;
-		std::cerr << "addr: " << rs_inet_ntoa(addr.sin_addr) << std::endl;
-		std::cerr << "port: " << ntohs(addr.sin_port) << std::endl;
-#endif
-		return true;
-	}
-
-#ifdef NET_DEBUG
-	std::cerr << "getaddrinfo failed - no address" << std::endl;
-#endif
-
-#endif
-#ifdef NET_DEBUG
-	//std::cerr << "getaddrinfo disabled" << std::endl;
-#endif
-	return false;
-}
-
-/*************************************************************
- * Socket Library Wrapper Functions
- * to get over the crapness of the windows.
- *
- */
-
-int unix_close(int fd)
-{
-	int ret;
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifndef WINDOWS_SYS // ie UNIX
-	ret = close(fd);
-#else
-
-#ifdef NET_DEBUG
-	std::cerr << "unix_close()" << std::endl;
-#endif
-	ret = closesocket(fd);
-	/* translate error */
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
-	return ret;
-}
-
-int unix_socket(int /*domain*/, int /*type*/, int /*protocol*/)
-{
-	int osock = socket(PF_INET, SOCK_STREAM, 0);
-
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifdef WINDOWS_SYS  // WINDOWS
-
-#ifdef NET_DEBUG
-	std::cerr << "unix_socket()" << std::endl;
-#endif
-
-	if ((unsigned) osock == INVALID_SOCKET)
-	{
-		// Invalidate socket Unix style.
-		osock = -1;
-		errno = WinToUnixError(WSAGetLastError());
-	}
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
-	return osock;
-}
-
-
-int unix_fcntl_nonblock(int fd)
-{
-        int ret;
-
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifndef WINDOWS_SYS // ie UNIX
-	ret = fcntl(fd, F_SETFL, O_NONBLOCK);
-
-#ifdef NET_DEBUG
-	std::cerr << "unix_fcntl_nonblock():" << ret << " errno:" << errno << std::endl;
-#endif
-
-#else
-	unsigned long int on = 1;
-	ret = ioctlsocket(fd, FIONBIO, &on);
-
-#ifdef NET_DEBUG
-	std::cerr << "unix_fcntl_nonblock()" << std::endl;
-#endif
-	if (ret != 0)
-	{
-		/* store unix-style error
-		 */
-		ret = -1;
-		errno = WinToUnixError(WSAGetLastError());
-	}
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
-	return ret;
-}
-
-
-int unix_connect(int fd, const struct sockaddr *serv_addr, socklen_t socklen)
-{
-#ifdef NET_DEBUG
-	std::cerr << "unix_connect()";
-	std::cerr << std::endl;
-#endif
-
-	const struct sockaddr_storage *ss_addr = (struct sockaddr_storage *) serv_addr;
-	socklen_t len = socklen;
-
-	switch (ss_addr->ss_family)
-	{
-		case AF_INET:
-			len = sizeof(struct sockaddr_in);
-			break;
-		case AF_INET6:
-			len = sizeof(struct sockaddr_in6);
-			break;
-	}
-
-	if (len > socklen)
-	{
-		std::cerr << "unix_connect() ERROR len > socklen";
-		std::cerr << std::endl;
-
-		len = socklen;
-		//return EINVAL;
-	}
-
-	int ret = connect(fd, serv_addr, len);
-
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifdef WINDOWS_SYS // WINDOWS
-
-#ifdef NET_DEBUG
-	std::cerr << "unix_connect()" << std::endl;
-#endif
-	if (ret != 0)
-	{
-		errno = WinToUnixError(WSAGetLastError());
-		ret = -1;
-	}
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
-	return ret;
-}
-
-
-int unix_getsockopt_error(int sockfd, int *err)
-{
-	int ret;
-	*err = 1;
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifndef WINDOWS_SYS // ie UNIX
-	socklen_t optlen = 4;
-	ret=getsockopt(sockfd, SOL_SOCKET, SO_ERROR, err, &optlen);
-#else // WINDOWS_SYS
-	int optlen = 4;
-	ret=getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char *) err, &optlen);
-	/* translate */
-#ifdef NET_DEBUG
-	std::cerr << "unix_getsockopt_error() returned: " << (int) err << std::endl;
-#endif
-	if (*err != 0)
-	{
-		*err = WinToUnixError(*err);
-	}
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
-	return ret;
-}
-
-/******************* WINDOWS SPECIFIC PART ******************/
-#ifdef WINDOWS_SYS // ie WINDOWS.
-
-int	WinToUnixError(int error)
-{
-#ifdef NET_DEBUG
-	std::cerr << "WinToUnixError(" << error << ")" << std::endl;
-#endif
-	switch(error)
-	{
-		case WSAEINPROGRESS:
-			return EINPROGRESS;
-			break;
-		case WSAEWOULDBLOCK:
-			return EINPROGRESS;
-			break;
-		case WSAENETUNREACH:
-			return ENETUNREACH;
-			break;
-		case WSAETIMEDOUT:
-			return ETIMEDOUT;
-			break;
-		case WSAEHOSTDOWN:
-			return EHOSTDOWN;
-			break;
-		case WSAECONNREFUSED:
-			return ECONNREFUSED;
-			break;
-		case WSAECONNRESET:
-			return ECONNRESET;
-			break;
-		default:
-#ifdef NET_DEBUG
-			std::cerr << "WinToUnixError(" << error << ") Code Unknown!";
-			std::cerr << std::endl;
-#endif
-			break;
-	}
-	return ECONNREFUSED; /* sensible default? */
-}
-
-#endif
-/******************* WINDOWS SPECIFIC PART ******************/
diff --git a/libretroshare/src/pqi/pqinetwork.h b/libretroshare/src/pqi/pqinetwork.h
index f8118f7..0ba8d26 100644
--- a/libretroshare/src/pqi/pqinetwork.h
+++ b/libretroshare/src/pqi/pqinetwork.h
@@ -97,6 +97,7 @@ extern int errno; /* Define extern errno, to duplicate unix behaviour */
 void showSocketError(std::string &out);

 std::string socket_errorType(int err);
+
 int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );
 int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 );
 int inaddr_cmp(struct sockaddr_in addr1, unsigned long);
@@ -104,10 +105,6 @@ int inaddr_cmp(struct sockaddr_in addr1, unsigned long);
 bool getPreferredInterface(struct sockaddr_storage &existAddr, struct sockaddr_storage &prefAddr); // returns best addr.
 bool getLocalInterfaces(struct sockaddr_storage &existAddr, std::list<struct sockaddr_storage> &addrs); // returns all possible addrs.

-	// checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
-bool    isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
-bool	sameNet(const struct in_addr *addr, const struct in_addr *addr2);
-
 in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.

 bool LookupDNSAddr(std::string name, struct sockaddr_in &addr);
diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc
index da85468..f85c526 100644
--- a/libretroshare/src/pqi/pqissl.cc
+++ b/libretroshare/src/pqi/pqissl.cc
@@ -99,7 +99,7 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3LinkMgr *lm)
 	sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
 	readpkt(NULL), pktlen(0), total_len(0),
 	attempt_ts(0),
-	sameLAN(false), n_read_zero(0), mReadZeroTS(0),
+	n_read_zero(0), mReadZeroTS(0),
 	mConnectDelay(0), mConnectTS(0),
 	mConnectTimeout(0), mTimeoutTS(0)
 {
@@ -251,7 +251,6 @@ int 	pqissl::reset_locked()
 	sockfd = -1;
 	waiting = WAITING_NOT;
 	ssl_connection = NULL;
-	sameLAN = false;
 	n_read_zero = 0;
 	mReadZeroTS = 0;
 	total_len = 0 ;
@@ -1429,22 +1428,12 @@ int	pqissl::accept_locked(SSL *ssl, int fd, const struct sockaddr_storage &forei

 	struct sockaddr_storage localaddr;
 	mLinkMgr->getLocalAddress(localaddr);
-	sameLAN = sockaddr_storage_samesubnet(remote_addr, localaddr);

 	{
 		std::string out = "pqissl::accept() SUCCESSFUL connection to: " + PeerId().toStdString();
 		out += " localaddr: " + sockaddr_storage_iptostring(localaddr);
 		out += " remoteaddr: " + sockaddr_storage_iptostring(remote_addr);

-		if (sameLAN)
-		{
-			out += " SAME LAN";
-		}
-		else
-		{
-			out += " DIFF LANs";
-		}
-
 		rslog(RSL_WARNING, pqisslzone, out);
 	}

diff --git a/libretroshare/src/pqi/pqissl.h b/libretroshare/src/pqi/pqissl.h
index 3f72a05..00b70b2 100644
--- a/libretroshare/src/pqi/pqissl.h
+++ b/libretroshare/src/pqi/pqissl.h
@@ -195,8 +195,6 @@ virtual int net_internal_fcntl_nonblock(int fd);

 	int attempt_ts;

-	bool sameLAN; /* flag use to allow high-speed transfers */
-
 	int n_read_zero; /* a counter to determine if the connection is really dead */
 	time_t mReadZeroTS; /* timestamp of first READ_ZERO occurance */

diff --git a/libretroshare/src/tests/pqi/TestNotes.txt b/libretroshare/src/tests/pqi/TestNotes.txt
index 880eae3..655c9d7 100644
--- a/libretroshare/src/tests/pqi/TestNotes.txt
+++ b/libretroshare/src/tests/pqi/TestNotes.txt
@@ -70,9 +70,7 @@ Description:
 (1) isExternalNet()
 (2) isPrivateNet()
 (3) isLoopbackNet()
-(4) sameNet()
 (5) isValidNet()
-(6) isSameSubnet()
 (7) pqi_inet_netof()

 ------------------------------------------------------------
diff --git a/libretroshare/src/tests/pqi/net_test.cc b/libretroshare/src/tests/pqi/net_test.cc
index 50dd647..0610b40 100644
--- a/libretroshare/src/tests/pqi/net_test.cc
+++ b/libretroshare/src/tests/pqi/net_test.cc
@@ -227,13 +227,8 @@ bool    isExternalNet(struct in_addr *addr); // if Valid & is not Private or Loo
 bool	isPrivateNet(struct in_addr *addr); // if inside 10.0.0.0 or
 						// other then firewalled.
 bool	isLoopbackNet(struct in_addr *addr);
-bool	sameNet(struct in_addr *addr, struct in_addr *addr2);
 bool	isValidNet(struct in_addr *addr);

-	// checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
-bool    isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
-
-
 struct in_addr getPreferredInterface(); // returns best addr.

 in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.
diff --git a/libretroshare/src/tests/pqi/net_test1.cc b/libretroshare/src/tests/pqi/net_test1.cc
index 599bacb..13c7c51 100644
--- a/libretroshare/src/tests/pqi/net_test1.cc
+++ b/libretroshare/src/tests/pqi/net_test1.cc
@@ -53,9 +53,7 @@ const char * invalid_addrstr = "AAA.BBB.256.256";
 int test_isExternalNet();
 int test_isPrivateNet();
 int test_isLoopbackNet();
-int test_sameNet();
 int test_isValidNet();
-int test_isSameSubnet();
 int test_pqi_inet_netof();

 INITTEST();
@@ -67,9 +65,7 @@ int main(int argc, char **argv)
 	test_isExternalNet();
 	test_isPrivateNet();
 	test_isLoopbackNet();
-	test_sameNet();
 	test_isValidNet();
-	test_isSameSubnet();
 	test_pqi_inet_netof();

 	FINALREPORT("net_test1");
@@ -158,42 +154,6 @@ int test_isLoopbackNet()
 	return 1;
 }

-int test_sameNet()
-{
-	struct in_addr localnet1_addr;
-	struct in_addr localnet2_addr;
-	struct in_addr localnet3_addr;
-	struct in_addr localnet4_addr;
-	struct in_addr localnet5_addr;
-	struct in_addr localnet6_addr;
-	struct in_addr localnet7_addr;
-	struct in_addr localnet8_addr;
-	struct in_addr external_addr;
-
-	inet_aton(localnet1_addrstr, &localnet1_addr);
-	inet_aton(localnet2_addrstr, &localnet2_addr);
-	inet_aton(localnet3_addrstr, &localnet3_addr);
-	inet_aton(localnet4_addrstr, &localnet4_addr);
-	inet_aton(localnet5_addrstr, &localnet5_addr);
-	inet_aton(localnet6_addrstr, &localnet6_addr);
-	inet_aton(localnet7_addrstr, &localnet7_addr);
-	inet_aton(localnet8_addrstr, &localnet8_addr);
-	inet_aton(external_addrstr, &external_addr);
-
-	CHECK(sameNet(&localnet1_addr, &localnet5_addr)==true);
-	CHECK(sameNet(&localnet2_addr, &localnet6_addr)==true);
-	CHECK(sameNet(&localnet3_addr, &localnet7_addr)==true);
-	CHECK(sameNet(&localnet4_addr, &localnet8_addr)==true);
-	CHECK(sameNet(&localnet1_addr, &external_addr)=úlse);
-	CHECK(sameNet(&localnet2_addr, &external_addr)=úlse);
-	CHECK(sameNet(&localnet3_addr, &external_addr)=úlse);
-	CHECK(sameNet(&localnet4_addr, &external_addr)=úlse);
-
-	REPORT("sameNet()");
-
-	return 1;
-}
-
 int test_isValidNet()
 {
 	struct in_addr localnet1_addr;
@@ -211,25 +171,6 @@ int test_isValidNet()
 	return 1;
 }

-int test_isSameSubnet()
-{
-	struct in_addr localnet1_addr;
-	struct in_addr classc1_addr;
-	struct in_addr classc2_addr;
-
-	inet_aton(localnet1_addrstr, &localnet1_addr);
-	//random class C addresses
-	inet_aton("197.67.28.93", &classc1_addr);
-	inet_aton("197.67.28.3", &classc2_addr);
-
-	CHECK(isSameSubnet(&localnet1_addr, &classc1_addr)=úlse);
-	CHECK(isSameSubnet(&classc1_addr, &classc2_addr)==true);
-
-	REPORT("isSameSubnet()");
-
-	return 1;
-}
-
 int test_pqi_inet_netof()
 {
 	struct in_addr localnet1_addr;
diff --git a/libretroshare/src/util/rsnet.h b/libretroshare/src/util/rsnet.h
index 5e78026..fa42443 100644
--- a/libretroshare/src/util/rsnet.h
+++ b/libretroshare/src/util/rsnet.h
@@ -102,8 +102,6 @@ bool operator<(const struct sockaddr_storage &a, const struct sockaddr_storage &
 bool sockaddr_storage_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_samefamily(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);

 // string,
 std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr);
diff --git a/libretroshare/src/util/rsnet_ss.cc b/libretroshare/src/util/rsnet_ss.cc
index d07322c..ebfa9fb 100644
--- a/libretroshare/src/util/rsnet_ss.cc
+++ b/libretroshare/src/util/rsnet_ss.cc
@@ -56,15 +56,10 @@ bool sockaddr_storage_ipv6_setport(struct sockaddr_storage &addr, uint16_t port)
 bool sockaddr_storage_ipv4_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_ipv4_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_ipv4_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);

 bool sockaddr_storage_ipv6_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_ipv6_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
 bool sockaddr_storage_ipv6_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_ipv6_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-bool sockaddr_storage_ipv6_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
-

 /********************************* Output     ***********************************/
 std::string sockaddr_storage_ipv4_iptostring(const struct sockaddr_storage &addr);
@@ -362,59 +357,6 @@ bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct s
 }


-bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-#ifdef SS_DEBUG
-	std::cerr << "sockaddr_storage_samenet()";
-	std::cerr << std::endl;
-#endif
-
-	if (!sockaddr_storage_samefamily(addr, addr2))
-		return false;
-
-	switch(addr.ss_family)
-	{
-		case AF_INET:
-			return sockaddr_storage_ipv4_samenet(addr, addr2);
-			break;
-		case AF_INET6:
-			return sockaddr_storage_ipv6_samenet(addr, addr2);
-			break;
-		default:
-			std::cerr << "sockaddr_storage_samenet() INVALID Family - error";
-			std::cerr << std::endl;
-			break;
-	}
-	return false;
-}
-
-bool sockaddr_storage_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-#ifdef SS_DEBUG
-	std::cerr << "sockaddr_storage_samesubnet()";
-	std::cerr << std::endl;
-#endif
-
-	if (!sockaddr_storage_samefamily(addr, addr2))
-		return false;
-
-	switch(addr.ss_family)
-	{
-		case AF_INET:
-			return sockaddr_storage_ipv4_samesubnet(addr, addr2);
-			break;
-		case AF_INET6:
-			return sockaddr_storage_ipv6_samesubnet(addr, addr2);
-			break;
-		default:
-			std::cerr << "sockaddr_storage_samesubnet() INVALID Family - error";
-			std::cerr << std::endl;
-			break;
-	}
-	return false;
-}
-
-
 /********************************* Output     ***********************************/

 std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr)
@@ -784,37 +726,6 @@ bool sockaddr_storage_ipv4_sameip(const struct sockaddr_storage &addr, const str
 }


-bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-	(void) addr;
-	(void) addr2;
-
-#ifdef SS_DEBUG
-	std::cerr << "sockaddr_storage_ipv4_samenet()";
-	std::cerr << std::endl;
-#endif
-
-
-	const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
-	const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
-	return sameNet(&(ptr1->sin_addr),&(ptr2->sin_addr));
-}
-
-bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-	(void) addr;
-	(void) addr2;
-
-#ifdef SS_DEBUG
-	std::cerr << "sockaddr_storage_ipv4_samesubnet() using pqinetwork::isSameSubnet()";
-	std::cerr << std::endl;
-#endif
-
-	const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
-	const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
-	return isSameSubnet((struct in_addr *) &(ptr1->sin_addr),(struct in_addr *) &(ptr2->sin_addr));
-}
-
 // IPV6
 bool sockaddr_storage_ipv6_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
 {
@@ -871,29 +782,6 @@ bool sockaddr_storage_ipv6_sameip(const struct sockaddr_storage &addr, const str
 }


-bool sockaddr_storage_ipv6_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-	(void) addr;
-	(void) addr2;
-
-	std::cerr << "sockaddr_storage_ipv6_samenet() TODO";
-	std::cerr << std::endl;
-
-	return false;
-}
-
-bool sockaddr_storage_ipv6_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
-{
-	(void) addr;
-	(void) addr2;
-
-	std::cerr << "sockaddr_storage_ipv6_samesubnet() TODO";
-	std::cerr << std::endl;
-
-	return false;
-}
-
-
 /********************************* Output     ***********************************/
 std::string sockaddr_storage_ipv4_iptostring(const struct sockaddr_storage &addr)
 {
--
2.0.5

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Retroshare-devel mailing list
Retroshare-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/retroshare-devel

Reply via email to