Skip to content

Commit

Permalink
Refactor sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraemii committed Oct 30, 2024
1 parent 1ce91d8 commit feea120
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 182 deletions.
3 changes: 2 additions & 1 deletion rust/examples/tcp.nasl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ ret = send(socket: sock, data: 'foobar');
display("num bytes sent: ", ret);
rec = recv(socket: sock, length: 10, min: 3);
display(rec);
display("end");
close(sock);
display("end");
1 change: 1 addition & 0 deletions rust/examples/udp.nasl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ ret = send(socket: sock, data: '123');
display("num bytes sent: ", ret);
rec = recv(socket: sock, length: 10);
display(rec);
close(sock);
display("end");
18 changes: 18 additions & 0 deletions rust/src/nasl/builtin/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ impl Display for OpenvasEncaps {
}
}

pub fn get_retry(context: &Context) -> u8 {
if let Ok(Some(val)) = get_kb_item(context, "timeout_retry") {
match val {
NaslValue::String(val) => val.parse::<u8>().unwrap_or(2),
NaslValue::Number(val) => {
if val < 1 || val > 255 {
2
} else {
val as u8
}
}
_ => 2,
}
} else {
2
}
}

pub fn get_kb_item(context: &Context, name: &str) -> Result<Option<NaslValue>, FunctionErrorKind> {
context
.retriever()
Expand Down
Loading

0 comments on commit feea120

Please sign in to comment.