-
Notifications
You must be signed in to change notification settings - Fork 0
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
add tests #2
Open
ibigbug
wants to merge
5
commits into
master
Choose a base branch
from
tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add tests #2
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/rust | ||
{ | ||
"name": "Rust", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye", | ||
"features": { | ||
"ghcr.io/devcontainers/features/rust:1": { | ||
"version": "latest", | ||
"profile": "minimal" | ||
} | ||
}, | ||
// Use 'mounts' to make the cargo cache persistent in a Docker Volume. | ||
// "mounts": [ | ||
// { | ||
// "source": "devcontainer-cargo-cache-${devcontainerId}", | ||
// "target": "/usr/local/cargo", | ||
// "type": "volume" | ||
// } | ||
// ] | ||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "rustc --version", | ||
// Configure tool-specific properties. | ||
// "customizations": {}, | ||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
"remoteUser": "root" | ||
} |
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,12 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for more information: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
# https://containers.dev/guide/dependabot | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "devcontainers" | ||
directory: "/" | ||
schedule: | ||
interval: weekly |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
mod platform; | ||
mod utils; | ||
|
||
pub use libc::{IPPROTO_TCP, IPPROTO_UDP}; | ||
pub use platform::{FindProc, FindProcImpl}; | ||
#[derive(PartialEq)] | ||
pub enum NetworkProtocol { | ||
TCP = 6, | ||
UDP = 17, | ||
} | ||
pub use platform::find_process_name; |
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 |
---|---|---|
@@ -1,32 +1,39 @@ | ||
pub trait FindProc { | ||
fn resolve( | ||
src: Option<std::net::SocketAddr>, | ||
dst: Option<std::net::SocketAddr>, | ||
proto: i32, | ||
) -> Option<String>; | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
mod linux; | ||
#[cfg(target_os = "linux")] | ||
pub use linux::FindProcImpl; | ||
pub use linux::find_process_name; | ||
|
||
#[cfg(target_os = "macos")] | ||
mod macos; | ||
#[cfg(target_os = "macos")] | ||
pub use macos::FindProcImpl; | ||
pub use macos::find_process_name; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
use std::net::TcpListener; | ||
|
||
#[test] | ||
fn test_compile() { | ||
let dst = std::net::SocketAddr::new( | ||
std::net::IpAddr::V4(std::net::Ipv4Addr::new(8, 8, 8, 8)), | ||
80, | ||
); | ||
let _process_name = FindProcImpl::resolve(None, Some(dst), libc::IPPROTO_TCP); | ||
fn test_get_find_tcp_socket() { | ||
let socket = TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let addr = socket.local_addr().unwrap(); | ||
let path = super::find_process_name(Some(addr), None, crate::NetworkProtocol::TCP); | ||
|
||
assert!(path.is_some()); | ||
|
||
let current_exe = std::env::current_exe().unwrap(); | ||
assert_eq!(path.unwrap(), current_exe.to_str().unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_get_find_udp_socket() { | ||
let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap(); | ||
let addr = socket.local_addr().unwrap(); | ||
let path = super::find_process_name(Some(addr), None, crate::NetworkProtocol::UDP); | ||
|
||
assert!(path.is_some()); | ||
|
||
let current_exe = std::env::current_exe().unwrap(); | ||
assert_eq!(path.unwrap(), current_exe.to_str().unwrap()); | ||
} | ||
} |
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,19 +1,26 @@ | ||
pub(crate) fn check(src: Option<std::net::SocketAddr>, dst: Option<std::net::SocketAddr>) -> bool { | ||
if src.is_none() && dst.is_none() { | ||
false | ||
} else if src.is_some() && dst.is_some() { | ||
let inner1 = src.unwrap(); | ||
let inner2 = dst.unwrap(); | ||
(inner1.is_ipv4() && inner2.is_ipv6()) || (inner2.is_ipv4() && inner1.is_ipv6()) | ||
} else { | ||
true | ||
pub(crate) fn pre_condition( | ||
src: Option<std::net::SocketAddr>, | ||
dst: Option<std::net::SocketAddr>, | ||
) -> bool { | ||
match (src, dst) { | ||
(None, None) => false, | ||
(Some(_), None) => true, | ||
(None, Some(_)) => true, | ||
(Some(left), Some(right)) => { | ||
// it was (inner1.is_ipv4() && inner2.is_ipv6()) || (inner2.is_ipv4() && inner1.is_ipv6()) | ||
(left.is_ipv4() && right.is_ipv4()) || (left.is_ipv6() && right.is_ipv6()) | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn is_ipv6(src: Option<std::net::SocketAddr>, dst: Option<std::net::SocketAddr>) -> bool { | ||
if src.is_some() { | ||
src.unwrap().is_ipv6() | ||
} else { | ||
dst.unwrap().is_ipv6() | ||
pub(crate) fn is_ipv6( | ||
src: Option<std::net::SocketAddr>, | ||
dst: Option<std::net::SocketAddr>, | ||
) -> bool { | ||
match (src, dst) { | ||
(Some(addr), None) => addr.is_ipv6(), | ||
(None, Some(addr)) => addr.is_ipv6(), | ||
(Some(left), Some(right)) => left.is_ipv6() || right.is_ipv6(), | ||
_ => false, | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VendettaReborn i might've made this wrong - but were you trying only pass src and dst with different proto here?