From 892598d6eb09879b659b8f0f4f900ab11f740f35 Mon Sep 17 00:00:00 2001 From: joss17 Date: Mon, 14 Dec 2009 10:34:57 +0000 Subject: [PATCH] change the address selection of udp connection git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1869 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 6115f3e7e..cb3976ad8 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -2254,7 +2254,14 @@ bool p3ConnectMgr::retryConnectTCP(std::string id) } } - if (!found && !isSameSubnet(&ipListIt->ipAddr.sin_addr, &ownState.currentlocaladdr.sin_addr)) {//add only if in different subnet + /* Try not to add internal address like 192.168.x.x + * check that the (addr1 & 255.255.0.0) == (addr2 & 255.255.0.0) + */ + unsigned long a1 = ntohl(ipListIt->ipAddr.sin_addr.s_addr); + unsigned long a2 = ntohl(ownState.currentlocaladdr.sin_addr.s_addr); + bool isLocal = ((a1 & 0xffff0000) == (a2 & 0xffff0000)); + + if (!found && !isLocal && !isSameSubnet(&ipListIt->ipAddr.sin_addr, &ownState.currentlocaladdr.sin_addr)) {//add only if in different subnet #ifdef CONN_DEBUG std::cerr << "Adding udp connection attempt." << std::endl; #endif