[erlang-questions] reliably figure out hostname

Ulf Wiger ulf@REDACTED
Thu Aug 2 23:47:42 CEST 2012


On 2 Aug 2012, at 22:58, Richard O'Keefe wrote:

> Eshell V5.6.3  (abort with ^G)
> 1> {ok, LocalHostName} = inet:gethostname().
> {ok,"oucs1251"}
> 2> inet_res:gethostbyname(LocalHostName).
> {error,timeout}
> 
> Tested on an intel Core 2 duo Mac running OSX 10.6.8.

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.

BR,
Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list