-
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.
Merge pull request #41 from shm11C3/feature/networkinfo
Add: Get Network Info
- Loading branch information
Showing
18 changed files
with
553 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,34 @@ | ||
use serde::{Serialize, Serializer}; | ||
use specta::Type; | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone, Type)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum BackendError { | ||
CpuInfoNotAvailable, | ||
StorageInfoNotAvailable, | ||
MemoryInfoNotAvailable, | ||
GraphicInfoNotAvailable, | ||
NetworkInfoNotAvailable, | ||
NetworkUsageNotAvailable, | ||
UnexpectedError, | ||
// SystemError(String), | ||
} | ||
|
||
impl Serialize for BackendError { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let s = match *self { | ||
BackendError::CpuInfoNotAvailable => "cpuInfoNotAvailable", | ||
BackendError::StorageInfoNotAvailable => "storageInfoNotAvailable", | ||
BackendError::MemoryInfoNotAvailable => "memoryInfoNotAvailable", | ||
BackendError::GraphicInfoNotAvailable => "graphicInfoNotAvailable", | ||
BackendError::NetworkInfoNotAvailable => "networkInfoNotAvailable", | ||
BackendError::NetworkUsageNotAvailable => "networkUsageNotAvailable", | ||
BackendError::UnexpectedError => "unexpectedError", | ||
// BackendError::SystemError(ref e) => e, | ||
}; | ||
serializer.serialize_str(s) | ||
} | ||
} |
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,2 +1,3 @@ | ||
pub mod config; | ||
pub mod error; | ||
pub mod hardware; |
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), false); | ||
|
||
// 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; |
Oops, something went wrong.