procedure biniplist_free(var l:tbiniplist);\r
procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist);\r
function biniplist_tostr(const l:tbiniplist):string;\r
+function isbiniplist(const l:tbiniplist):boolean;\r
\r
function htons(w:word):word;\r
function htonl(i:uint32):uint32;\r
procedure maskbits(var binip:tbinip;bits:integer);\r
function comparebinipmask(ip1,ip2:tbinip;bits:integer):boolean;\r
\r
+procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);\r
+\r
{deprecated}\r
function longip(s:string):longint;\r
\r
+function needconverttov4(const ip:tbinip):boolean;\r
procedure converttov4(var ip:tbinip);\r
\r
function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;\r
result := comparebinip(ip1,ip2);\r
end;\r
\r
-{converts a binary IP to v4 if it is a v6 IP in the v4 range}\r
-procedure converttov4(var ip:tbinip);\r
+function needconverttov4(const ip:tbinip):boolean;\r
begin\r
{$ifdef ipv6}\r
if ip.family = AF_INET6 then begin\r
if (ip.ip6.u6_addr32[0] = 0) and (ip.ip6.u6_addr32[1] = 0) and\r
(ip.ip6.u6_addr16[4] = 0) and (ip.ip6.u6_addr16[5] = $ffff) then begin\r
- ip.family := AF_INET;\r
- ip.ip := ip.ip6.s6_addr32[3];\r
+ result := true;\r
+ exit;\r
end;\r
end;\r
{$endif}\r
+\r
+ result := false;\r
end;\r
\r
-{------------------------------------------------------------------------------}\r
+{converts a binary IP to v4 if it is a v6 IP in the v4 range}\r
+procedure converttov4(var ip:tbinip);\r
+begin\r
+ {$ifdef ipv6}\r
+ if needconverttov4(ip) then begin\r
+ ip.family := AF_INET;\r
+ ip.ip := ip.ip6.s6_addr32[3];\r
+ end;\r
+ {$endif}\r
+end;\r
+\r
+{-----------biniplist stuff--------------------------------------------------}\r
+\r
+const\r
+ biniplist_prefix='bipl'#0;\r
+ biniplist_prefixlen=length(biniplist_prefix);\r
\r
function biniplist_new:tbiniplist;\r
begin\r
- result := '';\r
+ result := biniplist_prefix;\r
end;\r
\r
procedure biniplist_add(var l:tbiniplist;ip:tbinip);\r
\r
function biniplist_getcount(const l:tbiniplist):integer;\r
begin\r
- result := length(l) div sizeof(tbinip);\r
+ result := (length(l)-biniplist_prefixlen) div sizeof(tbinip);\r
end;\r
\r
function biniplist_get(const l:tbiniplist;index:integer):tbinip;\r
fillchar(result,sizeof(result),0);\r
exit;\r
end;\r
- move(l[index*sizeof(tbinip)+1],result,sizeof(result));\r
+ move(l[index*sizeof(tbinip)+1+biniplist_prefixlen],result,sizeof(result));\r
end;\r
\r
procedure biniplist_set(var l:tbiniplist;index:integer;ip:tbinip);\r
begin\r
uniquestring(l);\r
- move(ip,l[index*sizeof(tbinip)+1],sizeof(ip));\r
+ move(ip,l[index*sizeof(tbinip)+1+biniplist_prefixlen],sizeof(ip));\r
end;\r
\r
procedure biniplist_setcount(var l:tbiniplist;newlen:integer);\r
begin\r
- setlength(l,sizeof(tbinip)*newlen);\r
+ setlength(l,(sizeof(tbinip)*newlen)+biniplist_prefixlen);\r
end;\r
\r
procedure biniplist_free(var l:tbiniplist);\r
\r
procedure biniplist_addlist;\r
begin\r
- l := l + l2;\r
+ l := l + copy(l2,biniplist_prefixlen+1,maxlongint);\r
end;\r
\r
function biniplist_tostr(const l:tbiniplist):string;\r
result := result + ')';\r
end;\r
\r
+function isbiniplist(const l:tbiniplist):boolean;\r
+var\r
+ i : integer;\r
+begin\r
+ for i := 1 to biniplist_prefixlen do begin\r
+ if biniplist_prefix[i] <> l[i] then begin\r
+ result := false;\r
+ exit;\r
+ end;\r
+ end;\r
+ result := true;\r
+end;\r
+\r
+procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer);\r
+var\r
+ a:integer;\r
+ biniptemp:tbinip;\r
+begin\r
+ for a := biniplist_getcount(l2)-1 downto 0 do begin\r
+ biniptemp := biniplist_get(l2,a);\r
+ if (biniptemp.family = family) then biniplist_add(l,biniptemp);\r
+ end;\r
+end;\r
+\r
+\r
end.\r