12345678910111213141516171819202122232425open!CoreopenAsyncletlocalhost="localhost"letfqdnhost=match%mapAsync.Unix.Addr_info.get~host[AI_SOCKTYPEUnix.SOCK_STREAM;AI_FAMILYUnix.PF_INET;AI_CANONNAME]>>|List.map~f:(fun(info:Core_unix.addr_info)->info.ai_canonname)(* This filtering avoids using canonical names when those are not merely qualified
versions of the host.
*)>>|List.filter~f:(funpotential_fqdn->matchString.chop_prefixpotential_fqdn~prefix:hostwith|None->false|Some""->true|Somesuffix->String.is_prefixsuffix~prefix:".")with|[]->Or_error.errorf"No canonical name found for [%s]"host|[fqdn]->Okfqdn|_->Or_error.errorf"Too many results returned for [%s]"host;;