[erlang-questions] reliably figure out hostname

Tim Watson watson.timothy@REDACTED
Fri Aug 3 00:51:53 CEST 2012


On 2 August 2012 22:47, Ulf Wiger <ulf@REDACTED> wrote:
>
> This works on my Mac:
>
> hostname() ->
>     case {inet_db:gethostname(),inet_db:res_option(domain)} of
>         {H,D} when is_list(D), is_list(H),
>                    length(D)> 0, length(H)>0 ->
>             H ++ "." ++ D;
>         Other ->
>             error({hostname, Other})
>     end.

Sweet, thanks Ulf. I'll try that elsewhere, though it'll mean I've got
to carefully audit new OTP releases just in case the APIs change or
move, but I think pinning the framework to "R15.*" with rebar is
probably sufficient to do so for now.



More information about the erlang-questions mailing list