Erlang futures

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang futures

Magnus Ahltorp-2
How can I get a list of the IP addresses on the machine the node is
running on? There are two drivers named udp_inet and tcp_inet that
seem to return that when INET_REQ_IFGET is requested.

Is this the correct way? In that case, how do I call this driver? If
not, how do I get the list?

/Magnus


Reply | Threaded
Open this post in threaded view
|

Erlang futures

Raimo Niskanen-3
You can try the following undocomented (and unsupported, but it is not
very likely that they will change much in the future :-) functions in
lib/kernel/src/inet.erl:

18>
inet:getiflist().                                                          
{ok,["lo0","hme0"]}
19> inet:ifget("lo0", [addr, broadaddr, dstaddr, mtu, netmask, flags,
hwaddr]). {ok,[{addr,{127,0,0,1}},
     {netmask,{255,0,0,0}},
     {flags,[up,loopback,running,multicast]}]}
20> inet:ifget("hme0", [addr, broadaddr, dstaddr, mtu, netmask, flags,
hwaddr]).  
{ok,[{addr,{134,138,177,99}},
     {broadaddr,{134,138,179,255}},
     {netmask,{255,255,252,0}},
     {flags,[up,broadcast,running,multicast]}]}

"Use the Source, Luke. Let it guide Your hands."

/ Raimo Niskanen, Ericsson UAB, Erlang/OTP.



Magnus Ahltorp wrote:
>
> How can I get a list of the IP addresses on the machine the node is
> running on? There are two drivers named udp_inet and tcp_inet that
> seem to return that when INET_REQ_IFGET is requested.
>
> Is this the correct way? In that case, how do I call this driver? If
> not, how do I get the list?
>
> /Magnus


Reply | Threaded
Open this post in threaded view
|

Erlang futures

Claes Wikström
In reply to this post by Magnus Ahltorp-2
On Wed, Apr 18, 2001 at 10:36:11PM +0200, Magnus Ahltorp wrote:
> How can I get a list of the IP addresses on the machine the node is
> running on? There are two drivers named udp_inet and tcp_inet that
> seem to return that when INET_REQ_IFGET is requested.
>
> Is this the correct way? In that case, how do I call this driver? If
> not, how do I get the list?
>


-module(a).
-author('klacke').
-include_lib("kernel/include/inet.hrl").

-compile(export_all).

ips() ->
    {ok, Name} = inet:gethostname(),
    {ok, HE} = inet:gethostbyname(Name),
    HE#hostent.h_addr_list.



This of cource only returns info from the configured
name service.

The call inet:getif() will query the driver the way you
want and return a list of {IP, Bcast, Mask} tuples



/klacke


--
Claes Wikstrom                        -- Caps lock is nowhere and
Alteon WebSystems                     -- everything is under control          
http://www.bluetail.com/~klacke       --