added "length of IP in bits" functions. removed some trailing whitespace.
authorbeware <beware@bircd.org>
Sat, 23 Jan 2016 04:18:39 +0000 (04:18 +0000)
committerbeware <beware@bircd.org>
Sat, 23 Jan 2016 04:18:39 +0000 (04:18 +0000)
git-svn-id: file:///svnroot/lcore/trunk@145 b1de8a11-f9be-4011-bde0-cc7ace90066a

binipstuff.pas

index d6220293af9bd90240af9ee9396ddea0b4fc7e60..489c2a2e6b8de5e8a198f26743888c69f84f4588 100644 (file)
@@ -166,6 +166,10 @@ function inaddrvtobinip(inaddrv:tinetsockaddrv):tbinip;
 function makeinaddrv(addr:tbinip;port:ansistring;var inaddr:tinetsockaddrv):integer;\r
 function inaddrsize(inaddr:tinetsockaddrv):integer;\r
 \r
+function getbinipbitlength(const ip:tbinip):integer;\r
+function getipstrbitlength(const ip:thostname):integer;\r
+function getfamilybitlength(family:integer):integer;\r
+\r
 implementation\r
 \r
 uses sysutils;\r
@@ -555,8 +559,8 @@ begin
   {$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.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
@@ -660,5 +664,26 @@ begin
   end;\r
 end;\r
 \r
+function getfamilybitlength(family:integer):integer;\r
+begin\r
+  {$ifdef ipv6}\r
+  if family = AF_INET6 then result := 128 else\r
+  {$endif}\r
+  if family = AF_INET then result := 32\r
+  else result := 0;\r
+end;\r
+\r
+function getbinipbitlength(const ip:tbinip):integer;\r
+begin\r
+  result := getfamilybitlength(ip.family);\r
+end;\r
+\r
+function getipstrbitlength(const ip:thostname):integer;\r
+var\r
+  biniptemp:tbinip;\r
+begin\r
+  ipstrtobin(ip,biniptemp);\r
+  result := getbinipbitlength(biniptemp);\r
+end;\r
 \r
 end.\r