This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository ocaml-ipaddr.

commit 005a26ee9d7e6a3f634bf45d2492d6c01cf3b108
Author: Stephane Glondu <st...@glondu.net>
Date:   Thu Jun 26 15:02:25 2014 +0200

    Imported Upstream version 2.4.0
---
 CHANGES                 |  8 ++++++++
 _oasis                  |  2 +-
 lib/META                |  8 ++++----
 lib/ipaddr.ml           | 20 +++++++++++++++++++-
 lib/ipaddr.mli          | 21 +++++++++++++++++----
 lib_test/test_ipaddr.ml | 37 +++++++++++++++++++++++++++++++++++++
 setup.ml                |  6 +++---
 7 files changed, 89 insertions(+), 13 deletions(-)

diff --git a/CHANGES b/CHANGES
index 4474190..41b686c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+2.4.0 (2014-02-11):
+* Add `Ipaddr.V6.Prefix.of_netmask` for conversion from an IPv6
+  address/netmask to prefix (useful for some binary interfaces). See #27.
+* Add `Ipaddr.V6.Prefix.netmask` to generate a netmask address from a
+  prefix (useful for some binary interfaces). See #27.
+* Add `Ipaddr.Prefix.network` for generic prefix -> address conversion
+* Add `Ipaddr.Prefix.netmask` for generic prefix -> netmask conversion
+
 2.3.0 (2014-02-05):
 * Add `Ipaddr.V4.Prefix.of_netmask` for conversion from an
   address/netmask to prefix
diff --git a/_oasis b/_oasis
index 3ea1f03..4e43d4f 100644
--- a/_oasis
+++ b/_oasis
@@ -1,6 +1,6 @@
 OASISFormat: 0.3
 Name:        ipaddr
-Version:     2.3.0
+Version:     2.4.0
 Synopsis:    A library for manipulation of IP (and MAC) address representations
 Authors:     David Sheets, Anil Madhavapeddy, Hugo Heuzard
 License:     ISC
diff --git a/lib/META b/lib/META
index 85fdbd5..981d2bc 100644
--- a/lib/META
+++ b/lib/META
@@ -1,6 +1,6 @@
 # OASIS_START
-# DO NOT EDIT (digest: 54a6da91096efa40acc6dbee5b581fb0)
-version = "2.3.0"
+# DO NOT EDIT (digest: aace2be48ddf413aa8036abe8779d04c)
+version = "2.4.0"
 description =
 "A library for manipulation of IP (and MAC) address representations"
 archive(byte) = "ipaddr.cma"
@@ -9,7 +9,7 @@ archive(native) = "ipaddr.cmxa"
 archive(native, plugin) = "ipaddr.cmxs"
 exists_if = "ipaddr.cma"
 package "unix" (
- version = "2.3.0"
+ version = "2.4.0"
  description =
  "A library for manipulation of IP (and MAC) address representations"
  requires = "unix ipaddr"
@@ -21,7 +21,7 @@ package "unix" (
 )
 
 package "top" (
- version = "2.3.0"
+ version = "2.4.0"
  description = "Toplevel printers for IP addresses"
  requires = "ipaddr"
  archive(byte) = "ipaddr_top.cma"
diff --git a/lib/ipaddr.ml b/lib/ipaddr.ml
index a5599ae..170eab3 100644
--- a/lib/ipaddr.ml
+++ b/lib/ipaddr.ml
@@ -623,6 +623,16 @@ module V6 = struct
 
     let of_address_string s = try Some (of_address_string_exn s) with _ -> None
 
+    let of_netmask nm addr =
+      make (match nm with
+      | (0_l,0_l,0_l,0_l) -> 0
+      | (lsw ,0_l ,0_l ,0_l) -> V4.Prefix.(bits (of_netmask lsw V4.any))
+      | (-1_l,lsw ,0_l ,0_l) -> V4.Prefix.(bits (of_netmask lsw V4.any)) + 32
+      | (-1_l,-1_l,lsw ,0_l) -> V4.Prefix.(bits (of_netmask lsw V4.any)) + 64
+      | (-1_l,-1_l,-1_l,lsw) -> V4.Prefix.(bits (of_netmask lsw V4.any)) + 96
+      | _ -> raise (Parse_error ("invalid netmask", to_string nm))
+      ) addr
+
     let to_buffer buf (pre,sz) =
       Printf.bprintf buf "%a/%d" (to_buffer ~v4:false) pre sz
 
@@ -656,8 +666,8 @@ module V6 = struct
     let noneui64_interface  = make  3 (ip 0x0000 0 0 0 0 0 0 0)
 
     let network (pre,sz) = pre
-
     let bits (pre,sz) = sz
+    let netmask subnet = mask (bits subnet)
   end
 
   (* TODO: This could be optimized with something trie-like *)
@@ -817,6 +827,14 @@ module Prefix = struct
     | V4 p -> V4.Prefix.to_buffer buf p
     | V6 p -> V6.Prefix.to_buffer buf p
 
+  let network = function
+    | V4 p -> V4 (V4.Prefix.network p)
+    | V6 p -> V6 (V6.Prefix.network p)
+
+  let netmask = function
+    | V4 p -> V4 (V4.Prefix.netmask p)
+    | V6 p -> V6 (V6.Prefix.netmask p)
+
   let pp_hum ppf i =
     Format.fprintf ppf "%s" (to_string i)
 end
diff --git a/lib/ipaddr.mli b/lib/ipaddr.mli
index 3cacaed..7a76956 100644
--- a/lib/ipaddr.mli
+++ b/lib/ipaddr.mli
@@ -173,10 +173,6 @@ module V4 : sig
         raising an exception. *)
     val of_address_string : string -> (t * addr) option
 
-    (** [of_netmask netmask addr] is the subnet prefix of [addr] with netmask
-        [netmask]. *)
-    val of_netmask : addr -> addr -> t
-
     (** [to_address_string prefix addr] is the network address
         constructed from [prefix] and [addr]. *)
     val to_address_string : t -> addr -> string
@@ -189,6 +185,10 @@ module V4 : sig
         network address representing [addr] in [prefix] to the buffer [buf]. *)
     val to_address_buffer : Buffer.t -> t -> addr -> unit
 
+    (** [of_netmask netmask addr] is the subnet prefix of [addr] with netmask
+        [netmask]. *)
+    val of_netmask : addr -> addr -> t
+
     (** [mem ip subnet] checks whether [ip] is found within [subnet]. *)
     val mem : addr -> t -> bool
 
@@ -412,6 +412,10 @@ module V6 : sig
         network address representing [addr] in [prefix] to the buffer [buf]. *)
     val to_address_buffer : Buffer.t -> t -> addr -> unit
 
+    (** [of_netmask netmask addr] is the subnet prefix of [addr] with netmask
+        [netmask]. *)
+    val of_netmask : addr -> addr -> t
+
     (** [mem ip subnet] checks whether [ip] is found within [subnet]. *)
     val mem : addr -> t -> bool
 
@@ -441,6 +445,9 @@ module V6 : sig
     (** [network subnet] is the address for [subnet]. *)
     val network : t -> addr
 
+    (** [netmask subnet] is the netmask for [subnet]. *)
+    val netmask : t -> addr
+
     (** [bits subnet] is the bit size of the [subnet] prefix. *)
     val bits : t -> int
 
@@ -578,6 +585,12 @@ module Prefix : sig
   (** [of_addr ip] create a subnet composed of only one address, [ip].*)
   val of_addr : addr -> t
 
+  (** [network subnet] is the address for [subnet]. *)
+  val network : t -> addr
+
+  (** [netmask subnet] is the netmask for [subnet]. *)
+  val netmask : t -> addr
+
   include Map.OrderedType with type t := t
 end
 
diff --git a/lib_test/test_ipaddr.ml b/lib_test/test_ipaddr.ml
index 7d833d3..074412c 100644
--- a/lib_test/test_ipaddr.ml
+++ b/lib_test/test_ipaddr.ml
@@ -451,6 +451,41 @@ module Test_v6 = struct
       assert_equal ~msg (V6.Prefix.bits subnet) bits
     ) pairs
 
+  let test_prefix_netmask () =
+    let nets = [
+      "8::1/128","ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff";
+      "8::1/127","ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe";
+      "8::1/96", "ffff:ffff:ffff:ffff:ffff:ffff::";
+      "8::1/64", "ffff:ffff:ffff:ffff::";
+      "8::1/32", "ffff:ffff::";
+      "8::1/1",  "8000::";
+      "8::1/0",  "::";
+    ] in
+    List.iter (fun (net_str,nm_str) ->
+      let prefix, v6 = V6.Prefix.of_address_string_exn net_str in
+      let nm = V6.Prefix.netmask prefix in
+      let nnm_str = V6.to_string nm in
+      let msg = Printf.sprintf "netmask %s <> %s" nnm_str nm_str in
+      assert_equal ~msg nnm_str nm_str;
+      let prefix = V6.Prefix.of_netmask nm v6 in
+      let nns = V6.Prefix.to_address_string prefix v6 in
+      let msg = Printf.sprintf "%s is %s under netmask iso" net_str nns in
+      assert_equal ~msg net_str nns
+    ) nets
+
+  let test_prefix_netmask_bad () =
+    let bad_masks = [
+      error "7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" "invalid netmask";
+      error "ffff:ffff:ffff:ffff:ffff:fffe:8000:0" "invalid netmask";
+      error "ffff:ffff:ffff:fffe:8000::" "invalid netmask";
+      error "ffff:fffe:8000::" "invalid netmask";
+    ] in
+    List.iter (fun (nm_str,exn) ->
+      let nm = V6.of_string_exn nm_str in
+      let addr = V6.of_string_exn "::" in
+      assert_raises ~msg:nm_str exn (fun () -> V6.Prefix.of_netmask nm addr)
+    ) bad_masks
+
   let test_scope () =
     let localhost_v4 = V6.of_string_exn "::ffff:127.0.0.1" in
     let is subnet addr = V6.Prefix.(mem addr subnet) in
@@ -529,6 +564,8 @@ module Test_v6 = struct
     "prefix_string_rt_bad" >:: test_prefix_string_rt_bad;
     "network_address_rt"   >:: test_network_address_rt;
     "prefix_bits"          >:: test_prefix_bits;
+    "prefix_netmask"       >:: test_prefix_netmask;
+    "prefix_netmask_bad"   >:: test_prefix_netmask_bad;
     "scope"                >:: test_scope;
     "map"                  >:: test_map;
     "prefix_map"           >:: test_prefix_map;
diff --git a/setup.ml b/setup.ml
index 2f0be8b..60a1a00 100644
--- a/setup.ml
+++ b/setup.ml
@@ -1,7 +1,7 @@
 (* setup.ml generated for the first time by OASIS v0.4.1 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: c325a9786532b5c6c1e0901ab0ff21f8) *)
+(* DO NOT EDIT (digest: f1ed772ac7c3d5ed281d13698f0d64d6) *)
 (*
    Regenerated by OASIS v0.4.1
    Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6730,7 +6730,7 @@ let setup_t =
           alpha_features = [];
           beta_features = [];
           name = "ipaddr";
-          version = "2.3.0";
+          version = "2.4.0";
           license =
             OASISLicense.DEP5License
               (OASISLicense.DEP5Unit
@@ -6938,7 +6938,7 @@ let setup_t =
        };
      oasis_fn = Some "_oasis";
      oasis_version = "0.4.1";
-     oasis_digest = Some ";\2189o(\023=QX '_\2342\162\197";
+     oasis_digest = Some "\213\173l\\\168En>\213\244\b\163\rT\176U";
      oasis_exec = None;
      oasis_setup_args = [];
      setup_update = false

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-ocaml-maint/packages/ocaml-ipaddr.git

_______________________________________________
Pkg-ocaml-maint-commits mailing list
Pkg-ocaml-maint-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits

Reply via email to