mirror of
https://github.com/mirage/qubes-mirage-firewall.git
synced 2024-10-01 01:05:39 -04:00
2d78d47591
Co-Authored-By: Mindy Preston <yomimono@users.noreply.github.com> Co-Authored-By: Olle Jonsson <olle.jonsson@gmail.com> Co-Authored-By: hannes <hannes@mehnert.org> Co-Authored-By: cfcs <cfcs@users.noreply.github.com>
17 lines
379 B
OCaml
17 lines
379 B
OCaml
module Set = Set.Make(struct
|
|
type t = int
|
|
let compare a b = compare a b
|
|
end)
|
|
|
|
include Set
|
|
|
|
let rec pick_free_port ?(retries = 10) ~consult add_to =
|
|
let p = 1024 + Random.int (0xffff - 1024) in
|
|
if (mem p !consult || mem p !add_to) && retries <> 0
|
|
then pick_free_port ~retries:(retries - 1) ~consult add_to
|
|
else
|
|
begin
|
|
add_to := add p !add_to;
|
|
p
|
|
end
|