X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/6cb6b7ede2d178e03fa817bc28474c175f5a93b9..1958bd56792f6815dbf06aad80d4144a13439be7:/binipstuff.pas diff --git a/binipstuff.pas b/binipstuff.pas index 0c23533..70ac401 100755 --- a/binipstuff.pas +++ b/binipstuff.pas @@ -124,6 +124,7 @@ procedure biniplist_setcount(var l:tbiniplist;newlen:integer); procedure biniplist_free(var l:tbiniplist); procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist); function biniplist_tostr(const l:tbiniplist):string; +function isbiniplist(const l:tbiniplist):boolean; function htons(w:word):word; function htonl(i:uint32):uint32; @@ -140,9 +141,12 @@ function comparebinip(const ip1,ip2:tbinip):boolean; procedure maskbits(var binip:tbinip;bits:integer); function comparebinipmask(ip1,ip2:tbinip;bits:integer):boolean; +procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer); + {deprecated} function longip(s:string):longint; +function needconverttov4(const ip:tbinip):boolean; procedure converttov4(var ip:tbinip); function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip; @@ -498,25 +502,41 @@ begin result := comparebinip(ip1,ip2); end; -{converts a binary IP to v4 if it is a v6 IP in the v4 range} -procedure converttov4(var ip:tbinip); +function needconverttov4(const ip:tbinip):boolean; begin {$ifdef ipv6} if ip.family = AF_INET6 then begin if (ip.ip6.u6_addr32[0] = 0) and (ip.ip6.u6_addr32[1] = 0) and (ip.ip6.u6_addr16[4] = 0) and (ip.ip6.u6_addr16[5] = $ffff) then begin - ip.family := AF_INET; - ip.ip := ip.ip6.s6_addr32[3]; + result := true; + exit; end; end; {$endif} + + result := false; end; -{------------------------------------------------------------------------------} +{converts a binary IP to v4 if it is a v6 IP in the v4 range} +procedure converttov4(var ip:tbinip); +begin + {$ifdef ipv6} + if needconverttov4(ip) then begin + ip.family := AF_INET; + ip.ip := ip.ip6.s6_addr32[3]; + end; + {$endif} +end; + +{-----------biniplist stuff--------------------------------------------------} + +const + biniplist_prefix='bipl'#0; + biniplist_prefixlen=length(biniplist_prefix); function biniplist_new:tbiniplist; begin - result := ''; + result := biniplist_prefix; end; procedure biniplist_add(var l:tbiniplist;ip:tbinip); @@ -530,7 +550,7 @@ end; function biniplist_getcount(const l:tbiniplist):integer; begin - result := length(l) div sizeof(tbinip); + result := (length(l)-biniplist_prefixlen) div sizeof(tbinip); end; function biniplist_get(const l:tbiniplist;index:integer):tbinip; @@ -539,18 +559,18 @@ begin fillchar(result,sizeof(result),0); exit; end; - move(l[index*sizeof(tbinip)+1],result,sizeof(result)); + move(l[index*sizeof(tbinip)+1+biniplist_prefixlen],result,sizeof(result)); end; procedure biniplist_set(var l:tbiniplist;index:integer;ip:tbinip); begin uniquestring(l); - move(ip,l[index*sizeof(tbinip)+1],sizeof(ip)); + move(ip,l[index*sizeof(tbinip)+1+biniplist_prefixlen],sizeof(ip)); end; procedure biniplist_setcount(var l:tbiniplist;newlen:integer); begin - setlength(l,sizeof(tbinip)*newlen); + setlength(l,(sizeof(tbinip)*newlen)+biniplist_prefixlen); end; procedure biniplist_free(var l:tbiniplist); @@ -560,7 +580,7 @@ end; procedure biniplist_addlist; begin - l := l + l2; + l := l + copy(l2,biniplist_prefixlen+1,maxlongint); end; function biniplist_tostr(const l:tbiniplist):string; @@ -575,4 +595,29 @@ begin result := result + ')'; end; +function isbiniplist(const l:tbiniplist):boolean; +var + i : integer; +begin + for i := 1 to biniplist_prefixlen do begin + if biniplist_prefix[i] <> l[i] then begin + result := false; + exit; + end; + end; + result := true; +end; + +procedure addipsoffamily(var l:tbiniplist;const l2:tbiniplist;family:integer); +var + a:integer; + biniptemp:tbinip; +begin + for a := biniplist_getcount(l2)-1 downto 0 do begin + biniptemp := biniplist_get(l2,a); + if (biniptemp.family = family) then biniplist_add(l,biniptemp); + end; +end; + + end.