Skip to content

Commit 0674de9

Browse files
committed
Various cleanups
- Remove unnecessary dependencies - Add docstring for `get_interface_data()` - Add a sanity test
1 parent ce16301 commit 0674de9

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

Diff for: Project.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ authors = ["Johannes Blaschke <[email protected]>"]
44
version = "0.1.0"
55

66
[deps]
7-
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8-
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
9-
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
107
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
118

129
[compat]
13-
AbstractTrees = "0.4"
14-
CEnum = "0.4"
15-
CpuId = "0.3"
16-
julia = "1.7"
10+
julia = "1.7"

Diff for: src/NetworkInterfaceControllers.jl

+19
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ struct Interface
6969
ip::IPAddr
7070
end
7171

72+
"""
73+
get_interface_data([IPAddr]; loopback=false)
74+
75+
Return IP addresses, versions, and interface names of all connected interfaces.
76+
77+
# Examples
78+
```julia-repl
79+
julia> get_interface_data()
80+
2-element Vector{NetworkInterfaceControllers.Interface}:
81+
NetworkInterfaceControllers.Interface("wlo1", :v4, ip"192.168.178.21")
82+
NetworkInterfaceControllers.Interface("wlo1", :v6, ip"2001:9e8:687b:8b00:b9e2:345e:cfed:a673")
83+
84+
julia> import Sockets: IPv4
85+
86+
julia> get_interface_data(IPv4)
87+
1-element Vector{NetworkInterfaceControllers.Interface}:
88+
NetworkInterfaceControllers.Interface("wlo1", :v4, ip"192.168.178.21")
89+
```
90+
"""
7291
function get_interface_data(
7392
::Type{T}=IPAddr; loopback::Bool=false
7493
) where T <: IPAddr

Diff for: src/libuv_extensions.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ module LibUVExtensions
1414
##
1515

1616

17-
using CEnum
18-
1917
const sa_family_t = Cushort
2018

2119
const in_port_t = UInt16
@@ -133,4 +131,4 @@ function uv_free_interface_addresses(addresses, count)
133131
ccall(:uv_free_interface_addresses, Cvoid, (Ptr{uv_interface_address_t}, Cint), addresses, count)
134132
end
135133

136-
end
134+
end

Diff for: test/Project.toml

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
1-
name = "NIC Test"
2-
uuid = "6f74fd91-2978-43ad-8164-3af8c0ec0142"
3-
authors = ["Johannes Blaschke <[email protected]>"]
4-
version = "0.1.0"
5-
61
[deps]
7-
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
8-
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
9-
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
10-
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
11-
12-
[compat]
13-
AbstractTrees = "0.4"
14-
CEnum = "0.4"
15-
CpuId = "0.3"
2+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Diff for: test/runtests.jl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Test: @testset, @test
2+
3+
import NetworkInterfaceControllers: get_interface_data
4+
5+
6+
@testset "get_interface_data()" begin
7+
interfaces = get_interface_data(; loopback=true)
8+
# We should always see at least the loopback interface
9+
@test !isempty(interfaces)
10+
end

0 commit comments

Comments
 (0)