Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ colored = "2.0.0"
structopt = "0.3.20"
async-std = "1.6.4"
futures = "0.3"
rlimit = "0.4.0"
rlimit = "0.5.2"
shell-words = "1.0.0"
log = "0.4.0"
env_logger = "0.7.1"
Expand Down
4 changes: 2 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct Opts {

/// Automatically ups the ULIMIT with the value you provided.
#[structopt(short, long)]
pub ulimit: Option<rlimit::rlim>,
pub ulimit: Option<rlimit::RawRlim>,

/// The order of scanning to be performed. The "serial" option will
/// scan ports in ascending order while the "random" option will scan
Expand Down Expand Up @@ -205,7 +205,7 @@ pub struct Config {
timeout: Option<u32>,
tries: Option<u8>,
no_nmap: Option<bool>,
ulimit: Option<rlimit::rlim>,
ulimit: Option<rlimit::RawRlim>,
scan_order: Option<ScanOrder>,
command: Option<Vec<String>>,
}
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use benchmark::{Benchmark, NamedTimer};
use cidr_utils::cidr::IpCidr;
use colorful::{Color, Colorful};
use futures::executor::block_on;
use rlimit::{getrlimit, setrlimit, Resource};
use rlimit::{getrlimit, setrlimit, RawRlim, Resource, Rlim};
use std::collections::HashMap;
use std::fs::File;
use std::io::{prelude::*, BufReader};
Expand All @@ -31,9 +31,9 @@ extern crate colorful;
extern crate dirs;

// Average value for Ubuntu
const DEFAULT_FILE_DESCRIPTORS_LIMIT: rlimit::rlim = 8000;
const DEFAULT_FILE_DESCRIPTORS_LIMIT: RawRlim = 8000;
// Safest batch size based on experimentation
const AVERAGE_BATCH_SIZE: rlimit::rlim = 3000;
const AVERAGE_BATCH_SIZE: RawRlim = 3000;

#[macro_use]
extern crate log;
Expand Down Expand Up @@ -67,7 +67,7 @@ fn main() {
std::process::exit(1);
}

let ulimit: rlimit::rlim = adjust_ulimit_size(&opts);
let ulimit: RawRlim = adjust_ulimit_size(&opts);
let batch_size: u16 = infer_batch_size(&opts, ulimit);

let scanner = Scanner::new(
Expand Down Expand Up @@ -319,9 +319,9 @@ fn build_nmap_arguments<'a>(
arguments
}

fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim {
fn adjust_ulimit_size(opts: &Opts) -> RawRlim {
if opts.ulimit.is_some() {
let limit: rlimit::rlim = opts.ulimit.unwrap();
let limit: Rlim = Rlim::from_raw(opts.ulimit.unwrap());

match setrlimit(Resource::NOFILE, limit, limit) {
Ok(_) => {
Expand All @@ -343,11 +343,11 @@ fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim {

let (rlim, _) = getrlimit(Resource::NOFILE).unwrap();

rlim
rlim.as_raw()
}

fn infer_batch_size(opts: &Opts, ulimit: rlimit::rlim) -> u16 {
let mut batch_size: rlimit::rlim = opts.batch_size.into();
fn infer_batch_size(opts: &Opts, ulimit: RawRlim) -> u16 {
let mut batch_size: RawRlim = opts.batch_size.into();

// Adjust the batch size when the ulimit value is lower than the desired batch size
if ulimit < batch_size {
Expand Down