Skip to content

Commit

Permalink
Add ismulticast(::IPv4) function (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
klf-gs authored Aug 1, 2024
1 parent 51c39e2 commit f68899b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NetworkProtocols"
uuid = "cc8e9863-198f-4c11-8208-8a22403099d5"
authors = ["Christian Rorvik <[email protected]>"]
version = "0.2.5"
version = "0.2.6"

[deps]
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
Expand Down
4 changes: 4 additions & 0 deletions src/ip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ function decode_ipv4(data::DenseVector{UInt8})
p + h.header_length,
(Int(h.total_length - h.header_length),)))
end

function ismulticast(ip::IPv4)
ip"224.0.0.0" <= ip <= ip"239.255.255.255"
end
5 changes: 5 additions & 0 deletions test/ip_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
@test length(ipp.payload) == 48
end

@testset "ismulticast" begin
@test all(ismulticast(addr) for addr in multicast_addresses)
@test all(!ismulticast(addr) for addr in non_multicast_addresses)
end

end
13 changes: 13 additions & 0 deletions test/test_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@ const dns_packet = [
0x02, 0x63, 0x73, 0x05, 0x6d, 0x69, 0x61, 0x6d, 0x69, 0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01,
0x00, 0x01
]

const multicast_addresses = [
ip"224.0.0.0",
ip"224.0.0.10",
ip"224.0.10.20",
ip"239.255.255.255"
]

const non_multicast_addresses = [
ip"127.0.0.1",
ip"10.0.0.10",
ip"192.168.0.1"
]

2 comments on commit f68899b

@ancapdev
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112192

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.6 -m "<description of version>" f68899b6df4cca684b690bc8929116faa2af545c
git push origin v0.2.6

Please sign in to comment.