Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple way of referring to system on the other side of the network #6

Open
fhunleth opened this issue Mar 9, 2020 · 1 comment

Comments

@fhunleth
Copy link
Member

fhunleth commented Mar 9, 2020

Currently, it's not easy to refer to the other side of the network. With nerves_init_gadget, you could use peer.usb0.lan, but that doesn't exist with nerves_pack and vintage_net_direct.

Here's a workaround:

 def peer_address(ifname) do
    VintageNet.get(["interface", ifname, "addresses"])
    |> hd()
    |> Map.get(:address)
    |> add_one()
  end

  defp add_one({a, b, c, d}), do: {a, b, c, d + 1}

Example use:

iex> ifconfig
lo: flags=[:up, :loopback, :running]
    inet 127.0.0.1  netmask 255.0.0.0
    inet ::1  netmask ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
    hwaddr 00:00:00:00:00:00

usb0: flags=[:up, :broadcast, :running, :multicast]
    inet 172.31.6.93  netmask 255.255.255.252  broadcast 172.31.6.93
    inet fe80::38a3:1dff:fe15:ec81  netmask ffff:ffff:ffff:ffff::
    hwaddr 3a:a3:1d:15:ec:81

iex> TestModule.peer_address("usb0")
{172, 31, 6, 94}

It would be useful to add a DNS name like nerves_init_gadget did and to make the address of the other side of the connection visible via a VintageNet property.

@boydm
Copy link

boydm commented Mar 9, 2020

Thank you Frank! That is just what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants