package ipaddr

  1. Overview
  2. Docs

A collection of functions for IPv6 addresses.

type t

Type of the internet protocol v6 address of a host

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, [> `Msg of string ]) Stdlib.result

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

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

with_port_of_string ~default ipv6_string is the address represented by ipv6_string with a possibly :<port> (otherwise, we take the default value). Due to the ':' separator, the user should expand ipv6_string to let us to consider the last :<port> as a 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.
val of_string_raw : string -> int Stdlib.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 ipv6 is the string representation of ipv6, i.e. XXX:XX:X::XXX:XX.

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

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

val pp : Stdlib.Format.formatter -> t -> unit

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

Octets conversion

val of_octets_exn : ?off:int -> string -> t

of_octets_exn ?off ipv6_octets is the address represented by ipv6_octets, starting from offset off. Raises Parse_error if ipv6_octets is not a valid representation of an IPv6 address.

val of_octets : ?off:int -> string -> (t, [> `Msg of string ]) Stdlib.result

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

val write_octets_exn : ?off:int -> t -> bytes -> unit

write_octets_exn ?off ipv6 b writes 16 bytes that encode ipv6 into b starting from offset off within b. b must be at least off+16 bytes long or a Parse_error exception will be raised.

val write_octets : ?off:int -> t -> bytes -> (unit, [> `Msg of string ]) Stdlib.result

write_octets ?off ipv6 b writes 16 bytes that encode ipv6 into b starting from offset off within b. b must be at least off+16 bytes long or an error is returned.

val to_octets : t -> string

to_octets ipv6 returns the 16 bytes representing the ipv6 octets.

Int conversion

val of_int64 : (int64 * int64) -> t

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

val to_int64 : t -> int64 * int64

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

val of_int32 : (int32 * int32 * int32 * int32) -> t

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

val to_int32 : t -> int32 * int32 * int32 * int32

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

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.

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

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

MAC conversion

val multicast_to_mac : t -> Macaddr.t

multicast_to_mac ipv6 is the MAC address corresponding to the multicast address ipv6. Described by RFC 2464.

Host conversion

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

to_domain_name ipv6 is the domain name label list for reverse lookups of ipv6. This includes the .ip6.arpa suffix.

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

of_domain_name name is Some t if the name has an .ip6.arpa suffix, and an IPv6 address prefixed.

Utility functions

val succ : t -> (t, [> `Msg of string ]) Stdlib.result

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

val pred : t -> (t, [> `Msg of string ]) Stdlib.result

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

Common addresses

val unspecified : t

unspecified is ::.

val localhost : t

localhost is ::1.

val interface_nodes : t

interface_nodes is ff01::01.

link_nodes is ff02::01.

val interface_routers : t

interface_routers is ff01::02.

link_routers is ff02::02.

val site_routers : t

site_routers is ff05::02.

module Prefix : sig ... end

A module for manipulating IPv6 network prefixes (CIDR).

val scope : t -> scope

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

link_address_of_mac mac is the link-local address for an Ethernet interface derived by the IEEE MAC -> EUI-64 map with the Universal/Local bit complemented for IPv6.

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 Stdlib.Map.OrderedType with type t := t
val compare : t -> t -> int
module Set : Stdlib.Set.S with type elt := t
module Map : Stdlib.Map.S with type key := t