[erlang-questions] [Suspected Spam] Re: Sometime it's the simple stuff...

Raimo Niskanen raimo+erlang-questions@REDACTED
Mon May 5 16:25:47 CEST 2008


Try this undocumented feature:

inet_parse:ntoa({127,0,0,1}) ->
"127.0.0.1"

inet_parse:ntoa({0,0,0,0,0,65535,32512,1}).
"::FFFF:127.0.0.1"


On Mon, May 05, 2008 at 12:40:22AM -0700, Nick Gerakines wrote:
> This is what I came up with. Keep in mind its late.
> 
> %% @spec url_from_ip(IpTuple) -> string().
> %% where
> %%       IpTuple = {integer(), integer(), integer(), integer()}
> %% @doc Stringify a url out of an ip.
> %% Use: url_from_ip({10, 0, 100, 1}).
> url_from_ip(IpTuple) ->
>     "http://" ++
>     lists:foldl(fun(A, "") -> A; (A, Acc) -> Acc ++ "." ++ A end, "",
> [integer_to_list(X)|| X <- tuple_to_list(IpTuple)])
>     ++ "/".
> 
> *duck*
> 
> # Nick Gerakines
> 
> On Thu, May 1, 2008 at 6:56 AM, Dave Bryson <daveb@REDACTED> wrote:
> > I need to take an IP address in the form of "[{10,0,1,100}]" and
> >  create an http URL like this:  "http://10.0.1.100/".  I've tried using
> >  io_lib:format and successfully generated a list.  But, the inets http
> >  client  doesn't  like the format and complains of a malformed URL.
> >
> >  What's the easiest way to convert an IP to the String version?
> >
> >  Thanks!
> >  Dave
> >  _______________________________________________
> >  erlang-questions mailing list
> >  erlang-questions@REDACTED
> >  http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list