package ipaddr

  1. Overview
  2. Docs

Module IpaddrSource

A library for manipulation of IP address representations.

v5.6.0 - homepage

Sourceexception Parse_error of string * string

Parse_error (err,packet) is raised when parsing of the IP address syntax fails. err contains a human-readable error and packet is the original octet list that failed to parse.

Sourcetype scope =
  1. | Point
  2. | Interface
  3. | Admin
  4. | Site
  5. | Organization
  6. | Global

Type of ordered address scope classifications

Sourceval string_of_scope : scope -> string

string_of_scope scope returns a human-readable representation of scope.

Sourceval scope_of_string : string -> (scope, [> `Msg of string ]) result

scope_of_string s returns a scope from a string representation of s. Valid string values for s can be obtained via string_of_scope.

Sourceval pp_scope : Format.formatter -> scope -> unit

pp_scope fmt scope outputs a human-readable representation of scope to the fmt formatter.

Sourcemodule V4 : sig ... end

A collection of functions for IPv4 addresses.

Sourcemodule V6 : sig ... end

A collection of functions for IPv6 addresses.

Sourcetype ('v4, 'v6) v4v6 =
  1. | V4 of 'v4
  2. | V6 of 'v6

Type of either an IPv4 value or an IPv6 value

Sourcetype t = (V4.t, V6.t) v4v6

Type of any IP address

Sourceval to_string : t -> string

to_string addr is the text string representation of addr.

Sourceval to_buffer : Buffer.t -> t -> unit

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

Sourceval pp : Format.formatter -> t -> unit

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

Sourceval 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.

Sourceval of_string : string -> (t, [> `Msg of string ]) result

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

Sourceval of_string_raw : string -> int ref -> t

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

Sourceval with_port_of_string : default:int -> string -> (t * int, [> `Msg of string ]) result

with_port_of_string ~default s parses s as an IPv4 or IPv6 address with a possible port seperated by a ':' (if not, we use default). For IPv6, due to the ':' separator, only a full expansion of the IPv6 plus the port lets us to interpret the last :<int> as the port. In other words:

  • ::1:8080 returns the IPv6 ::1:8080 with the default port
  • 0:0:0:0:0:0:0:1:8080 returns ::1 with the port 8080.
Sourceval of_octets_exn : string -> t

of_octets_exn octets is the address t represented by octets. The octets must be 4 bytes long for a V4 or 16 if a V6. Raises Parse_error if octets is not a valid representation of an address.

Sourceval of_octets : string -> (t, [> `Msg of string ]) result

Same as of_octets_exn but returns a result type instead of raising an exception.

Sourceval to_octets : t -> string

to_octets addr returns the bytes representing the addr octets, which will be 4 bytes long if addr is a V4 or 16 if a V6.

Sourceval 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.

Sourceval to_v4 : t -> V4.t option

to_v4 addr is the IPv4 representation of addr.

Sourceval v6_of_v4 : V4.t -> V6.t

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

Sourceval to_v6 : t -> V6.t

to_v6 addr is the IPv6 representation of addr.

Sourceval scope : t -> scope

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

Sourceval is_global : t -> bool

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

Sourceval is_multicast : t -> bool

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

Sourceval is_private : t -> bool

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

Sourceval multicast_to_mac : t -> Macaddr.t

multicast_to_mac addr is the MAC address corresponding to the multicast address addr. See V4.multicast_to_mac and V6.multicast_to_mac.

Sourceval to_domain_name : t -> [ `host ] Domain_name.t

to_domain_name addr is the domain name label list for reverse lookups of addr. This includes the .in-addr.arpa or .ip6.arpa suffix.

Sourceval of_domain_name : 'a Domain_name.t -> t option

of_domain_name name is Some t if the name has an .in-addr.arpa or ip6.arpa suffix, and an IP address prefixed.

Sourceval succ : t -> (t, [> `Msg of string ]) result

succ addr is ip address next to addr. Returns a human-readable error string if it's already the highest address.

Sourceval pred : t -> (t, [> `Msg of string ]) result

pred addr is ip address before addr. Returns a human-readable error string if it's already the lowest address.

Sourcemodule Prefix : sig ... end
include Map.OrderedType with type t := t
Sourceval compare : t -> t -> int

A total ordering function over the keys. This is a two-argument function f such that f e1 e2 is zero if the keys e1 and e2 are equal, f e1 e2 is strictly negative if e1 is smaller than e2, and f e1 e2 is strictly positive if e1 is greater than e2. Example: a suitable ordering function is the generic structural comparison function Stdlib.compare.

Sourcemodule Set : Set.S with type elt := t
Sourcemodule Map : Map.S with type key := t
OCaml

Innovation. Community. Security.