Codebase list ocaml-ipaddr / 508cb9f
Imported Upstream version 2.2.0 Stephane Glondu 9 years ago
15 changed file(s) with 369 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1111
1212 echo "yes" | sudo add-apt-repository ppa:$ppa
1313 sudo apt-get update -qq
14 sudo apt-get install -qq ocaml ocaml-native-compilers camlp4-extra opam
14 sudo apt-get install -qq ocaml ocaml-native-compilers ocaml-compiler-libs camlp4-extra opam
1515 export OPAMYES=1
1616 export OPAMVERBOSE=1
1717 echo OCaml version
0 2.2.0 (2014-01-27):
1 * Add an [Ipaddr_unix] module to convert to-and-from the standard library.
2 * Add a toplevel pretty printer in the `ipaddr.top` package.
3
04 2.1.0 (2014-01-20):
15 * Add `of_string_raw` to `Ipaddr.V4.Prefix` and `Ipaddr.V6.Prefix`
26 * Add `of_addr` to `Ipaddr.V4.Prefix` and `Ipaddr.V6.Prefix`
1111 * `Ipaddr.V4` and `Ipaddr.V4.Prefix` modules are `Map.OrderedType`
1212 * `Ipaddr.V6` and `Ipaddr.V6.Prefix` modules are `Map.OrderedType`
1313 * `Ipaddr` and `Ipaddr.Prefix` modules are `Map.OrderedType`
14 * `Ipaddr_unix` in findlib subpackage `ipaddr.unix` provides compatibility with the standard library `Unix` module
15 * `Ipaddr_top` in findlib subpackage `ipaddr.top` provides top-level pretty printers (requires compiler-libs default since OCaml 4.0)
1416 * IP address scope classification
1517 * IPv4-mapped addresses in IPv6 (::ffff:0:0/96) are an embedding of IPv4
1618 * MAC-48 (Ethernet) address support
00 OASISFormat: 0.3
11 Name: ipaddr
2 Version: 2.1.0
2 Version: 2.2.0
33 Synopsis: A library for manipulation of IP (and MAC) address representations
44 Authors: David Sheets, Anil Madhavapeddy, Hugo Heuzard
55 License: ISC
66 Plugins: META (0.3), DevFiles (0.3)
77 BuildTools: ocamlbuild
8
9 Flag unix
10 Description: build the unix library
11 Default: true
12
13 Flag top
14 Description: build the toplevel printers
15 Default: true
816
917 Library ipaddr
1018 Path: lib
1321 NativeOpt: -w @f@p@u@s@40
1422 ByteOpt: -w @f@p@u@s@40
1523
24 Library ipaddr_unix
25 Build$: flag(unix)
26 Path: lib
27 Findlibparent: ipaddr
28 Findlibname: unix
29 Modules: Ipaddr_unix
30 BuildDepends: unix, ipaddr
31
32 Library ipaddr_top
33 Build$: flag(top)
34 Path: top
35 FindlibName: top
36 FindlibParent: ipaddr
37 Modules: Ipaddr_top
38 # Compiler libs do not exists for OCaml < 4.0.0 and otherwise always
39 # present. Use _tags to set them up.
40 # BuildDepends: compiler-libs.toplevel
41 XMETARequires: ipaddr
42 XMETADescription: Toplevel printers for IP addresses
43
1644 Test ipaddr
1745 Run: true
1846 Command: make
00 # OASIS_START
1 # DO NOT EDIT (digest: 4ae62e3665fc102fb022d9d1c2c8df73)
1 # DO NOT EDIT (digest: 6e3d75e627e8d27796e5d44e56fed7b0)
22 # Ignore VCS directories, you can use the same kind of rule outside
33 # OASIS_START/STOP if you want to exclude directories that contains
44 # useless stuff for the build process
1818 <lib/*.ml{,i}>: oasis_library_ipaddr_byte
1919 <lib/ipaddr.{cma,cmxa}>: oasis_library_ipaddr_native
2020 <lib/*.ml{,i}>: oasis_library_ipaddr_native
21 # Library ipaddr_unix
22 "lib/ipaddr_unix.cmxs": use_ipaddr_unix
23 <lib/*.ml{,i}>: use_ipaddr
24 <lib/*.ml{,i}>: pkg_unix
25 # Library ipaddr_top
26 "top/ipaddr_top.cmxs": use_ipaddr_top
2127 # OASIS_STOP
2228 true: debug, annot, bin_annot, principal
29 <top/*.ml>: I(+compiler-libs)
00 # OASIS_START
1 # DO NOT EDIT (digest: 27735b5b8ddb548ad5bbe2baf0be89b6)
2 version = "2.0.0"
1 # DO NOT EDIT (digest: 958d37e3e4912bb1de77a8fb8718d800)
2 version = "2.2.0"
33 description =
44 "A library for manipulation of IP (and MAC) address representations"
55 archive(byte) = "ipaddr.cma"
77 archive(native) = "ipaddr.cmxa"
88 archive(native, plugin) = "ipaddr.cmxs"
99 exists_if = "ipaddr.cma"
10 package "unix" (
11 version = "2.2.0"
12 description =
13 "A library for manipulation of IP (and MAC) address representations"
14 requires = "unix ipaddr"
15 archive(byte) = "ipaddr_unix.cma"
16 archive(byte, plugin) = "ipaddr_unix.cma"
17 archive(native) = "ipaddr_unix.cmxa"
18 archive(native, plugin) = "ipaddr_unix.cmxs"
19 exists_if = "ipaddr_unix.cma"
20 )
21
22 package "top" (
23 version = "2.2.0"
24 description = "Toplevel printers for IP addresses"
25 requires = "ipaddr"
26 archive(byte) = "ipaddr_top.cma"
27 archive(byte, plugin) = "ipaddr_top.cma"
28 archive(native) = "ipaddr_top.cmxa"
29 archive(native, plugin) = "ipaddr_top.cmxs"
30 exists_if = "ipaddr_top.cma"
31 )
1032 # OASIS_STOP
1133
133133 to_buffer b i;
134134 Buffer.contents b
135135
136 let pp_hum ppf i =
137 Format.fprintf ppf "%s" (to_string i)
138
136139 (* Byte conversion *)
137140
138141 let of_bytes_raw bs o =
233236 let b = Buffer.create 18 in
234237 to_buffer b subnet;
235238 Buffer.contents b
239
240 let pp_hum ppf i =
241 Format.fprintf ppf "%s" (to_string i)
236242
237243 let to_address_buffer buf ((_,sz) as subnet) addr =
238244 to_buffer buf (network_address subnet addr,sz)
521527 to_buffer ?v4 buf l;
522528 Buffer.contents buf
523529
530 let pp_hum ppf i =
531 Format.fprintf ppf "%s" (to_string i)
532
524533 (* byte conversion *)
525534
526535 let of_bytes_raw bs o = (* TODO : from cstruct *)
609618 let buf = Buffer.create 43 in
610619 to_buffer buf subnet;
611620 Buffer.contents buf
621
622 let pp_hum ppf i =
623 Format.fprintf ppf "%s" (to_string i)
612624
613625 let to_address_buffer buf ((_,sz) as subnet) addr =
614626 to_buffer buf (network_address subnet addr,sz)
682694 | V4 x -> V4.to_buffer buf x
683695 | V6 x -> V6.to_buffer buf x
684696
697 let pp_hum ppf i =
698 Format.fprintf ppf "%s" (to_string i)
699
685700 let of_string_raw s offset =
686701 let len = String.length s in
687702 if len < !offset + 1 then raise (need_more s);
790805 | V4 p -> V4.Prefix.to_buffer buf p
791806 | V6 p -> V6.Prefix.to_buffer buf p
792807
808 let pp_hum ppf i =
809 Format.fprintf ppf "%s" (to_string i)
793810 end
6363 buffer [buf]. *)
6464 val to_buffer : Buffer.t -> t -> unit
6565
66 (** [pp_hum f ipv4] outputs a human-readable representation of [ipv4] to
67 the formatter [f]. *)
68 val pp_hum : Format.formatter -> t -> unit
69
6670 (** Bytestring conversion *)
6771
6872 (** [of_bytes_exn ipv4_octets] is the address represented
154158 (** [to_string prefix] is the CIDR notation string representation
155159 of [prefix], i.e. XXX.XX.X.XXX/XX. *)
156160 val to_string : t -> string
161
162 (** [pp_hum f prefix] outputs a human-readable representation of [prefix]
163 to the formatter [f]. *)
164 val pp_hum : Format.formatter -> t -> unit
157165
158166 (** [of_address_string_exn cidr_addr] is the address and prefix
159167 represented by [cidr_addr]. Raises [Parse_error] if [cidr_addr] is not
276284 buffer [buf]. *)
277285 val to_buffer : ?v4:bool -> Buffer.t -> t -> unit
278286
287 (** [pp_hum f ipv6] outputs a human-readable representation of [ipv6] to
288 the formatter [f]. *)
289 val pp_hum : Format.formatter -> t -> unit
290
279291 (** Bytestring conversion *)
280292
281293 (** [of_bytes_exn ipv6_octets] is the address represented
367379 of [prefix], i.e. XXX:XX:X::XXX/XX. *)
368380 val to_string : t -> string
369381
382 (** [pp_hum f prefix] outputs a human-readable representation of [prefix]
383 to the formatter [f]. *)
384 val pp_hum : Format.formatter -> t -> unit
385
370386 (** [of_address_string_exn cidr_addr] is the address and prefix
371387 represented by [cidr_addr]. Raises [Parse_error] if [cidr_addr] is not
372388 a valid representation of a CIDR-scoped address. *)
457473 [buf]. *)
458474 val to_buffer : Buffer.t -> t -> unit
459475
476 (** [pp_hum f ip] outputs a human-readable representation of [ip] to the
477 formatter [f]. *)
478 val pp_hum : Format.formatter -> t -> unit
479
460480 (** [of_string_exn s] parses [s] as an IPv4 or IPv6 address.
461481 Raises [Parse_error] if [s] is not a valid string representation of an IP
462482 address. *)
507527
508528 val compare : t -> t -> int
509529
530 (** [to_string subnet] is the text string representation of [subnet]. *)
531 val to_string : t -> string
532
533 (** [to_buffer buf subnet] writes the text string representation of [subnet]
534 into [buf]. *)
535 val to_buffer : Buffer.t -> t -> unit
536
537 (** [pp_hum f subnet] outputs a human-readable representation of [subnet]
538 to the formatter [f]. *)
539 val pp_hum : Format.formatter -> t -> unit
540
510541 (** [of_string_exn cidr] is the subnet prefix represented by the CIDR
511542 string, [cidr]. Raises [Parse_error] if [cidr] is not a valid
512543 representation of a CIDR notation routing prefix. *)
539570 (** [of_addr ip] create a subnet composed of only one address, [ip].*)
540571 val of_addr : addr -> t
541572
542 (** [to_string subnet] is the text string representation of [subnet]. *)
543 val to_string : t -> string
544
545 (** [to_buffer buf subnet] writes the text string representation of [subnet]
546 into [buf]. *)
547 val to_buffer : Buffer.t -> t -> unit
548
549573 include Map.OrderedType with type t := t
550574 end
551575
0 (*
1 * Copyright (c) 2014 Anil Madhavapeddy <anil@recoil.org>
2 *
3 * Permission to use, copy, modify, and distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 *
15 *)
16
17 let to_inet_addr t =
18 Unix.inet_addr_of_string (Ipaddr.to_string t)
19
20 let of_inet_addr t =
21 Ipaddr.of_string_exn (Unix.string_of_inet_addr t)
22
23 module V4 = struct
24
25 let to_inet_addr t =
26 Unix.inet_addr_of_string (Ipaddr.V4.to_string t)
27
28 let of_inet_addr_exn t =
29 Ipaddr.V4.of_string_exn (Unix.string_of_inet_addr t)
30
31 let of_inet_addr t =
32 try Some (of_inet_addr_exn t)
33 with _ -> None
34 end
35
36 module V6 = struct
37
38 let to_inet_addr t =
39 Unix.inet_addr_of_string (Ipaddr.V6.to_string t)
40
41 let of_inet_addr_exn t =
42 Ipaddr.V6.of_string_exn (Unix.string_of_inet_addr t)
43
44 let of_inet_addr t =
45 try Some (of_inet_addr_exn t)
46 with _ -> None
47 end
0 (*
1 * Copyright (c) 2014 Anil Madhavapeddy <anil@recoil.org>
2 *
3 * Permission to use, copy, modify, and distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 *
15 *)
16
17 (** Convert to and from [Unix] to [Ipaddr] representations *)
18
19 (** [to_inet_addr ip] is the {! Unix.inet_addr} equivalent of the
20 IPv4 or IPv6 address [ip]. *)
21 val to_inet_addr : Ipaddr.t -> Unix.inet_addr
22
23 (** [of_inet_addr ip] is the {! Ipaddr.t} equivalent of the
24 {! Unix.inet_addr} [ip]. *)
25 val of_inet_addr : Unix.inet_addr -> Ipaddr.t
26
27 module V4 : sig
28
29 (** [to_inet_addr ip] is the {! Unix.inet_addr} equivalent of the
30 IPv4 address [ip]. *)
31 val to_inet_addr : Ipaddr.V4.t -> Unix.inet_addr
32
33 (** [of_inet_addr_exn ip] is the {! Ipaddr.t} equivalent of the
34 {!Unix.inet_addr} [ip] IPv4 address. Raises {! Ipaddr.Parse_error} if
35 [ip] is not a valid representation of an IPv4 address. *)
36 val of_inet_addr_exn : Unix.inet_addr -> Ipaddr.V4.t
37
38 (** Same as [of_inet_addr_exn] but returns an option type instead of raising
39 an exception. *)
40 val of_inet_addr : Unix.inet_addr -> Ipaddr.V4.t option
41 end
42
43 module V6 : sig
44
45 (** [to_inet_addr ip] is the {! Unix.inet_addr} equivalent of the
46 IPv6 address [ip]. *)
47 val to_inet_addr : Ipaddr.V6.t -> Unix.inet_addr
48
49
50 (** [of_inet_addr_exn ip] is the {! Ipaddr.t} equivalent of the
51 {!Unix.inet_addr} [ip] IPv6 address. Raises {! Ipaddr.Parse_error} if
52 [ip] is not a valid representation of an IPv6 address. *)
53 val of_inet_addr_exn : Unix.inet_addr -> Ipaddr.V6.t
54
55 (** Same as [of_inet_addr_exn] but returns an option type instead of raising
56 an exception. *)
57 val of_inet_addr : Unix.inet_addr -> Ipaddr.V6.t option
58 end
0 # OASIS_START
1 # DO NOT EDIT (digest: ee982b4e45569cc57d5ac614e4a92b5b)
2 Ipaddr_unix
3 # OASIS_STOP
00 (* OASIS_START *)
1 (* DO NOT EDIT (digest: a1f1555690ba83caaade174974cb5694) *)
1 (* DO NOT EDIT (digest: b9f1896c4b44f5c023c34582ffa087bd) *)
22 module OASISGettext = struct
33 (* # 22 "src/oasis/OASISGettext.ml" *)
44
554554 open Ocamlbuild_plugin;;
555555 let package_default =
556556 {
557 MyOCamlbuildBase.lib_ocaml = [("ipaddr", ["lib"], [])];
557 MyOCamlbuildBase.lib_ocaml =
558 [
559 ("ipaddr", ["lib"], []);
560 ("ipaddr_unix", ["lib"], []);
561 ("ipaddr_top", ["top"], [])
562 ];
558563 lib_c = [];
559564 flags =
560565 [
577582
578583 let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
579584
580 # 582 "myocamlbuild.ml"
585 # 587 "myocamlbuild.ml"
581586 (* OASIS_STOP *)
582 Ocamlbuild_plugin.dispatch dispatch_default;;
587 let () =
588 let additional_rules = function
589 | After_rules ->
590 pflag ["compile"; "ocaml"] "I" (fun x -> S [A "-I"; A x]);
591 | _ -> ()
592 in
593 Ocamlbuild_plugin.dispatch
594 (MyOCamlbuildBase.dispatch_combine
595 [MyOCamlbuildBase.dispatch_default package_default; additional_rules])
0 (* setup.ml generated for the first time by OASIS v0.3.1 *)
0 (* setup.ml generated for the first time by OASIS v0.4.1 *)
11
22 (* OASIS_START *)
3 (* DO NOT EDIT (digest: e94c7d0b39c533c6cd2c54151586f95f) *)
3 (* DO NOT EDIT (digest: 2064a96eb9de6b7991f512d5fa478005) *)
44 (*
55 Regenerated by OASIS v0.4.1
66 Visit http://oasis.forge.ocamlcore.org for more information and
67296729 alpha_features = [];
67306730 beta_features = [];
67316731 name = "ipaddr";
6732 version = "2.0.0";
6732 version = "2.2.0";
67336733 license =
67346734 OASISLicense.DEP5License
67356735 (OASISLicense.DEP5Unit
67836783 files_ab = [];
67846784 sections =
67856785 [
6786 Flag
6787 ({
6788 cs_name = "unix";
6789 cs_data = PropList.Data.create ();
6790 cs_plugin_data = []
6791 },
6792 {
6793 flag_description = Some "build the unix library";
6794 flag_default = [(OASISExpr.EBool true, true)]
6795 });
6796 Flag
6797 ({
6798 cs_name = "top";
6799 cs_data = PropList.Data.create ();
6800 cs_plugin_data = []
6801 },
6802 {
6803 flag_description = Some "build the toplevel printers";
6804 flag_default = [(OASISExpr.EBool true, true)]
6805 });
67866806 Library
67876807 ({
67886808 cs_name = "ipaddr";
68156835 lib_findlib_name = Some "ipaddr";
68166836 lib_findlib_containers = []
68176837 });
6838 Library
6839 ({
6840 cs_name = "ipaddr_unix";
6841 cs_data = PropList.Data.create ();
6842 cs_plugin_data = []
6843 },
6844 {
6845 bs_build =
6846 [
6847 (OASISExpr.EBool true, false);
6848 (OASISExpr.EFlag "unix", true)
6849 ];
6850 bs_install = [(OASISExpr.EBool true, true)];
6851 bs_path = "lib";
6852 bs_compiled_object = Best;
6853 bs_build_depends =
6854 [
6855 FindlibPackage ("unix", None);
6856 InternalLibrary "ipaddr"
6857 ];
6858 bs_build_tools = [ExternalTool "ocamlbuild"];
6859 bs_c_sources = [];
6860 bs_data_files = [];
6861 bs_ccopt = [(OASISExpr.EBool true, [])];
6862 bs_cclib = [(OASISExpr.EBool true, [])];
6863 bs_dlllib = [(OASISExpr.EBool true, [])];
6864 bs_dllpath = [(OASISExpr.EBool true, [])];
6865 bs_byteopt = [(OASISExpr.EBool true, [])];
6866 bs_nativeopt = [(OASISExpr.EBool true, [])]
6867 },
6868 {
6869 lib_modules = ["Ipaddr_unix"];
6870 lib_pack = false;
6871 lib_internal_modules = [];
6872 lib_findlib_parent = Some "ipaddr";
6873 lib_findlib_name = Some "unix";
6874 lib_findlib_containers = []
6875 });
6876 Library
6877 ({
6878 cs_name = "ipaddr_top";
6879 cs_data = PropList.Data.create ();
6880 cs_plugin_data = []
6881 },
6882 {
6883 bs_build =
6884 [
6885 (OASISExpr.EBool true, false);
6886 (OASISExpr.EFlag "top", true)
6887 ];
6888 bs_install = [(OASISExpr.EBool true, true)];
6889 bs_path = "top";
6890 bs_compiled_object = Best;
6891 bs_build_depends = [];
6892 bs_build_tools = [ExternalTool "ocamlbuild"];
6893 bs_c_sources = [];
6894 bs_data_files = [];
6895 bs_ccopt = [(OASISExpr.EBool true, [])];
6896 bs_cclib = [(OASISExpr.EBool true, [])];
6897 bs_dlllib = [(OASISExpr.EBool true, [])];
6898 bs_dllpath = [(OASISExpr.EBool true, [])];
6899 bs_byteopt = [(OASISExpr.EBool true, [])];
6900 bs_nativeopt = [(OASISExpr.EBool true, [])]
6901 },
6902 {
6903 lib_modules = ["Ipaddr_top"];
6904 lib_pack = false;
6905 lib_internal_modules = [];
6906 lib_findlib_parent = Some "ipaddr";
6907 lib_findlib_name = Some "top";
6908 lib_findlib_containers = []
6909 });
68186910 Test
68196911 ({
68206912 cs_name = "ipaddr";
68456937 };
68466938 oasis_fn = Some "_oasis";
68476939 oasis_version = "0.4.1";
6848 oasis_digest = Some "R\021\187\"\243\226u\149=\232\191A\177O\215\223";
6940 oasis_digest = Some "vz\180\151\174:\136\164H\128{((Q\000V";
68496941 oasis_exec = None;
68506942 oasis_setup_args = [];
68516943 setup_update = false
68536945
68546946 let setup () = BaseSetup.setup setup_t;;
68556947
6856 # 6858 "setup.ml"
6948 # 6950 "setup.ml"
68576949 (* OASIS_STOP *)
68586950 let () = setup ();;
0 let printers = [
1 "Ipaddr.pp_hum";
2 "Ipaddr.Prefix.pp_hum";
3 "Ipaddr.V4.pp_hum";
4 "Ipaddr.V4.Prefix.pp_hum";
5 "Ipaddr.V6.pp_hum";
6 "Ipaddr.V6.Prefix.pp_hum";
7 ]
8
9 let eval_string
10 ?(print_outcome = false) ?(err_formatter = Format.err_formatter) str =
11 let lexbuf = Lexing.from_string str in
12 let phrase = !Toploop.parse_toplevel_phrase lexbuf in
13 Toploop.execute_phrase print_outcome err_formatter phrase
14
15 let rec install_printers = function
16 | [] -> true
17 | printer :: printers ->
18 let cmd = Printf.sprintf "#install_printer %s;;" printer in
19 eval_string cmd && install_printers printers
20
21 let () =
22 if not (install_printers printers) then
23 Format.eprintf "Problem installing Ipaddr-printers@."
0 # OASIS_START
1 # DO NOT EDIT (digest: 3d356511396d154b0f981aed8b64d9b1)
2 Ipaddr_top
3 # OASIS_STOP