17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 |
*) |
*) |
19 |
|
|
20 |
|
open Int64ops |
21 |
open Printf2 |
open Printf2 |
22 |
type t = int * int * int * int |
type t = int * int * int * int |
23 |
|
|
50 |
Printf.sprintf "%03d.%03d.%03d.%03d" a4 a3 a2 a1 |
Printf.sprintf "%03d.%03d.%03d.%03d" a4 a3 a2 a1 |
51 |
|
|
52 |
let to_int64 ((a4, a3, a2, a1) as t) = |
let to_int64 ((a4, a3, a2, a1) as t) = |
53 |
let small = a1 + 256 * (a2 + 256 * a3) in |
let small = a1 lor (a2 lsl 8) lor (a3 lsl 16) in |
54 |
Int64.add (Int64.of_int small) (Int64.shift_left (Int64.of_int a4) 24) |
(Int64.of_int small) ++ (Int64.shift_left (Int64.of_int a4) 24) |
|
|
|
|
let const_int32_255 = Int64.of_int 255 |
|
55 |
|
|
56 |
let of_int64 i = |
let of_int64 i = |
57 |
let a4 = Int64.to_int (Int64.logand (Int64.shift_right i 24) const_int32_255) |
let a4 = Int64.to_int (Int64.logand (Int64.shift_right i 24) 0xffL) |
58 |
in |
in |
59 |
let a3 = Int64.to_int (Int64.logand (Int64.shift_right i 16) const_int32_255) |
let a3 = Int64.to_int (Int64.logand (Int64.shift_right i 16) 0xffL) |
60 |
in |
in |
61 |
let a2 = Int64.to_int (Int64.logand (Int64.shift_right i 8) const_int32_255) |
let a2 = Int64.to_int (Int64.logand (Int64.shift_right i 8) 0xffL) |
62 |
in |
in |
63 |
let a1 = Int64.to_int (Int64.logand i const_int32_255) |
let a1 = Int64.to_int (Int64.logand i 0xffL) |
64 |
in |
in |
65 |
(a4, a3, a2, a1) |
(a4, a3, a2, a1) |
66 |
|
|