* Add NetAddrIsPrivate function from Ondrej Pokorny

This commit is contained in:
Michaël Van Canneyt 2023-01-09 09:37:23 +01:00
parent f43912a383
commit 00e3cdddce
2 changed files with 13 additions and 0 deletions

View File

@ -750,3 +750,13 @@ begin
end;
function NetAddrIsPrivate(const IP: in_addr): Boolean;
begin
NetAddrIsPrivate:=
// 10.0.0.0 10.255.255.255
(IP.s_bytes[1]=10)
// 172.16.0.0 172.31.255.255
or ((IP.s_bytes[1]=172) and (IP.s_bytes[2]>=16) and (IP.s_bytes[2]<=31))
// 192.168.0.0 192.168.255.255
or ((IP.s_bytes[1]=192) and (IP.s_bytes[2]=168));
end;

View File

@ -203,6 +203,9 @@ Function NetToHost (Net : Longint) : Longint; deprecated;
Function ShortHostToNet(Host : Word) : Word; deprecated;
Function ShortNetToHost(Net : Word) : Word; deprecated;
function NetAddrIsPrivate(const IP: in_addr): Boolean;
// ipv6
function HostAddrToStr6(Entry : Tin6_addr) : AnsiString;
function StrToHostAddr6(IP : AnsiString) : Tin6_addr; // not implemented?!?