Skip to content

Commit

Permalink
Add: NASL builtin function recv_line
Browse files Browse the repository at this point in the history
Also implements the buffer for TCP connections, as received messages must be buffered in order to read them line by line.
  • Loading branch information
Kraemii committed Sep 23, 2024
1 parent 07bc95b commit 2282ff5
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 57 deletions.
2 changes: 1 addition & 1 deletion rust/src/nasl/builtin/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- islocalnet
- get_host_ip
- scanner_add_port
- recv_line

## Missing

Expand All @@ -28,7 +29,6 @@
- leave_multicast_group
- open_priv_sock_tcp
- open_priv_sock_udp
- recv_line
- scanner_get_port
- start_denial
- telnet_init
12 changes: 12 additions & 0 deletions rust/src/nasl/builtin/network/network_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket},
ptr,
str::FromStr,
time::Duration,
};

use crate::nasl::prelude::*;
Expand All @@ -22,6 +23,17 @@ pub fn ipstr2ipaddr(ip_addr: &str) -> Result<IpAddr, FunctionErrorKind> {
}
}

/// Convert timeout
pub fn convert_timeout(timeout: Option<i64>) -> Option<Duration> {
timeout.and_then(|timeout| {
if timeout < 1 {
None
} else {
Some(Duration::from_secs(timeout as u64))
}
})
}

/// Bind a local UDP socket to a V4 or V6 address depending on the given destination address
pub fn bind_local_socket(dst: &SocketAddr) -> Result<UdpSocket, FunctionErrorKind> {
let fe = Err(FunctionErrorKind::Diagnostic(
Expand Down
Loading

0 comments on commit 2282ff5

Please sign in to comment.