X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/968c333d05db5d5ecf3599f8e304c67e64f21159..4e72d8df4cde72eb1e62da6e0331af4b7f3e4c6a:/binipstuff.pas?ds=sidebyside diff --git a/binipstuff.pas b/binipstuff.pas index 93363e2..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; @@ -334,7 +338,7 @@ written by beware - implementation does not depend on other ipv6 code such as the tin6_addr type, the parameter can also be untyped. -- it is host endian neutral - binary format is aways network order +- it is host endian neutral - binary format is always network order - it supports compression of zeroes - it supports ::ffff:192.168.12.34 style addresses - they are made to do the Right Thing, more efficient implementations are possible @@ -386,7 +390,7 @@ begin end; end; - {run length atleast 2 0 words} + {run length at least 2 0 words} if (runlength = 1) then begin runlength := 0; runbegin := 0; @@ -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.