module Cf_ip4_addr: sig
.. end
IPv4 addresses with attribute parameters for type safety.
This module implements IPv4 addresses in an abstract type suitable for use
with the Cf_nameinfo
module, the Cf_socket
module and its cognates
for IPv4 transports. Internally, the IPv4 address is represented as a
boxed 4-byte custom block. Externally, the IPv4 address abstract type is
parameterized with a shadow attribute that constrains how it may be used
depending on its address category.
type -'a
t
The type of IPv4 addresses, parameterized by address category attribute.
type
opaque = [ `AF_INET ]
The shadow attribute type of IPv4 addresses of unknown category.
type
category =
| |
Unspecified |
| |
Unicast |
| |
Multicast |
| |
Experimental |
| |
Broadcast |
The IPv4 address category type.
type
unspecified = [ `AF_INET | `X ]
The shadow attribute type of IPv4 addresses of the Unspecified category.
type
unicast = [ `AF_INET | `U ]
The shadow attribute type of IPv4 addresses of the Unicast category.
type
multicast = [ `AF_INET | `M ]
The shadow attribute type of IPv4 addresses of the Multicast category.
type
experimental = [ `AF_INET | `E ]
The shadow attribute type of IPv4 addresses of the Experimental category.
type
broadcast = [ `AF_INET | `B ]
The shadow attribute type of IPv4 addresses of the Broadcast category.
val category : opaque t -> category
Use category a
to obtain the category of an opaque IPv4 address.
val is_unicast : [> opaque ] t -> unicast t
Use is_unicast a
to validate that an IPv4 address is a unicast address.
Raises Failure
if the address is not a unicast address.
val is_multicast : [> opaque ] t -> multicast t
Use is_multicast a
to validate that an IPv4 address is a multicast
address. Raises Failure
if the address is not a multicast address.
val is_experimental : [> opaque ] t ->
experimental t
Use is_experimental a
to validate that an IPv4 address is an experimental
address. Raises Failure
if the address is not an experimental address.
type
unicast_realm =
| |
U_loopback |
| |
U_link |
| |
U_private |
| |
U_global |
The type of unicast address realms.
val unicast_realm : [> unicast ] t -> unicast_realm
Use unicast_realm a
to identify the address realm of the unicast address
a
.
type
multicast_realm =
The type of multicast address realms.
val multicast_realm : [> multicast ] t -> multicast_realm
Use multicast realm a
to identify the address of the multicast address
a
.
val any : unspecified t
The unspecified IPv4 address, i.e. 0.0.0.0.
val broadcast : broadcast t
The link-local broadcast IPv4 address, i.e. 255.255.255.255.
val loopback : unicast t
The default loopback host address, i.e. 127.0.0.1.
val empty_group : multicast t
The empty group multicast address, i.e. 224.0.0.0.
val all_hosts_group : multicast t
The all-hosts group multicast address, i.e. 224.0.0.1
val all_routers_group : multicast t
The all-routers group multicast address, i.e. 224.0.0.2
val equal : ([> opaque ] as 'a) t -> 'a t -> bool
Use equal a1 a2
to compare two IPv4 addresses for equality.
val compare : ([> opaque ] as 'a) t -> 'a t -> int
Use compare a1 a2
to compare the ordinality of two IPv4 addresses.
val pton : string -> opaque t option
Use pton s
to convert the string s
containing an IPv4 address in
dot-quad format to its equivalent opaque IPv4 address. Returns None
if
the string is not in dot-quad format.
val ntop : [> opaque ] t -> string
Use ntop a
to obtain a string representation of the IPv4 address a
in dot-quad format.
type
network_t
The type of an IPv4 network identifier.
val net_create : ?subnet:int ->
[> unicast ] t -> network_t
Use net_create ?subnet a
to create an IPv4 network identifier that
contains the address a
in its logical scope, optional constraining the
network to subnetwork of width subnet
.
val net_number : network_t -> unicast t
Use net_number n
to produce the IPv4 address conventionally used to
identify the network.
val net_broadcast : network_t -> unicast t
Use net_broadcast n
to produce the IPv4 address conventionally used to
identify the broadcast address for the network or subnet.
val net_prefix : network_t -> int
Use net_prefix
to obtain the number of bits in the subnet mask.
val net_member : network_t -> [> unicast ] t -> bool
Use net_member n a
to test whether the address a
is in the scope of the
network n
.
val net_mask : network_t -> string
Use net_mask n
to return a string representation of the subnet mask for
the network n
in traditional dot-quad format.
val net_increasing : network_t -> unicast t Cf_seq.t
Use net_increasing n
to obtain the sequence of unicast IPv4 addresses
belong to the network n
in increasing order.
val net_decreasing : network_t -> unicast t Cf_seq.t
Use net_decreasing n
to obtain the sequence of unicast IPv4 addresses
belong to the network n
in decreasing order.