Determine local IP address

773 views
Skip to first unread message

Justin Johnson

unread,
Jul 24, 2013, 7:58:59 AM7/24/13
to elixir-l...@googlegroups.com
Hi,

I'm new to Elixir and I'm loving it.  I decided to write a UDP server for the original SliMP3 device to help me learn the language.

One thing I need to do is send a packet to the SliMP3 device telling it the IP address for the server.  I see that I can call :inet.getifaddrs for the full list of interfaces and could then filter out by netmask to get my local 192.168... address.  Is there a cleaner way to handle this?  One option is to simply require that the server IP address be specified when starting up the server and passed in as an option to :gen_udp.open/2.  Does anyone have any other suggestions?

If it is helpful, my scanty code can be found at https://github.com/justincjohnson/slim-elixir/blob/master/lib/slim/server.ex.

Thanks.
Justin

José Valim

unread,
Jul 24, 2013, 8:12:08 AM7/24/13
to elixir-l...@googlegroups.com
There is a :inet.getif() and I've seen people using it but it is not documented.

José Valim
Skype: jv.ptec
Founder and Lead Developer


Justin

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Justin Johnson

unread,
Jul 24, 2013, 8:29:56 AM7/24/13
to elixir-l...@googlegroups.com
Thanks José.



--
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/Ow_bPTe48hA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.

Jesse Schoch

unread,
Jul 26, 2013, 2:33:13 PM7/26/13
to elixir-l...@googlegroups.com
you can also try :net_adm.localhost which should produce the same hostname as iex --name

One thing I noticed is launching iex gets epmd to bind to the first interface, so if you are trying to Node.connect on a 2nd interface it will not be able to connect with a nodistribution error
Reply all
Reply to author
Forward
0 new messages