Merge with develop
--HG-- branch : compatibility-develop
This commit is contained in:
commit
e42d3a3f74
3 changed files with 62 additions and 45 deletions
|
@ -144,7 +144,7 @@ public:
|
|||
bool is127001 () const;
|
||||
|
||||
/// Returns true if this CInetAddress is a loop back address
|
||||
bool CInetAddress::isloopbackIPAddress () const;
|
||||
bool isLoopbackIPAddress () const;
|
||||
|
||||
/// Creates a CInetAddress object with local host address, port=0
|
||||
static CInetAddress localHost();
|
||||
|
|
|
@ -92,18 +92,18 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
|||
|
||||
BOOLEAN IN6_IS_ADDR_UNSPECIFIED(CONST IN6_ADDR *a)
|
||||
{
|
||||
//
|
||||
// We can't use the in6addr_any variable, since that would
|
||||
// require existing callers to link with a specific library.
|
||||
//
|
||||
return (BOOLEAN)((a->s6_words[0] == 0) &&
|
||||
(a->s6_words[1] == 0) &&
|
||||
(a->s6_words[2] == 0) &&
|
||||
(a->s6_words[3] == 0) &&
|
||||
(a->s6_words[4] == 0) &&
|
||||
(a->s6_words[5] == 0) &&
|
||||
(a->s6_words[6] == 0) &&
|
||||
(a->s6_words[7] == 0));
|
||||
//
|
||||
// We can't use the in6addr_any variable, since that would
|
||||
// require existing callers to link with a specific library.
|
||||
//
|
||||
return (BOOLEAN)((a->s6_words[0] == 0) &&
|
||||
(a->s6_words[1] == 0) &&
|
||||
(a->s6_words[2] == 0) &&
|
||||
(a->s6_words[3] == 0) &&
|
||||
(a->s6_words[4] == 0) &&
|
||||
(a->s6_words[5] == 0) &&
|
||||
(a->s6_words[6] == 0) &&
|
||||
(a->s6_words[7] == 0));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -700,13 +700,6 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
|||
throw ESocket( "Unable to get local hostname" );
|
||||
}
|
||||
|
||||
// for loopback ipv4
|
||||
struct in_addr *psin_addrIPv4 = NULL;
|
||||
|
||||
// for loopback ipv6
|
||||
struct in6_addr *psin_addrIPv6 = NULL;
|
||||
|
||||
|
||||
// 2. Get address list
|
||||
vector<CInetAddress> vect;
|
||||
|
||||
|
@ -721,21 +714,32 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
|||
if (status)
|
||||
{
|
||||
// will come here if the local hostname (/etc/hostname in Linux) is not the real name
|
||||
throw ESocket( (string("Hostname resolution failed for ")+string(localhost)).c_str() );
|
||||
throw ESocket( toString("Hostname resolution failed for %s", localhost).c_str() );
|
||||
}
|
||||
|
||||
struct addrinfo *p = res;
|
||||
|
||||
// for loopback ipv4
|
||||
bool IPv4LoopbackAdded = false;
|
||||
|
||||
// for loopback ipv6
|
||||
bool IPv6LoopbackAdded = false;
|
||||
|
||||
// process all addresses
|
||||
while (p != NULL)
|
||||
{
|
||||
// check address family
|
||||
if (p->ai_family == AF_INET){ // ipv4
|
||||
if (p->ai_family == AF_INET)
|
||||
{
|
||||
// loopback ipv4
|
||||
if(!psin_addrIPv4){ // add loopback address only once
|
||||
struct in_addr *psin_addrIPv4 = new in_addr;
|
||||
psin_addrIPv4->s_addr = htonl(INADDR_LOOPBACK);
|
||||
vect.push_back(CInetAddress(psin_addrIPv4, localhost));
|
||||
if (!IPv4LoopbackAdded)
|
||||
{
|
||||
// add loopback address only once
|
||||
struct in_addr psin_addrIPv4;
|
||||
psin_addrIPv4.s_addr = htonl(INADDR_LOOPBACK);
|
||||
vect.push_back(CInetAddress(&psin_addrIPv4, localhost));
|
||||
|
||||
IPv4LoopbackAdded = true;
|
||||
}
|
||||
|
||||
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
|
||||
|
@ -743,12 +747,16 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
|||
vect.push_back( CInetAddress( &ipv4->sin_addr, localhost ) );
|
||||
|
||||
}
|
||||
else if (p->ai_family == AF_INET6){ // ipv6
|
||||
else if (p->ai_family == AF_INET6)
|
||||
{
|
||||
// loopback ipv6
|
||||
if(!psin_addrIPv6){ // add loopback address only once
|
||||
struct in6_addr aLoopback6 = IN6ADDR_LOOPBACK_INIT;
|
||||
psin_addrIPv6 = &aLoopback6;
|
||||
vect.push_back(CInetAddress(psin_addrIPv6, localhost));
|
||||
if (!IPv6LoopbackAdded)
|
||||
{
|
||||
// add loopback address only once
|
||||
struct in6_addr psin_addrIPv6 = IN6ADDR_LOOPBACK_INIT;
|
||||
vect.push_back(CInetAddress(&psin_addrIPv6, localhost));
|
||||
|
||||
IPv6LoopbackAdded = true;
|
||||
}
|
||||
|
||||
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
|
||||
|
@ -765,7 +773,7 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
|||
|
||||
if(vect.empty())
|
||||
{
|
||||
throw ESocket( (string("No network card detected for ")+string(localhost)).c_str() );
|
||||
throw ESocket(toString("No network card detected for %s", localhost).c_str() );
|
||||
}
|
||||
|
||||
return vect;
|
||||
|
@ -776,14 +784,14 @@ bool CInetAddress::is127001 () const
|
|||
return (internalIPAddress () == htonl(0x7F000001));
|
||||
}
|
||||
|
||||
bool CInetAddress::isloopbackIPAddress () const
|
||||
bool CInetAddress::isLoopbackIPAddress () const
|
||||
{
|
||||
const char *sIPAddress = ipAddress().c_str();
|
||||
std::string sIPAddress = ipAddress();
|
||||
|
||||
return (strcmp(sIPAddress, "::") == 0) ||
|
||||
(strcmp(sIPAddress, "::1") == 0) ||
|
||||
(strcmp(sIPAddress, "127.0.0.1") == 0) ||
|
||||
(strcmp(sIPAddress, "0:0:0:0:0:0:0:1") == 0);
|
||||
return (sIPAddress.compare("::") == 0) ||
|
||||
(sIPAddress.compare("::1") == 0) ||
|
||||
(sIPAddress.compare("127.0.0.1") == 0) ||
|
||||
(sIPAddress.compare("0:0:0:0:0:0:0:1") == 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -831,8 +831,9 @@ void CUnifiedNetwork::addService(const string &name, const vector<CInetAddress>
|
|||
|
||||
uint j = 0;
|
||||
|
||||
if (!addr[i].isloopbackIPAddress ()){ // it 's loopback ip address, it s ok
|
||||
|
||||
if (!addr[i].isLoopbackIPAddress())
|
||||
{
|
||||
// it's loopback ip address, it's ok
|
||||
for (j = 0; j < laddr.size (); j++)
|
||||
{
|
||||
if (laddr[j].internalNetAddress () == addr[i].internalNetAddress ())
|
||||
|
@ -1293,8 +1294,11 @@ uint8 CUnifiedNetwork::findConnectionId (TServiceId sid, uint8 nid)
|
|||
if (connectionId >= _IdCnx[sid.get()].Connections.size() || !_IdCnx[sid.get()].Connections[connectionId].valid() || !_IdCnx[sid.get()].Connections[connectionId].CbNetBase->connected())
|
||||
{
|
||||
|
||||
if(nid != 0xFF) // not a default network. There's a problem with the selected connectionID, so try to find a valid one
|
||||
if (nid != 0xFF)
|
||||
{
|
||||
// not a default network. There's a problem with the selected connectionID, so try to find a valid one
|
||||
nlwarning ("HNETL5: Can't find selected connection id %hu to send message to %s because connection is not valid or connected, find a valid connection id", (uint16)connectionId, _IdCnx[sid.get()].ServiceName.c_str ());
|
||||
}
|
||||
|
||||
for (connectionId = 0; connectionId < _IdCnx[sid.get()].Connections.size(); connectionId++)
|
||||
{
|
||||
|
@ -1302,13 +1306,18 @@ uint8 CUnifiedNetwork::findConnectionId (TServiceId sid, uint8 nid)
|
|||
{
|
||||
// we found one at last, use this one
|
||||
//nldebug ("HNETL5: Ok, we found a valid connectionid, use %hu", (uint16)connectionId);
|
||||
if(nid < _IdCnx[sid.get()].NetworkConnectionAssociations.size()){
|
||||
if (nid < _IdCnx[sid.get()].NetworkConnectionAssociations.size())
|
||||
{
|
||||
_IdCnx[sid.get()].NetworkConnectionAssociations[nid] = connectionId; // we set the preferred networkConnectionAssociation
|
||||
} else {
|
||||
if(nid == 0xFF){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nid == 0xFF)
|
||||
{
|
||||
_IdCnx[sid.get()].DefaultNetwork = connectionId;
|
||||
}
|
||||
}
|
||||
|
||||
nlwarning ("HNETL5: selected connection id %hu from network %hu to send message to %s", (uint16)connectionId, (uint16)nid, _IdCnx[sid.get()].ServiceName.c_str ());
|
||||
break;
|
||||
}
|
||||
|
@ -1789,7 +1798,7 @@ bool CUnifiedNetwork::isServiceLocal (TServiceId sid)
|
|||
{
|
||||
for (uint j = 0; j < _IdCnx[sid.get()].ExtAddress.size(); j++)
|
||||
{
|
||||
if (_IdCnx[sid.get()].ExtAddress[j].isloopbackIPAddress ())
|
||||
if (_IdCnx[sid.get()].ExtAddress[j].isLoopbackIPAddress ())
|
||||
return true;
|
||||
|
||||
if (_IdCnx[sid.get()].ExtAddress[j].internalIPAddress () == laddr[i].internalIPAddress ())
|
||||
|
|
Loading…
Reference in a new issue