Erlang :gen_tcp.connect/3
‘s first argument(Address
) is either an :inet.ip_address()
which is a tuple of octets or an :inet.hostname()
which is a char_list. Write a function format_host
that takes a string a returns a valid format for :gen_tcp.connect
format_host("192.168.0.1") #=> {192, 168, 0, 1}
format_host("www.example.com") #=> 'www.example.com'
How about using interop with Erlang to handle a solved problem for you, and take advantage of :inet.parse_strict_address. This solution would also handle IPv6 addresses as well. ;)