add ip2int and int2ip functions to be able to store on pg IPV4 ip addresses
[brisk.git] / web / Obj / brisk.phh
index 6c18990..f221518 100644 (file)
@@ -345,6 +345,20 @@ $G_PG_cons_n = 345;
     /*     printf("\n"); */
     /* } */
 
+function ip2int($s)
+{
+    $v = ip2long($s);
+    if (PHP_INT_SIZE == 4)
+        return ($v);
+
+    return ( ($v & 0x80000000 ? 0xffffffff00000000 : 0x00) | $v );
+}
+
+function int2ip($i)
+{
+    return long2ip($i & 0xffffffff);
+}
+
 function nickserv_msg($dt, $msg) {
     return sprintf('chatt_sub("%s",[0x040003,"%s"],"%s");', $dt, NICKSERV, $msg);
 }