The following code is in KademliaUDPListener.cpp (aMule 2.1.3), which contains a bug:
...
void CKademliaUDPListener::addContacts( const byte *data, uint32 lenData, uint16 numContacts)
{
CMemFile bio((byte*)data, lenData );
CRoutingZone *routingZone = CKademlia::getRoutingZone();
for (uint16 i=0; i CUInt128 id = bio.ReadUInt128();
uint32 ip = bio.ReadUInt32();
ip = wxUINT32_SWAP_ALWAYS(ip);
uint16 port = bio.ReadUInt16();
uint16 tport = bio.ReadUInt16();
byte type = bio.ReadUInt8();
//AddDebugLogLineM(false, logKadMain, wxT("Adding contact(s) with ip ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip),port));
if (IsGoodIPPort(wxUINT32_SWAP_ALWAYS(ip),port)) {
routingZone->add(id, ip, port, tport, type);
}
}
}
...
Note that in the above code the statement
ip = wxUINT32_SWAP_ALWAYS(ip);
should be removed. Because the changing from network order to host order has already been done in bio.ReadUInt32():
//the following code is in SafeFile.cpp
uint32 CFileDataIO::ReadUInt32() const
{
uint32 value = 0;
Read(&value, 4);
return ENDIAN_SWAP_32(value);
}
//the following code is in ArchSpecific.h
#define ENDIAN_SWAP_32(x) (wxUINT32_SWAP_ON_BE(x))
//the following code is in defs.h
#define wxUINT32_SWAP_ON_BE(val) wxUINT32_SWAP_ALWAYS(val)