NetworkMonitor watches network interfaces and emits events to listeners when interfaces appear or vanish.
Example
{:ok, port} = :gen_tcp.connect('www.google.com', 80)
NetworkMonitor.close_on_down(port)
# now when the network cable is unplugged the port
# is automatically closed
Summary
Functions
Returns a specification to start this module under a supervisor.
Wrapper around on_down_apply executes the :inet.close(socket) function
call on the given socket when the sockets associated local interface
goes down.
Returns a MapSet of the currently up interfaces
Execute the given {module, function, arguments} (mfa) tuple when the ip-address
given in with addr is going down. addr should be a member of
interfaces() or the mfa will be executed immediately.
Subscribe to interface events. The given pid or self() by default
will receive these two signals on interface changes
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Wrapper around on_down_apply executes the :inet.close(socket) function
call on the given socket when the sockets associated local interface
goes down.
The sockets associated local interface is retrieved using
:inet.sockname(socket)
Instead of :inet another module name can be specified such
as :ssl
Returns a MapSet of the currently up interfaces
Execute the given {module, function, arguments} (mfa) tuple when the ip-address
given in with addr is going down. addr should be a member of
interfaces() or the mfa will be executed immediately.
Subscribe to interface events. The given pid or self() by default
will receive these two signals on interface changes:
{:interface_down, [ifs]}{:interface_up, [ifs]}
Where ifs is a list of ip address tuples. So for example:
{192, 168, 0, 1} for IPv4 or {0, 0, 0, 0, 0, 0, 0, 1} for IPv6