Skip to content

Refactor functions which work with IP addresses #1988

Open
@Disinterpreter

Description

@Disinterpreter

Describe the solution you'd like
Need to refactor these lines and replace all inet_addr and inet_ntoa

Additional context

bool CBanManager::IsValidIP(const char* szIP)
{
char strIP[256] = {'\0'};
strncpy(strIP, szIP, 255);
strIP[255] = '\0';
char* szIP1 = strtok(strIP, ".");
char* szIP2 = strtok(NULL, ".");
char* szIP3 = strtok(NULL, ".");
char* szIP4 = strtok(NULL, "\r");
if (szIP1 && szIP2 && szIP3 && szIP4)
{
if (IsValidIPPart(szIP1) && IsValidIPPart(szIP2) && IsValidIPPart(szIP3) && IsValidIPPart(szIP4))
return true;
}
return false;
}
bool CBanManager::IsValidIPPart(const char* szIP)
{
if (IsNumericString(szIP))
{
int iIP = atoi(szIP);
if (iIP >= 0 && iIP < 256)
return true;
}
else if (strcmp(szIP, "*") == 0)
return true;
return false;
}

if (a == 10 || a == 127 || (a == 169 && b == 254) || (a == 192 && b == 168))
{
CLogger::LogPrintf("WARNING: Private IP '%s' with ase enabled! Use: <serverip>auto</serverip>\n", *strServerIP);
}

Server\mods\deathmatch\logic\CGame.cpp(728,27): warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Shared\mods\deathmatch\logic\Utils.cpp(1009,12): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Server\mods\deathmatch\logic\ASE.cpp(99,40): warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Server\mods\deathmatch\logic\ASE.cpp(166,50): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
Shared\mods\deathmatch\logic\Utils.cpp(1009,12): warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings

https://github.com/multitheftauto/mtasa-blue/search?l=C%2B%2B&q=inet_addr

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions