Skip to content

Commit

Permalink
add Ipaddr.Prefix.address
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hannesm committed May 22, 2024
1 parent c762628 commit a814bd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ipaddr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/ipaddr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]. *)

Expand Down

0 comments on commit a814bd4

Please sign in to comment.