Mask some part of public IP in the logs for security reason.

This commit is contained in:
ANR2ME 2022-06-23 00:41:41 +07:00
parent 4b78224d22
commit ea6e5c8f74
2 changed files with 6 additions and 3 deletions

View File

@ -170,10 +170,13 @@ bool isPTPPortInUse(uint16_t port, bool forListen, SceNetEtherAddr* dstmac, uint
}
// Replacement for inet_ntoa since it's getting deprecated
std::string ip2str(in_addr in) {
std::string ip2str(in_addr in, bool maskPublicIP) {
char str[INET_ADDRSTRLEN] = "...";
u8* ipptr = (u8*)∈
snprintf(str, sizeof(str), "%u.%u.%u.%u", ipptr[0], ipptr[1], ipptr[2], ipptr[3]);
if (maskPublicIP && !isPrivateIP(in.s_addr))
snprintf(str, sizeof(str), "%u.%u.xx.%u", ipptr[0], ipptr[1], ipptr[3]);
else
snprintf(str, sizeof(str), "%u.%u.%u.%u", ipptr[0], ipptr[1], ipptr[2], ipptr[3]);
return std::string(str);
}

View File

@ -1014,7 +1014,7 @@ bool isPDPPortInUse(uint16_t port);
bool isPTPPortInUse(uint16_t port, bool forListen, SceNetEtherAddr* dstmac = nullptr, uint16_t dstport = 0);
// Convert IPv4 address to string (Replacement for inet_ntoa since it's getting deprecated)
std::string ip2str(in_addr in);
std::string ip2str(in_addr in, bool maskPublicIP = true);
// Convert MAC address to string
std::string mac2str(SceNetEtherAddr* mac);