X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/987e8123d8ba3201ed2690004cfefd7983ff7487..fd34612bda96990b8a77d39fb939ba2703c85f3e:/binipstuff.pas

diff --git a/binipstuff.pas b/binipstuff.pas
old mode 100755
new mode 100644
index 8411cd3..8f28a27
--- 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
@@ -91,7 +93,8 @@ type
       cuint16=word;
       cuint32=dword;
       sa_family_t=word;
-
      TInetSockAddr6 = packed record
+
+      TInetSockAddr6 = packed record
         sin6_family: word;
         sin6_port: word;
         sin6_flowinfo: uint32;
@@ -154,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;
@@ -323,7 +327,7 @@ end;
 
 {
 IPv6 address binary to/from string conversion routines
-written by beware (steendijk at xs4all dot nl)
+written by beware
 
 - implementation does not depend on other ipv6 code such as the tin6_addr type,
   the parameter can also be untyped.
@@ -534,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
@@ -541,7 +562,8 @@ const
   //fpc 1.0.x doesn't seem to like use of length function in a constant 
   //definition
   //biniplist_prefixlen=length(biniplist_prefix);
-
  biniplist_prefixlen=5;
+
+  biniplist_prefixlen=5;
   
 function biniplist_new:tbiniplist;
 begin