FreeBSD support
[lcore.git] / binipstuff.pas
index 227c6f4965d99af2966c9fb50644a4f91c9e8363..9f84721a27c0e58bcbba33e049a0470d9a77c57f 100644 (file)
@@ -78,8 +78,8 @@ type
    Adding "4" to non IPv6 record names improves code clarity }\r
 \r
   {$ifndef mswindows}\r
-    {zipplet 20170204: Do we still need to support ver1_0? Perhaps a cleanup is in order.\r
-     For now keep supporting it for compatibility. }\r
+    //zipplet 20170204: Do we still need to support ver1_0? Perhaps a cleanup is in order.\r
+    //For now keep supporting it for compatibility.\r
     {$ifdef ver1_0}\r
       cuint16 = word;\r
       cuint32 = dword;\r
@@ -88,15 +88,25 @@ type
   {$endif}\r
 \r
   TLInetSockAddr4 = packed Record\r
+   {$ifdef bsd}\r
+    len:byte;\r
+    family:byte;\r
+   {$else}\r
     family:Word;\r
+   {$endif}\r
     port  :Word;\r
     addr  :uint32;\r
-    pad   :array [0..7] of byte; {zipplet 20170204 - originally this was 1..8 for some reason}\r
+    pad   :array [0..7] of byte;   //zipplet 20170204 - originally this was 1..8 for some reason\r
   end;\r
   \r
   {$ifdef ipv6}\r
     TLInetSockAddr6 = packed record\r
+     {$ifdef bsd}\r
+      sin6_len:byte;\r
+      sin6_family:byte;\r
+     {$else}\r
       sin6_family: word;\r
+     {$endif}\r
       sin6_port: word;\r
       sin6_flowinfo: uint32;\r
       sin6_addr: tin6_addr;\r
@@ -104,7 +114,7 @@ type
     end;\r
   {$endif}\r
 \r
-  {zipplet 20170204: I did not rename the unioned record. We might want to rename this to TLinetSockAddrv }\r
+  //zipplet 20170204: I did not rename the unioned record. We might want to rename this to TLinetSockAddrv\r
   TinetSockAddrv = packed record\r
     case integer of\r
       0: (InAddr:TLInetSockAddr4);\r
@@ -206,6 +216,9 @@ begin
   fillchar(inaddr,sizeof(inaddr),0);\r
   //writeln('converted address '+addr+' to binip '+ipbintostr(biniptemp));\r
   if addr.family = AF_INET then begin\r
+    {$ifdef bsd}\r
+    inAddr.InAddr.Len := sizeof(tlinetsockaddr4);\r
+    {$endif}\r
     inAddr.InAddr.family:=AF_INET;\r
     inAddr.InAddr.port:=htons(strtointdef(port,0));\r
     inAddr.InAddr.addr:=addr.ip;\r
@@ -213,6 +226,9 @@ begin
   end else\r
   {$ifdef ipv6}\r
   if addr.family = AF_INET6 then begin\r
+    {$ifdef bsd}\r
+    inAddr.InAddr6.sin6_len := sizeof(tlinetsockaddr6);\r
+    {$endif}\r
     inAddr.InAddr6.sin6_family:=AF_INET6;\r
     inAddr.InAddr6.sin6_port:=htons(strtointdef(port,0));\r
     inAddr.InAddr6.sin6_addr:=addr.ip6;\r
@@ -300,7 +316,10 @@ begin
   {$endif}\r
 \r
   {try v4}\r
-  binip.ip := htonl(longip(s));\r
+  // zipplet: htonl() expects a uint32 but longip() spits out longint.\r
+  // Because longip() is deprecated, we do not fix it but typecast.\r
+  //binip.ip := htonl(longip(s));\r
+  binip.ip := htonl(uint32(longip(s)));\r
   if (binip.ip <> 0) or (s = '0.0.0.0') then begin\r
     result := true;\r
     binip.family := AF_INET;\r