Skip to content

Commit

Permalink
fix conflicts and improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Nov 28, 2024
1 parent 3a40fee commit e1319d9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
5 changes: 0 additions & 5 deletions rust/src/nasl/builtin/host/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
## Implements

- get_host_name
- get_host_names

## Missing

- TARGET_IS_IPV6
- add_host_name
- get_host_name
Expand Down
5 changes: 2 additions & 3 deletions rust/src/nasl/builtin/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
mod tests;

use std::{
net::{IpAddr, SocketAddr, ToSocketAddrs},
net::{IpAddr, ToSocketAddrs},
str::FromStr,
};

use dns_lookup::lookup_addr;

use crate::function_set;
use crate::nasl::utils::{error::FunctionErrorKind, hosts::resolve, lookup_keys::TARGET};
use crate::nasl::utils::error::FunctionErrorKind;
use crate::nasl::utils::{error::FunctionErrorKind, hosts::resolve};

use crate::nasl::syntax::NaslValue;
use crate::nasl::utils::{Context, ContextType, Register};
Expand Down
2 changes: 1 addition & 1 deletion rust/src/nasl/builtin/ssh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod tests;
pub use error::SshError;
pub use sessions::SshSessions as Ssh;

use std::{borrow::BorrowMut, time::Duration};
use std::time::Duration;

use ::russh::{cipher, Preferred};
use russh_keys::key;
Expand Down
15 changes: 3 additions & 12 deletions rust/src/nasl/utils/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Default for Register {
}
}
use std::collections::HashMap;
use std::net::{AddrParseError, IpAddr};
use std::net::IpAddr;
use std::str::FromStr;
use std::sync::Mutex;

Expand Down Expand Up @@ -363,19 +363,10 @@ impl Target {
// Store the IpAddr if possible, else default to localhost
if let Ok(host) = resolve(self.target.clone()) {
let t = match host {
Some(mut a) => {
let address = a.next().map_or_else(String::new, |x| x.to_string());
address[..(address.len() - 5)].to_string()
}
Some(mut a) => a.next().map_or_else(String::new, |x| x.ip().to_string()),
None => "127.0.0.1".to_string(),
};

self.ip_addr = match t {
x if !x.is_empty() => x.to_string(),
_ => "127.0.0.1".to_string(),
}
.parse()
.unwrap();
self.ip_addr = IpAddr::from_str(t.as_str()).unwrap();
}
self
}
Expand Down

0 comments on commit e1319d9

Please sign in to comment.