From a814bd4e13df1e8f9784d8113482196ff05f152f Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 22 May 2024 10:46:47 +0200 Subject: [PATCH] add Ipaddr.Prefix.address previously only Ipaddr.V4.Prefix.address and Ipaddr.V6.Prefix.address were available. it is pretty useful to also extract an IP address from an Ipaddr.Prefix.t --- lib/ipaddr.ml | 4 ++++ lib/ipaddr.mli | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/ipaddr.ml b/lib/ipaddr.ml index 18794c5..64e74f4 100644 --- a/lib/ipaddr.ml +++ b/lib/ipaddr.ml @@ -1354,6 +1354,10 @@ module Prefix = struct | V4 p -> V4 (V4.Prefix.netmask p) | V6 p -> V6 (V6.Prefix.netmask p) + let address = function + | V4 p -> V4 (V4.Prefix.address p) + | V6 p -> V6 (V6.Prefix.address p) + let pp ppf i = Format.fprintf ppf "%s" (to_string i) let first = function diff --git a/lib/ipaddr.mli b/lib/ipaddr.mli index 62f3dec..95124ed 100644 --- a/lib/ipaddr.mli +++ b/lib/ipaddr.mli @@ -777,6 +777,9 @@ module Prefix : sig val netmask : t -> addr (** [netmask subnet] is the netmask for [subnet]. *) + val address : t -> addr + (** [address cidr] is the address for [cidr]. *) + val first : t -> addr (** [first subnet] is first valid unicast address in this [subnet]. *)