♻️ refactor: make the self-IP code available within the program
parent
2ba1dc2834
commit
39bcea54d4
1
ideas.md
1
ideas.md
|
@ -3,3 +3,4 @@ Cool ideas that can be done but probably won't be.
|
||||||
- Command for shell substituting IPs into commands
|
- Command for shell substituting IPs into commands
|
||||||
- Arbitrary TCP forwarding of (stdin? stdout? TCP?)
|
- Arbitrary TCP forwarding of (stdin? stdout? TCP?)
|
||||||
- Netcat replacement "Just send a file" _including filename_
|
- Netcat replacement "Just send a file" _including filename_
|
||||||
|
- Public-key crypto for trusting peers on first use (Hard cause it requires mutable disk state)
|
||||||
|
|
21
src/ip.rs
21
src/ip.rs
|
@ -10,6 +10,27 @@ pub enum IpError {
|
||||||
Io (#[from] std::io::Error),
|
Io (#[from] std::io::Error),
|
||||||
#[error (transparent)]
|
#[error (transparent)]
|
||||||
FromUtf8 (#[from] std::string::FromUtf8Error),
|
FromUtf8 (#[from] std::string::FromUtf8Error),
|
||||||
|
#[error ("Self-IP detection is not implemented on Mac OS")]
|
||||||
|
NotImplementedOnMac,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub fn get_ips () -> Result <Vec <Ipv4Addr>, IpError> {
|
||||||
|
let output = linux::get_ip_addr_output ()?;
|
||||||
|
|
||||||
|
Ok (linux::parse_ip_addr_output (&output))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn get_ips () -> Result <Vec <Ipv4Addr>, IpError> {
|
||||||
|
Err (IpError::NotImplementedOnMac)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub fn get_ips () -> Result <Vec <Ipv4Addr>, IpError> {
|
||||||
|
let output = windows::get_ip_config_output ()?;
|
||||||
|
|
||||||
|
Ok (windows::parse_ip_config_output (&output))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -45,11 +45,8 @@ async fn async_main () -> Result <(), AppError> {
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
fn my_ips () -> Result <(), AppError> {
|
fn my_ips () -> Result <(), AppError> {
|
||||||
let output = ip::linux::get_ip_addr_output ()?;
|
for addr in ip::get_ips ()?
|
||||||
|
|
||||||
for addr in ip::linux::parse_ip_addr_output (&output)
|
|
||||||
.iter ()
|
.iter ()
|
||||||
.filter (|a| ! a.is_loopback ())
|
.filter (|a| ! a.is_loopback ())
|
||||||
{
|
{
|
||||||
|
@ -58,21 +55,3 @@ fn my_ips () -> Result <(), AppError> {
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
fn my_ips () -> Result <(), AppError> {
|
|
||||||
println! ("my-ips subcommand not implemented for macos");
|
|
||||||
Ok (())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn my_ips () -> Result <(), AppError> {
|
|
||||||
let output = ip::windows::get_ip_config_output ()?;
|
|
||||||
|
|
||||||
for addr in ip::windows::parse_ip_config_output (&output) {
|
|
||||||
println! ("{:?}", addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok (())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue