diff --git a/Project.toml b/Project.toml index c2da874..7ad865a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NetworkProtocols" uuid = "cc8e9863-198f-4c11-8208-8a22403099d5" authors = ["Christian Rorvik "] -version = "0.2.5" +version = "0.2.6" [deps] FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e" diff --git a/src/ip.jl b/src/ip.jl index 0dfcda6..c9d23e9 100644 --- a/src/ip.jl +++ b/src/ip.jl @@ -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 diff --git a/test/ip_tests.jl b/test/ip_tests.jl index 0266881..bbeca7b 100644 --- a/test/ip_tests.jl +++ b/test/ip_tests.jl @@ -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 diff --git a/test/test_data.jl b/test/test_data.jl index d4086b5..b387fa9 100644 --- a/test/test_data.jl +++ b/test/test_data.jl @@ -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" +]