This is an automated email from the git hooks/post-receive script. glondu pushed a commit to branch master in repository ocaml-ipaddr.
commit 724757d50901c3aa3b22387bc0d343085bb83462 Author: Stephane Glondu <st...@glondu.net> Date: Thu Jun 26 15:02:17 2014 +0200 Imported Upstream version 2.3.0 --- CHANGES | 5 +++++ _oasis | 2 +- lib/META | 8 ++++---- lib/ipaddr.ml | 11 +++++++++++ lib/ipaddr.mli | 7 +++++++ lib_test/test_ipaddr.ml | 33 ++++++++++++++++++++++++++++++++- setup.ml | 6 +++--- 7 files changed, 63 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index cf2ccf2..4474190 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +2.3.0 (2014-02-05): +* Add `Ipaddr.V4.Prefix.of_netmask` for conversion from an + address/netmask to prefix +* Add `Ipaddr.V4.Prefix.netmask` to generate a netmask address from a prefix + 2.2.0 (2014-01-27): * Add an [Ipaddr_unix] module to convert to-and-from the standard library. * Add a toplevel pretty printer in the `ipaddr.top` package. diff --git a/_oasis b/_oasis index 0d4cef2..3ea1f03 100644 --- a/_oasis +++ b/_oasis @@ -1,6 +1,6 @@ OASISFormat: 0.3 Name: ipaddr -Version: 2.2.0 +Version: 2.3.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 1c39024..85fdbd5 100644 --- a/lib/META +++ b/lib/META @@ -1,6 +1,6 @@ # OASIS_START -# DO NOT EDIT (digest: 958d37e3e4912bb1de77a8fb8718d800) -version = "2.2.0" +# DO NOT EDIT (digest: 54a6da91096efa40acc6dbee5b581fb0) +version = "2.3.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.2.0" + version = "2.3.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.2.0" + version = "2.3.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 a3101fd..a5599ae 100644 --- a/lib/ipaddr.ml +++ b/lib/ipaddr.ml @@ -231,6 +231,16 @@ module V4 = struct let of_address_string s = try Some (of_address_string_exn s) with _ -> None + let of_netmask nm addr = + let rec find_greatest_one bits i = + if bits = 0_l then i-1 else find_greatest_one (bits >|> 1) (i+1) + in + let one = nm &&& (Int32.neg nm) in + let sz = 32 - (find_greatest_one one (if one = 0_l then 33 else 0)) in + if nm <> (mask sz) + then raise (Parse_error ("invalid netmask",to_string nm)) + else make sz addr + let to_buffer buf (pre,sz) = Printf.bprintf buf "%a/%d" to_buffer pre sz let to_string subnet = @@ -274,6 +284,7 @@ module V4 = struct let broadcast (pre,sz) = pre ||| (0x0_FF_FF_FF_FF_l >|> sz) 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 *) diff --git a/lib/ipaddr.mli b/lib/ipaddr.mli index 4188d93..3cacaed 100644 --- a/lib/ipaddr.mli +++ b/lib/ipaddr.mli @@ -173,6 +173,10 @@ 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 @@ -226,6 +230,9 @@ module V4 : 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 diff --git a/lib_test/test_ipaddr.ml b/lib_test/test_ipaddr.ml index b3ae637..7d833d3 100644 --- a/lib_test/test_ipaddr.ml +++ b/lib_test/test_ipaddr.ml @@ -170,6 +170,36 @@ module Test_v4 = struct assert_equal ~msg (V4.Prefix.bits subnet) bits ) pairs + let test_prefix_netmask () = + let nets = [ + "192.168.0.1/32","255.255.255.255"; + "192.168.0.1/31","255.255.255.254"; + "192.168.0.1/1", "128.0.0.0"; + "192.168.0.1/0", "0.0.0.0"; + ] in + List.iter (fun (net_str,nm_str) -> + let prefix, v4 = V4.Prefix.of_address_string_exn net_str in + let nm = V4.Prefix.netmask prefix in + let nnm_str = V4.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 = V4.Prefix.of_netmask nm v4 in + let nns = V4.Prefix.to_address_string prefix v4 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 "127.255.255.255" "invalid netmask"; + error "255.255.254.128" "invalid netmask"; + ] in + List.iter (fun (nm_str,exn) -> + let nm = V4.of_string_exn nm_str in + let addr = V4.of_string_exn "192.168.0.1" in + assert_raises ~msg:nm_str exn (fun () -> V4.Prefix.of_netmask nm addr) + ) bad_masks + let test_scope () = let ip = V4.of_string_exn in (*let is subnet addr = V4.Prefix.(mem addr subnet) in*) @@ -248,6 +278,8 @@ module Test_v4 = struct "network_address_rt" >:: test_network_address_rt; "prefix_broadcast" >:: test_prefix_broadcast; "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; @@ -551,7 +583,6 @@ let test_map () = let test_prefix_mem () = let ip = of_string_exn in - let v4net = Prefix.v4_of_v6 in let ships = [ ip "192.168.0.1", V4 V4.Prefix.private_192, true; ip "192.168.0.1", Prefix.of_string_exn "::ffff:0:0/96", true; diff --git a/setup.ml b/setup.ml index 5fafb11..2f0be8b 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: 2064a96eb9de6b7991f512d5fa478005) *) +(* DO NOT EDIT (digest: c325a9786532b5c6c1e0901ab0ff21f8) *) (* 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.2.0"; + version = "2.3.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 "vz\180\151\174:\136\164H\128{((Q\000V"; + oasis_digest = Some ";\2189o(\023=QX '_\2342\162\197"; 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