Skip to content

Commit

Permalink
Use inet_parse:ntoa/1 in yaws_ctl to format IP addrs
Browse files Browse the repository at this point in the history
Instead of using ad hoc code use inet_parse:ntoa/1 to parse IP
addresses for status output. Note that we have to use
inet_parse:ntoa/1 rather than inet:ntoa/1, since the latter is not
available in older Erlang/OTP releases.
  • Loading branch information
vinoski committed Mar 22, 2016
1 parent d3dcbf7 commit 3f38f85
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/yaws_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,8 @@ vsn(IP) when size(IP) =:= 4 ->
vsn(IP) when size(IP) =:= 8 ->
"(ipv6)".

-define(IPV4_FMT, "~p.~p.~p.~p").
-define(IPV6_FMT,
"~2.16.0b~2.16.0b:~2.16.0b~2.16.0b:~2.16.0b~2.16.0b:~2.16.0b~2.16.0b").

format_ip(IP) ->
case size(IP) of
4 ->
{A, B, C, D} = IP,
io_lib:format(?IPV4_FMT,
[A, B, C, D]);

8 ->
{A, B, C, D, E, F, G, H} = IP,
io_lib:format(?IPV6_FMT,
[A, B, C, D, E, F, G, H])
end.

inet_parse:ntoa(IP).

a_running_config(Sock) ->
gen_tcp:send(Sock, a_running_config()).
Expand Down

0 comments on commit 3f38f85

Please sign in to comment.