From 4e72d8df4cde72eb1e62da6e0331af4b7f3e4c6a Mon Sep 17 00:00:00 2001 From: beware Date: Sat, 23 Jan 2016 04:18:39 +0000 Subject: [PATCH] added "length of IP in bits" functions. removed some trailing whitespace. git-svn-id: file:///svnroot/lcore/trunk@145 b1de8a11-f9be-4011-bde0-cc7ace90066a --- binipstuff.pas | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/binipstuff.pas b/binipstuff.pas index d622029..489c2a2 100644 --- a/binipstuff.pas +++ b/binipstuff.pas @@ -166,6 +166,10 @@ function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip; function makeinaddrv(addr:tbinip;port:ansistring;var inaddr:tinetsockaddrv):integer; function inaddrsize(inaddr:tinetsockaddrv):integer; +function getbinipbitlength(const ip:tbinip):integer; +function getipstrbitlength(const ip:thostname):integer; +function getfamilybitlength(family:integer):integer; + implementation uses sysutils; @@ -555,8 +559,8 @@ begin {$ifdef ipv6} if ip.family = AF_INET then begin ip.family := AF_INET6; - ip.ip6.s6_addr32[3] := ip.ip; - ip.ip6.u6_addr32[0] := 0; + ip.ip6.s6_addr32[3] := ip.ip; + ip.ip6.u6_addr32[0] := 0; ip.ip6.u6_addr32[1] := 0; ip.ip6.u6_addr16[4] := 0; ip.ip6.u6_addr16[5] := $ffff; @@ -660,5 +664,26 @@ begin end; end; +function getfamilybitlength(family:integer):integer; +begin + {$ifdef ipv6} + if family = AF_INET6 then result := 128 else + {$endif} + if family = AF_INET then result := 32 + else result := 0; +end; + +function getbinipbitlength(const ip:tbinip):integer; +begin + result := getfamilybitlength(ip.family); +end; + +function getipstrbitlength(const ip:thostname):integer; +var + biniptemp:tbinip; +begin + ipstrtobin(ip,biniptemp); + result := getbinipbitlength(biniptemp); +end; end. -- 2.30.2