@@ -23,9 +23,9 @@ extern crate dirs;
2323
2424// Average value for Ubuntu
2525#[ cfg( unix) ]
26- const DEFAULT_FILE_DESCRIPTORS_LIMIT : u64 = 8000 ;
26+ const DEFAULT_FILE_DESCRIPTORS_LIMIT : usize = 8000 ;
2727// Safest batch size based on experimentation
28- const AVERAGE_BATCH_SIZE : u16 = 3000 ;
28+ const AVERAGE_BATCH_SIZE : usize = 3000 ;
2929
3030#[ macro_use]
3131extern crate log;
@@ -78,10 +78,10 @@ fn main() {
7878 }
7979
8080 #[ cfg( unix) ]
81- let batch_size: u16 = infer_batch_size ( & opts, adjust_ulimit_size ( & opts) ) ;
81+ let batch_size: usize = infer_batch_size ( & opts, adjust_ulimit_size ( & opts) ) ;
8282
8383 #[ cfg( not( unix) ) ]
84- let batch_size: u16 = AVERAGE_BATCH_SIZE ;
84+ let batch_size: usize = AVERAGE_BATCH_SIZE ;
8585
8686 let scanner = Scanner :: new (
8787 & ips,
@@ -233,10 +233,12 @@ The Modern Day Port Scanner."#;
233233}
234234
235235#[ cfg( unix) ]
236- fn adjust_ulimit_size ( opts : & Opts ) -> u64 {
236+ fn adjust_ulimit_size ( opts : & Opts ) -> usize {
237237 use rlimit:: Resource ;
238+ use std:: convert:: TryInto ;
238239
239240 if let Some ( limit) = opts. ulimit {
241+ let limit = limit as u64 ;
240242 if Resource :: NOFILE . set ( limit, limit) . is_ok ( ) {
241243 detail ! (
242244 format!( "Automatically increasing ulimit value to {limit}." ) ,
@@ -253,14 +255,12 @@ fn adjust_ulimit_size(opts: &Opts) -> u64 {
253255 }
254256
255257 let ( soft, _) = Resource :: NOFILE . get ( ) . unwrap ( ) ;
256- soft
258+ soft. try_into ( ) . unwrap_or ( usize :: MAX )
257259}
258260
259261#[ cfg( unix) ]
260- fn infer_batch_size ( opts : & Opts , ulimit : u64 ) -> u16 {
261- use std:: convert:: TryInto ;
262-
263- let mut batch_size: u64 = opts. batch_size . into ( ) ;
262+ fn infer_batch_size ( opts : & Opts , ulimit : usize ) -> usize {
263+ let mut batch_size = opts. batch_size ;
264264
265265 // Adjust the batch size when the ulimit value is lower than the desired batch size
266266 if ulimit < batch_size {
@@ -271,7 +271,7 @@ fn infer_batch_size(opts: &Opts, ulimit: u64) -> u16 {
271271 // When the OS supports high file limits like 8000, but the user
272272 // selected a batch size higher than this we should reduce it to
273273 // a lower number.
274- if ulimit < AVERAGE_BATCH_SIZE . into ( ) {
274+ if ulimit < AVERAGE_BATCH_SIZE {
275275 // ulimit is smaller than aveage batch size
276276 // user must have very small ulimit
277277 // decrease batch size to half of ulimit
@@ -280,7 +280,7 @@ fn infer_batch_size(opts: &Opts, ulimit: u64) -> u16 {
280280 batch_size = ulimit / 2 ;
281281 } else if ulimit > DEFAULT_FILE_DESCRIPTORS_LIMIT {
282282 info ! ( "Batch size is now average batch size" ) ;
283- batch_size = AVERAGE_BATCH_SIZE . into ( ) ;
283+ batch_size = AVERAGE_BATCH_SIZE ;
284284 } else {
285285 batch_size = ulimit - 100 ;
286286 }
@@ -293,8 +293,6 @@ fn infer_batch_size(opts: &Opts, ulimit: u64) -> u16 {
293293 }
294294
295295 batch_size
296- . try_into ( )
297- . expect ( "Couldn't fit the batch size into a u16." )
298296}
299297
300298#[ cfg( test) ]
0 commit comments