+{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
+\r
+{converts a binary IP to v6 if it is a v4 IP}\r
+procedure converttov6(var ip:tbinip);\r
+begin\r
+ {$ifdef ipv6}\r
+ if ip.family = AF_INET then begin\r
+ ip.family := AF_INET6;\r
+ ip.ip6.s6_addr32[3] := ip.ip; \r
+ ip.ip6.u6_addr32[0] := 0; \r
+ ip.ip6.u6_addr32[1] := 0;\r
+ ip.ip6.u6_addr16[4] := 0;\r
+ ip.ip6.u6_addr16[5] := $ffff;\r
+ end;\r
+ {$endif}\r
+end;\r
+\r
+\r
+{-----------biniplist stuff--------------------------------------------------}\r
+\r
+const\r
+ biniplist_prefix: ansistring = 'bipl'#0;\r
+ //fpc 1.0.x doesn't seem to like use of length function in a constant \r
+ //definition\r
+ //biniplist_prefixlen=length(biniplist_prefix);\r
+\r
+ biniplist_prefixlen=5;\r
+ \r
+function biniplist_new:tbiniplist;\r
+begin\r
+ result := biniplist_prefix;\r
+end;\r
+\r
+procedure biniplist_add(var l:tbiniplist;ip:tbinip);\r
+var\r
+ a:integer;\r
+begin\r
+ a := biniplist_getcount(l);\r
+ biniplist_setcount(l,a+1);\r
+ biniplist_set(l,a,ip);\r
+end;\r
+\r
+function biniplist_getcount(const l:tbiniplist):integer;\r
+begin\r
+ result := (length(l)-biniplist_prefixlen) div sizeof(tbinip);\r
+end;\r
+\r
+function biniplist_get(const l:tbiniplist;index:integer):tbinip;\r
+begin\r
+ if (index >= biniplist_getcount(l)) then begin\r
+ fillchar(result,sizeof(result),0);\r
+ exit;\r
+ end;\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+biniplist_prefixlen],sizeof(ip));\r
+end;\r
+\r
+procedure biniplist_setcount(var l:tbiniplist;newlen:integer);\r
+begin\r
+ setlength(l,(sizeof(tbinip)*newlen)+biniplist_prefixlen);\r
+end;\r
+\r
+procedure biniplist_free(var l:tbiniplist);\r
+begin\r
+ l := '';\r
+end;\r
+\r
+procedure biniplist_addlist;\r
+begin\r
+ l := l + copy(l2,biniplist_prefixlen+1,maxlongint);\r
+end;\r
+\r
+function biniplist_tostr(const l:tbiniplist):thostname;\r
+var\r
+ a:integer;\r
+begin\r
+ result := '(';\r
+ for a := 0 to biniplist_getcount(l)-1 do begin\r
+ if result <> '(' then result := result + ', ';\r
+ result := result + ipbintostr(biniplist_get(l,a));\r
+ end;\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