Skip to content

Commit

Permalink
Clean up docs for udhcpc/udhcpd
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth committed Dec 20, 2019
1 parent ba1063a commit 9b73dae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/vintage_net/interface/udhcpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule VintageNet.Interface.Udhcpc do
require Logger

@doc """
Handle deconfig reports from udhcpc
"""
@impl true
def deconfig(ifname, info) do
Expand Down Expand Up @@ -40,6 +41,7 @@ defmodule VintageNet.Interface.Udhcpc do
end

@doc """
Handle leasefail reports from udhcpc
"""
@impl true
def leasefail(ifname, _info) do
Expand All @@ -54,6 +56,7 @@ defmodule VintageNet.Interface.Udhcpc do
end

@doc """
Handle nak reports from udhcpc
"""
@impl true
def nak(ifname, info) do
Expand All @@ -77,6 +80,7 @@ defmodule VintageNet.Interface.Udhcpc do
end

@doc """
Handle renew reports from udhcpc
"""
@impl true
def renew(ifname, info) do
Expand Down Expand Up @@ -145,6 +149,7 @@ defmodule VintageNet.Interface.Udhcpc do
end

@doc """
Handle bound reports from udhcpc
"""
@impl true
def bound(ifname, info) do
Expand Down
17 changes: 10 additions & 7 deletions lib/vintage_net/interface/udhcpd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ defmodule VintageNet.Interface.Udhcpd do
end
end

@doc "Parse the leases file from udhcpd"
@doc """
Parse the leases file from udhcpd
"""
@spec parse_leases(Path.t()) :: {:ok, [map()]} | {:error, File.posix()}
def parse_leases(path) do
with {:ok, <<_timestamp::binary-size(8), rest::binary>>} <- File.read(path) do
do_parse_leases(rest, [])
end
end

def do_parse_leases(
<<leasetime::unsigned-integer-size(32), ip1, ip2, ip3, ip4, mac1, mac2, mac3, mac4, mac5,
mac6, hostname::binary-size(20), _pad::binary-size(2), rest::binary>>,
acc
) do
defp do_parse_leases(
<<leasetime::unsigned-integer-size(32), ip1, ip2, ip3, ip4, mac1, mac2, mac3, mac4, mac5,
mac6, hostname::binary-size(20), _pad::binary-size(2), rest::binary>>,
acc
) do
lease = %{
leasetime: leasetime,
lease_nip: Enum.join([ip1, ip2, ip3, ip4], "."),
Expand All @@ -52,5 +55,5 @@ defmodule VintageNet.Interface.Udhcpd do
do_parse_leases(rest, [lease | acc])
end

def do_parse_leases(<<>>, acc), do: {:ok, acc}
defp do_parse_leases(<<>>, acc), do: {:ok, acc}
end

0 comments on commit 9b73dae

Please sign in to comment.