X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/055fa6bf18e0733d1bf2f97075d6bb33c76e72b5..9a44a542cab11c03215fe3c844dde2529a87258d:/binipstuff.pas diff --git a/binipstuff.pas b/binipstuff.pas index 675b03e..8f28a27 100644 --- a/binipstuff.pas +++ b/binipstuff.pas @@ -9,10 +9,8 @@ interface {$include lcoreconfig.inc} {$ifndef win32} -{$ifdef ipv6} uses sockets; {$endif} -{$endif} {$ifdef fpc} {$mode delphi} @@ -24,11 +22,15 @@ uses sockets; const hexchars:array[0..15] of char='0123456789abcdef'; - AF_INET=2; {$ifdef win32} + AF_INET=2; AF_INET6=23; {$else} - AF_INET6=10; + //redeclare these constants so units that use us can use them + //without using sockets directly + AF_INET=AF_INET; + AF_INET6=AF_INET6; + //AF_INET6=10; {$endif} type @@ -155,6 +157,7 @@ function longip(s:string):longint; function needconverttov4(const ip:tbinip):boolean; procedure converttov4(var ip:tbinip); +procedure converttov6(var ip:tbinip); function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip; function makeinaddrv(addr:tbinip;port:string;var inaddr:tinetsockaddrv):integer; @@ -535,6 +538,23 @@ begin {$endif} end; + +{converts a binary IP to v6 if it is a v4 IP} +procedure converttov6(var ip:tbinip); +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.u6_addr32[1] := 0; + ip.ip6.u6_addr16[4] := 0; + ip.ip6.u6_addr16[5] := $ffff; + end; + {$endif} +end; + + {-----------biniplist stuff--------------------------------------------------} const