-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
178 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::utils::ip::*; | ||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; | ||
|
||
#[test] | ||
fn test_link_local_ipv6() { | ||
// リンクローカルアドレス | ||
let ip = IpAddr::V6("fe80::1".parse::<Ipv6Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), true); | ||
|
||
// グローバルIPv6アドレス | ||
let ip = IpAddr::V6("2400:4051::1".parse::<Ipv6Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), true); | ||
|
||
// IPv6マルチキャスト | ||
let ip = IpAddr::V6("ff02::1".parse::<Ipv6Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
|
||
// 未指定アドレス | ||
let ip = IpAddr::V6("::".parse::<Ipv6Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
} | ||
|
||
#[test] | ||
fn test_ipv4_not_link_local() { | ||
// IPv4アドレス(リンクローカルではない) | ||
let ip = IpAddr::V4("192.168.1.1".parse::<Ipv4Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
|
||
// IPv4アドレス(リンクローカルではない) | ||
let ip = IpAddr::V4("127.0.0.1".parse::<Ipv4Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
} | ||
|
||
#[test] | ||
fn test_with_direct_ipv6() { | ||
// 直接Ipv6Addr型でテスト | ||
let ip = "fe80::1".parse::<Ipv6Addr>().unwrap(); | ||
assert_eq!(is_unicast_link_local(&ip), true); | ||
|
||
let ip = "2400:4051::1".parse::<Ipv6Addr>().unwrap(); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
} | ||
|
||
#[test] | ||
fn test_with_invalid_format() { | ||
// 無効なアドレス文字列はパースエラーを引き起こすためここではテストしないが、 | ||
// 型制約に沿ってテストする例 | ||
let ip = IpAddr::V4("255.255.255.255".parse::<Ipv4Addr>().unwrap()); | ||
assert_eq!(is_unicast_link_local(&ip), false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
pub mod color; | ||
#[cfg(test)] | ||
pub mod formatter; | ||
#[cfg(test)] | ||
pub mod ip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::net::IpAddr; | ||
|
||
pub fn is_unicast_link_local<T>(ip: &T) -> bool | ||
where | ||
T: Into<IpAddr> + Clone, | ||
{ | ||
match ip.clone().into() { | ||
IpAddr::V6(v6) => v6.segments()[0] & 0xffc0 == 0xfe80, | ||
_ => false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod color; | ||
pub mod file; | ||
pub mod formatter; | ||
pub mod ip; | ||
pub mod logger; | ||
pub mod tauri; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters