Up

module Ipaddr

: sig

A library for manipulation of IP address representations.

#
exception Parse_error of string * string

Raised when parsing of IP address syntax fails.

#
type bytes = string
#
type scope =
# | Point
# | Interface
# | Admin
# | Site
# | Organization
# | Global

Type of ordered address scope classifications

#
module V4 : sig

A collection of functions for IPv4 addresses.

#
type t

Type of the internet protocol v4 address of a host

#
val compare : t -> t -> int
#
val make : int -> int -> int -> int -> t

Converts the low bytes of four int values into an abstract V4.t.

Text string conversion

#
val of_string_exn : string -> t

of_string_exn ipv4_string is the address represented by ipv4_string. Raises Parse_error if ipv4_string is not a valid representation of an IPv4 address.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val to_string : t -> string

to_string ipv4 is the dotted decimal string representation of ipv4, i.e. XXX.XX.X.XXX.

#
val to_buffer : Buffer.t -> t -> unit

to_buffer buf ipv4 writes the string representation of ipv4 into the buffer buf.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f ipv4 outputs a human-readable representation of ipv4 to the formatter f.

Bytestring conversion

#
val of_bytes_exn : bytes -> t

of_bytes_exn ipv4_octets is the address represented by ipv4_octets. Raises Parse_error if ipv4_octets is not a valid representation of an IPv4 address.

#
val of_bytes : bytes -> t option

Same as of_bytes_exn but returns an option type instead of raising an exception.

#
val of_bytes_raw : bytes -> int -> t

Same as of_bytes_exn but take an extra paramenter, the offset into the bytes for reading.

#
val to_bytes : t -> bytes

to_bytes ipv4 is a string of length 4 encoding ipv4.

#
val to_bytes_raw : t -> bytes -> int -> unit

to_bytes_raw ipv4 bytes offset writes the 4 byte encoding of ipv4 into bytes at offset offset.

Int conversion

#
val of_int32 : int32 -> t

of_int32 ipv4_packed is the address represented by ipv4_packed.

#
val to_int32 : t -> int32

to_int32 ipv4 is the 32-bit packed encoding of ipv4.

#
val of_int16 : int * int -> t

of_int16 ipv4_packed is the address represented by ipv4_packed.

#
val to_int16 : t -> int * int

to_int16 ipv4 is the 16-bit packed encoding of ipv4.

#
val any : t

any is 0.0.0.0.

#
val unspecified : t

unspecified is 0.0.0.0.

#
val broadcast : t

broadcast is 255.255.255.255.

#
val nodes : t

nodes is 224.0.0.1.

#
val routers : t

routers is 224.0.0.2.

#
val localhost : t

localhost is 127.0.0.1.

#
module Prefix : sig

A module for manipulating IPv4 network prefixes.

#
type addr = t
#
type t

Type of a internet protocol subnet

#
val compare : t -> t -> int
#
val mask : int -> addr

mask n is the pseudo-address of an n bit subnet mask.

#
val make : int -> addr -> t

make n addr is the n bit subnet prefix to which addr belongs.

#
val network_address : t -> addr -> addr

network_address prefix addr is the address with prefix prefix and suffix from addr. See <http://tools.ietf.org/html/rfc4291#section-2.3>.

#
val of_string_exn : string -> t

of_string_exn cidr is the subnet prefix represented by the CIDR string, cidr. Raises Parse_error if cidr is not a valid representation of a CIDR notation routing prefix.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val to_string : t -> string

to_string prefix is the CIDR notation string representation of prefix, i.e. XXX.XX.X.XXX/XX.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f prefix outputs a human-readable representation of prefix to the formatter f.

#
val of_address_string_exn : string -> t * addr

of_address_string_exn cidr_addr is the address and prefix represented by cidr_addr. Raises Parse_error if cidr_addr is not a valid representation of a CIDR-scoped address.

#
val of_address_string : string -> (t * addr) option

Same as of_address_string_exn but returns an option type instead of raising an exception.

#
val to_address_string : t -> addr -> string

to_address_string prefix addr is the network address constructed from prefix and addr.

#
val to_buffer : Buffer.t -> t -> unit

to_buffer buf prefix writes the string representation of prefix into the buffer buf.

#
val to_address_buffer : Buffer.t -> t -> addr -> unit

to_address_buffer buf prefix addr writes string representation of the network address representing addr in prefix to the buffer buf.

#
val of_netmask : addr -> addr -> t

of_netmask netmask addr is the subnet prefix of addr with netmask netmask.

#
val mem : addr -> t -> bool

mem ip subnet checks whether ip is found within subnet.

#
val of_addr : addr -> t

of_addr ip create a subnet composed of only one address, ip. It is the same as make 32 ip.

#
val global : t

The default route, all addresses in IPv4-space, 0.0.0.0/0.

#
val loopback : t

The host loopback network, 127.0.0.0/8.

#
val relative : t

The relative addressing network, 0.0.0.0/8.

#
val multicast : t

The multicast network, 224.0.0.0/4.

#
val private_10 : t

The private subnet with 10 as first octet, 10.0.0.0/8.

#
val private_172 : t

The private subnet with 172 as first octet, 172.16.0.0/12.

#
val private_192 : t

The private subnet with 192 as first octet, 192.168.0.0/16.

#
val private_blocks : t list

The privately addressable networks: loopback, link, private_10, private_172, private_192.

#
val broadcast : t -> addr

broadcast subnet is the broadcast address for subnet.

#
val network : t -> addr

network subnet is the address for subnet.

#
val netmask : t -> addr

netmask subnet is the netmask for subnet.

#
val bits : t -> int

bits subnet is the bit size of the subnet prefix.

include Map.OrderedType with type t := t
#
val addr_of_sexp : Sexplib.Sexp.t -> addr
#
val sexp_of_addr : addr -> Sexplib.Sexp.t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val scope : t -> scope

scope ipv4 is the classification of ipv4 by the scope hierarchy.

#
val is_global : t -> bool

is_global ipv4 is a predicate indicating whether ipv4 globally addresses a node.

#
val is_multicast : t -> bool

is_multicast ipv4 is a predicate indicating whether ipv4 is a multicast address.

#
val is_private : t -> bool

is_private ipv4 is a predicate indicating whether ipv4 privately addresses a node.

include Map.OrderedType with type t := t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
module V6 : sig

A collection of functions for IPv6 addresses.

#
type t

Type of the internet protocol v6 address of a host

#
val compare : t -> t -> int
#
val make : int -> int -> int -> int -> int -> int -> int -> int -> t

Converts the low bytes of eight int values into an abstract V6.t.

Text string conversion

#
val of_string_exn : string -> t

of_string_exn ipv6_string is the address represented by ipv6_string. Raises Parse_error if ipv6_string is not a valid representation of an IPv6 address.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val to_string : ?v4:bool -> t -> string

to_string ipv6 is the string representation of ipv6, i.e. XXX:XX:X::XXX:XX.

#
val to_buffer : ?v4:bool -> Buffer.t -> t -> unit

to_buffer buf ipv6 writes the string representation of ipv6 into the buffer buf.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f ipv6 outputs a human-readable representation of ipv6 to the formatter f.

Bytestring conversion

#
val of_bytes_exn : bytes -> t

of_bytes_exn ipv6_octets is the address represented by ipv6_octets. Raises Parse_error if ipv6_octets is not a valid representation of an IPv6 address.

#
val of_bytes : bytes -> t option

Same as of_bytes_exn but returns an option type instead of raising an exception.

#
val of_bytes_raw : bytes -> int -> t

Same as of_bytes_exn but takes an extra paramenter, the offset into the bytes for reading.

#
val to_bytes : t -> bytes

to_bytes ipv6 is a string of length 16 encoding ipv6.

#
val to_bytes_raw : t -> bytes -> int -> unit

to_bytes_raw ipv6 bytes offset writes the 16 bytes encoding of ipv6 into bytes at offset offset.

Int conversion

#
val of_int64 : int64 * int64 -> t

of_int64 (ho, lo) is the IPv6 address represented by two int64.

to_int64 ipv6 is the 128-bit packed encoding of ipv6.

#
val to_int64 : t -> int64 * int64
#
val of_int32 : int32 * int32 * int32 * int32 -> t

of_int32 (a, b, c, d) is the IPv6 address represented by four int32.

to_int32 ipv6 is the 128-bit packed encoding of ipv6.

#
val to_int32 : t -> int32 * int32 * int32 * int32
#
val of_int16 : int * int * int * int * int * int * int * int -> t

of_int16 (a, b, c, d, e, f, g, h) is the IPv6 address represented by eight 16-bit int.

to_int16 ipv6 is the 128-bit packed encoding of ipv6.

#
val to_int16 : t -> int * int * int * int * int * int * int * int
#
val unspecified : t

unspecified is ::.

#
val localhost : t

localhost is ::1.

#
val interface_nodes : t

interface_nodes is ff01::01.

#
module Prefix : sig

A module for manipulating IPv6 network prefixes.

#
type addr = t
#
type t

Type of a internet protocol subnet

#
val compare : t -> t -> int
#
val mask : int -> addr

mask n is the pseudo-address of an n bit subnet mask.

#
val make : int -> addr -> t

make n addr is the n bit subnet prefix to which addr belongs.

#
val network_address : t -> addr -> addr

network_address prefix addr is the address with prefix prefix and suffix from addr. See <http://tools.ietf.org/html/rfc4291#section-2.3>.

#
val of_string_exn : string -> t

of_string_exn cidr is the subnet prefix represented by the CIDR string, cidr. Raises Parse_error if cidr is not a valid representation of a CIDR notation routing prefix.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val to_string : t -> string

to_string prefix is the CIDR notation string representation of prefix, i.e. XXX:XX:X::XXX/XX.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f prefix outputs a human-readable representation of prefix to the formatter f.

#
val of_address_string_exn : string -> t * addr

of_address_string_exn cidr_addr is the address and prefix represented by cidr_addr. Raises Parse_error if cidr_addr is not a valid representation of a CIDR-scoped address.

#
val of_address_string : string -> (t * addr) option

Same as of_address_string_exn but returns an option type instead of raising an exception.

#
val to_address_string : t -> addr -> string

to_address_string prefix addr is the network address constructed from prefix and addr.

#
val to_buffer : Buffer.t -> t -> unit

to_buffer buf prefix writes the string representation of prefix to the buffer buf.

#
val to_address_buffer : Buffer.t -> t -> addr -> unit

to_address_buffer buf prefix addr writes string representation of the network address representing addr in prefix to the buffer buf.

#
val of_netmask : addr -> addr -> t

of_netmask netmask addr is the subnet prefix of addr with netmask netmask.

#
val mem : addr -> t -> bool

mem ip subnet checks whether ip is found within subnet.

#
val of_addr : addr -> t

of_addr ip create a subnet composed of only one address, ip. It is the same as make 128 ip.

#
val global_unicast_001 : t

Global Unicast 001, 2000::/3.

#
val unique_local : t

The Unique Local Unicast (ULA), fc00::/7.

#
val multicast : t

The multicast network, ff00::/8.

#
val ipv4_mapped : t

IPv4-mapped addresses, ::ffff:0:0/96.

#
val noneui64_interface : t

Global Unicast addresses that don't use Modified EUI64 interface identifiers, ::/3.

#
val network : t -> addr

network subnet is the address for subnet.

#
val netmask : t -> addr

netmask subnet is the netmask for subnet.

#
val bits : t -> int

bits subnet is the bit size of the subnet prefix.

include Map.OrderedType with type t := t
#
val addr_of_sexp : Sexplib.Sexp.t -> addr
#
val sexp_of_addr : addr -> Sexplib.Sexp.t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
val scope : t -> scope

scope ipv6 is the classification of ipv6 by the scope hierarchy.

#
val is_global : t -> bool

is_global ipv6 is a predicate indicating whether ipv6 globally addresses a node.

#
val is_multicast : t -> bool

is_multicast ipv6 is a predicate indicating whether ipv6 is a multicast address.

#
val is_private : t -> bool

is_private ipv6 is a predicate indicating whether ipv6 privately addresses a node.

include Map.OrderedType with type t := t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
#
type ('v4, 'v6) v4v6 =
# | V4 of 'v4
# | V6 of 'v6

Type of either an IPv4 value or an IPv6 value

#
type t = (V4.t, V6.t) v4v6

Type of any IP address

#
val compare : t -> t -> int
#
val to_string : t -> string

to_string addr is the text string representation of addr.

#
val to_buffer : Buffer.t -> t -> unit

to_buffer buf addr writes the text string representation of addr into buf.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f ip outputs a human-readable representation of ip to the formatter f.

#
val of_string_exn : string -> t

of_string_exn s parses s as an IPv4 or IPv6 address. Raises Parse_error if s is not a valid string representation of an IP address.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val v4_of_v6 : V6.t -> V4.t option

v4_of_v6 ipv6 is the IPv4 representation of the IPv6 address ipv6. If ipv6 is not an IPv4-mapped address, None is returned.

#
val to_v4 : t -> V4.t option

to_v4 addr is the IPv4 representation of addr.

#
val v6_of_v4 : V4.t -> V6.t

v6_of_v4 ipv4 is the IPv6 representation of the IPv4 address ipv4.

#
val to_v6 : t -> V6.t

to_v6 addr is the IPv6 representation of addr.

#
val scope : t -> scope

scope addr is the classification of addr by the scope hierarchy.

#
val is_global : t -> bool

is_global addr is a predicate indicating whether addr globally addresses a node.

#
val is_multicast : t -> bool

is_multicast addr is a predicate indicating whether addr is a multicast address.

#
val is_private : t -> bool

is_private addr is a predicate indicating whether addr privately addresses a node.

#
module Prefix : sig
#
type addr = t
#
type t = (V4.Prefix.t, V6.Prefix.t) v4v6

Type of a internet protocol subnet

#
val compare : t -> t -> int
#
val to_string : t -> string

to_string subnet is the text string representation of subnet.

#
val to_buffer : Buffer.t -> t -> unit

to_buffer buf subnet writes the text string representation of subnet into buf.

#
val pp_hum : Format.formatter -> t -> unit

pp_hum f subnet outputs a human-readable representation of subnet to the formatter f.

#
val of_string_exn : string -> t

of_string_exn cidr is the subnet prefix represented by the CIDR string, cidr. Raises Parse_error if cidr is not a valid representation of a CIDR notation routing prefix.

#
val of_string : string -> t option

Same as of_string_exn but returns an option type instead of raising an exception.

#
val of_string_raw : string -> int Pervasives.ref -> t

Same as of_string_exn but takes as an extra argument the offset into the string for reading.

#
val v4_of_v6 : V6.Prefix.t -> V4.Prefix.t option

v4_of_v6 ipv6 is the IPv4 representation of the IPv6 subnet ipv6. If ipv6 is not an IPv4-mapped subnet, None is returned.

#
val to_v4 : t -> V4.Prefix.t option

to_v4 subnet is the IPv4 representation of subnet.

#
val v6_of_v4 : V4.Prefix.t -> V6.Prefix.t

v6_of_v4 ipv4 is the IPv6 representation of the IPv4 subnet ipv4.

#
val to_v6 : t -> V6.Prefix.t

to_v6 subnet is the IPv6 representation of subnet.

#
val mem : addr -> t -> bool

mem ip subnet checks whether ip is found within subnet.

#
val of_addr : addr -> t

of_addr ip create a subnet composed of only one address, ip.

#
val network : t -> addr

network subnet is the address for subnet.

#
val netmask : t -> addr

netmask subnet is the netmask for subnet.

include Map.OrderedType with type t := t
#
val addr_of_sexp : Sexplib.Sexp.t -> addr
#
val sexp_of_addr : addr -> Sexplib.Sexp.t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end
include Map.OrderedType with type t := t
#
val scope_of_sexp : Sexplib.Sexp.t -> scope
#
val sexp_of_scope : scope -> Sexplib.Sexp.t
#
val v4v6_of_sexp : (Sexplib.Sexp.t -> 'v4) -> (Sexplib.Sexp.t -> 'v6) -> Sexplib.Sexp.t -> ('v4, 'v6) v4v6
#
val sexp_of_v4v6 : ('v4 -> Sexplib.Sexp.t) -> ('v6 -> Sexplib.Sexp.t) -> ('v4, 'v6) v4v6 -> Sexplib.Sexp.t
#
val t_of_sexp : Sexplib.Sexp.t -> t
#
val sexp_of_t : t -> Sexplib.Sexp.t
end