mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 03:53:52 +02:00
fix incorrect debugging of agent local and public addresses
This commit is contained in:
parent
22cb78afca
commit
a5ea1dca7e
3 changed files with 20 additions and 18 deletions
|
@ -261,30 +261,19 @@ float Agent::getAverageKilobitsPerSecond() {
|
|||
}
|
||||
|
||||
void Agent::printLog(Agent const& agent) {
|
||||
|
||||
sockaddr_in *agentPublicSocket = (sockaddr_in *) agent.publicSocket;
|
||||
sockaddr_in *agentLocalSocket = (sockaddr_in *) agent.localSocket;
|
||||
|
||||
const char* publicAddressString = (agentPublicSocket == NULL)
|
||||
? "Unknown"
|
||||
: inet_ntoa(agentPublicSocket->sin_addr);
|
||||
unsigned short publicAddressPort = (agentPublicSocket == NULL)
|
||||
? 0
|
||||
: ntohs(agentPublicSocket->sin_port);
|
||||
char publicAddressBuffer[16] = {'\0'};
|
||||
unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, agent.publicSocket);
|
||||
|
||||
char localAddressBuffer[16] = {'\0'};
|
||||
unsigned short localAddressPort = loadBufferWithSocketInfo(localAddressBuffer, agent.localSocket);
|
||||
|
||||
const char* localAddressString = (agentLocalSocket == NULL)
|
||||
? "Unknown"
|
||||
: inet_ntoa(agentLocalSocket->sin_addr);
|
||||
unsigned short localAddressPort = (agentLocalSocket == NULL)
|
||||
? 0
|
||||
: ntohs(agentPublicSocket->sin_port);
|
||||
|
||||
::printLog("ID: %d T: %s (%c) PA: %s:%d LA: %s:%d\n",
|
||||
agent.agentId,
|
||||
agent.getTypeName(),
|
||||
agent.type,
|
||||
publicAddressString,
|
||||
publicAddressBuffer,
|
||||
publicAddressPort,
|
||||
localAddressString,
|
||||
localAddressBuffer,
|
||||
localAddressPort);
|
||||
}
|
|
@ -107,6 +107,18 @@ int getLocalAddress() {
|
|||
return localAddress;
|
||||
}
|
||||
|
||||
unsigned short loadBufferWithSocketInfo(char *addressBuffer, sockaddr *socket) {
|
||||
if (socket != NULL) {
|
||||
char *copyBuffer = inet_ntoa(((sockaddr_in*) socket)->sin_addr);
|
||||
memcpy(addressBuffer, copyBuffer, strlen(copyBuffer));
|
||||
return htons(((sockaddr_in*) socket)->sin_port);
|
||||
} else {
|
||||
const char* unknownAddress = "Unknown";
|
||||
memcpy(addressBuffer, unknownAddress, strlen(unknownAddress));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
UDPSocket::UDPSocket(int listeningPort) {
|
||||
init();
|
||||
// create the socket
|
||||
|
|
|
@ -36,5 +36,6 @@ int packSocket(unsigned char *packStore, in_addr_t inAddress, in_port_t networkO
|
|||
int packSocket(unsigned char *packStore, sockaddr *socketToPack);
|
||||
int unpackSocket(unsigned char *packedData, sockaddr *unpackDestSocket);
|
||||
int getLocalAddress();
|
||||
unsigned short loadBufferWithSocketInfo(char *addressBuffer, sockaddr *socket);
|
||||
|
||||
#endif /* defined(__interface__UDPSocket__) */
|
||||
|
|
Loading…
Reference in a new issue