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

Various cleanups #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ authors = ["Johannes Blaschke <[email protected]>"]
version = "0.1.0"

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

[compat]
AbstractTrees = "0.4"
CEnum = "0.4"
CpuId = "0.3"
julia = "1.7"
julia = "1.7"
19 changes: 19 additions & 0 deletions src/NetworkInterfaceControllers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ struct Interface
ip::IPAddr
end

"""
get_interface_data([IPAddr]; loopback=false)

Return IP addresses, versions, and interface names of all connected interfaces.

# Examples
```julia-repl
julia> get_interface_data()
2-element Vector{NetworkInterfaceControllers.Interface}:
NetworkInterfaceControllers.Interface("wlo1", :v4, ip"192.168.178.21")
NetworkInterfaceControllers.Interface("wlo1", :v6, ip"2001:9e8:687b:8b00:b9e2:345e:cfed:a673")

julia> import Sockets: IPv4

julia> get_interface_data(IPv4)
1-element Vector{NetworkInterfaceControllers.Interface}:
NetworkInterfaceControllers.Interface("wlo1", :v4, ip"192.168.178.21")
```
"""
function get_interface_data(
::Type{T}=IPAddr; loopback::Bool=false
) where T <: IPAddr
Expand Down
4 changes: 1 addition & 3 deletions src/libuv_extensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ module LibUVExtensions
##


using CEnum

const sa_family_t = Cushort

const in_port_t = UInt16
Expand Down Expand Up @@ -133,4 +131,4 @@ function uv_free_interface_addresses(addresses, count)
ccall(:uv_free_interface_addresses, Cvoid, (Ptr{uv_interface_address_t}, Cint), addresses, count)
end

end
end
15 changes: 1 addition & 14 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
name = "NIC Test"
uuid = "6f74fd91-2978-43ad-8164-3af8c0ec0142"
authors = ["Johannes Blaschke <[email protected]>"]
version = "0.1.0"

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

[compat]
AbstractTrees = "0.4"
CEnum = "0.4"
CpuId = "0.3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test: @testset, @test

import NetworkInterfaceControllers: get_interface_data


@testset "get_interface_data()" begin
interfaces = get_interface_data(; loopback=true)
# We should always see at least the loopback interface
@test !isempty(interfaces)
end