package ipaddr

  1. Overview
  2. Docs

A collection of functions for IPv4 addresses.

type t

Type of the internet protocol v4 address of a host

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

of_string s is the address t represented by the IPv4 address s. Returns a human-readable error string if parsing failed.

val of_string_exn : string -> t

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

val of_string_raw : string -> int Stdlib.ref -> t

of_string_raw s off acts as of_string_exn but takes as an extra argument the offset into the string for reading. off will be mutated to an unspecified value during the function call.

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 : Stdlib.Buffer.t -> t -> unit

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

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

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

Bytestring conversion

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

of_bytes s is the address t represented by the IPv4 octets represented by s. s should be exactly 4 bytes long. Returns a human-readable error string if parsing fails.

val of_bytes_exn : string -> 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_raw : string -> int -> t

of_bytes_raw s off is the same as of_bytes_exn but takes an extra paramenter off the offset into the bytes for reading.

val to_bytes : t -> string

to_bytes ipv4 is a string of length 4 encoding ipv4.

val to_bytes_raw : t -> Stdlib.Bytes.t -> 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.

MAC conversion

val multicast_to_mac : t -> Macaddr.t

multicast_to_mac ipv4 is the MAC address corresponding to the multicast address ipv4. Described by RFC 1112.

Host conversion

val to_domain_name : t -> string list

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

Common addresses

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

A module for manipulating IPv4 network prefixes.

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 Stdlib.Map.OrderedType with type t := t
val compare : t -> t -> int
OCaml

Innovation. Community. Security.