mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-26 02:20:54 +00:00
Merge with develop
This commit is contained in:
parent
e29d08861d
commit
587804cab7
3 changed files with 62 additions and 45 deletions
|
@ -144,7 +144,7 @@ public:
|
||||||
bool is127001 () const;
|
bool is127001 () const;
|
||||||
|
|
||||||
/// Returns true if this CInetAddress is a loop back address
|
/// 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
|
/// Creates a CInetAddress object with local host address, port=0
|
||||||
static CInetAddress localHost();
|
static CInetAddress localHost();
|
||||||
|
|
|
@ -700,13 +700,6 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
||||||
throw ESocket( "Unable to get local hostname" );
|
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
|
// 2. Get address list
|
||||||
vector<CInetAddress> vect;
|
vector<CInetAddress> vect;
|
||||||
|
|
||||||
|
@ -721,21 +714,32 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
||||||
if (status)
|
if (status)
|
||||||
{
|
{
|
||||||
// will come here if the local hostname (/etc/hostname in Linux) is not the real name
|
// 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;
|
struct addrinfo *p = res;
|
||||||
|
|
||||||
|
// for loopback ipv4
|
||||||
|
bool IPv4LoopbackAdded = false;
|
||||||
|
|
||||||
|
// for loopback ipv6
|
||||||
|
bool IPv6LoopbackAdded = false;
|
||||||
|
|
||||||
// process all addresses
|
// process all addresses
|
||||||
while (p != NULL)
|
while (p != NULL)
|
||||||
{
|
{
|
||||||
// check address family
|
// check address family
|
||||||
if (p->ai_family == AF_INET){ // ipv4
|
if (p->ai_family == AF_INET)
|
||||||
|
{
|
||||||
// loopback ipv4
|
// loopback ipv4
|
||||||
if(!psin_addrIPv4){ // add loopback address only once
|
if (!IPv4LoopbackAdded)
|
||||||
struct in_addr *psin_addrIPv4 = new in_addr;
|
{
|
||||||
psin_addrIPv4->s_addr = htonl(INADDR_LOOPBACK);
|
// add loopback address only once
|
||||||
vect.push_back(CInetAddress(psin_addrIPv4, localhost));
|
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;
|
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 ) );
|
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
|
// loopback ipv6
|
||||||
if(!psin_addrIPv6){ // add loopback address only once
|
if (!IPv6LoopbackAdded)
|
||||||
struct in6_addr aLoopback6 = IN6ADDR_LOOPBACK_INIT;
|
{
|
||||||
psin_addrIPv6 = &aLoopback6;
|
// add loopback address only once
|
||||||
vect.push_back(CInetAddress(psin_addrIPv6, localhost));
|
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;
|
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
|
||||||
|
@ -765,7 +773,7 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
|
||||||
|
|
||||||
if(vect.empty())
|
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;
|
return vect;
|
||||||
|
@ -776,14 +784,14 @@ bool CInetAddress::is127001 () const
|
||||||
return (internalIPAddress () == htonl(0x7F000001));
|
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) ||
|
return (sIPAddress.compare("::") == 0) ||
|
||||||
(strcmp(sIPAddress, "::1") == 0) ||
|
(sIPAddress.compare("::1") == 0) ||
|
||||||
(strcmp(sIPAddress, "127.0.0.1") == 0) ||
|
(sIPAddress.compare("127.0.0.1") == 0) ||
|
||||||
(strcmp(sIPAddress, "0:0:0:0:0: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;
|
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++)
|
for (j = 0; j < laddr.size (); j++)
|
||||||
{
|
{
|
||||||
if (laddr[j].internalNetAddress () == addr[i].internalNetAddress ())
|
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 (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 ());
|
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++)
|
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
|
// we found one at last, use this one
|
||||||
//nldebug ("HNETL5: Ok, we found a valid connectionid, use %hu", (uint16)connectionId);
|
//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
|
_IdCnx[sid.get()].NetworkConnectionAssociations[nid] = connectionId; // we set the preferred networkConnectionAssociation
|
||||||
} else {
|
}
|
||||||
if(nid == 0xFF){
|
else
|
||||||
|
{
|
||||||
|
if (nid == 0xFF)
|
||||||
|
{
|
||||||
_IdCnx[sid.get()].DefaultNetwork = connectionId;
|
_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 ());
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1789,7 +1798,7 @@ bool CUnifiedNetwork::isServiceLocal (TServiceId sid)
|
||||||
{
|
{
|
||||||
for (uint j = 0; j < _IdCnx[sid.get()].ExtAddress.size(); j++)
|
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;
|
return true;
|
||||||
|
|
||||||
if (_IdCnx[sid.get()].ExtAddress[j].internalIPAddress () == laddr[i].internalIPAddress ())
|
if (_IdCnx[sid.get()].ExtAddress[j].internalIPAddress () == laddr[i].internalIPAddress ())
|
||||||
|
|
Loading…
Reference in a new issue