Refactor main
This commit is contained in:
45
src/main.rs
45
src/main.rs
@@ -85,7 +85,7 @@ struct Arg {
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let arg = Arg::parse();
|
||||
let mut file = arg.output.map(|path| {
|
||||
let mut output = arg.output.map(|path| {
|
||||
//TODO automatically add file extension
|
||||
let file_out = File::create(path).expect("Error opening file for writing");
|
||||
let header = PcapHeader {
|
||||
@@ -101,8 +101,8 @@ fn main() -> Result<()> {
|
||||
let file = io::BufReader::new(io::stdin());
|
||||
thread::spawn(move || tnc_loop(tx, file).unwrap());
|
||||
}
|
||||
s if Path::new(s).exists() => {
|
||||
let file = io::BufReader::new(File::open(s)?);
|
||||
path if Path::new(path).exists() => {
|
||||
let file = io::BufReader::new(File::open(path)?);
|
||||
thread::spawn(move || tnc_loop(tx, file).unwrap());
|
||||
}
|
||||
addr => {
|
||||
@@ -113,37 +113,28 @@ fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
while let Ok(pkt) = rx.recv() {
|
||||
//let time = SystemTime::now();
|
||||
//let timestamp = time.duration_since(SystemTime::UNIX_EPOCH);
|
||||
let mut s = String::new();
|
||||
for byte in pkt.data.iter() {
|
||||
//if byte >= ' '.into() && byte <= '~'.into() {
|
||||
if *byte >= 32 && *byte <= 126 {
|
||||
s.push((*byte).into());
|
||||
} else {
|
||||
s.push_str(&format!("\\{:x?} ", *byte));
|
||||
}
|
||||
}
|
||||
|
||||
if arg.verbose {
|
||||
if let Ok(frame) = Ax25Frame::from_bytes(&pkt.data[1..]) {
|
||||
if let Ok(frame) = Ax25Frame::from_bytes(&pkt.data[1..]) {
|
||||
if arg.verbose {
|
||||
frame.print_long();
|
||||
} else {
|
||||
//TODO print time stamp
|
||||
println!("{}", s);
|
||||
frame.print_short();
|
||||
}
|
||||
} else {
|
||||
if let Ok(frame) = Ax25Frame::from_bytes(&pkt.data[1..]) {
|
||||
frame.print_short();
|
||||
} else {
|
||||
//TODO print time stamp
|
||||
println!("{}", s);
|
||||
let mut s = String::new();
|
||||
for byte in pkt.data.iter() {
|
||||
if *byte >= 32 && *byte <= 126 {
|
||||
s.push((*byte).into());
|
||||
} else {
|
||||
s.push_str(&format!("\\{:x?} ", *byte));
|
||||
}
|
||||
}
|
||||
//TODO print time stamp
|
||||
println!("{}", s);
|
||||
}
|
||||
|
||||
if let Some(ref mut writer) = file {
|
||||
let pkt = PcapPacket::new_owned(pkt.timestamp, pkt.orig_len, pkt.data);
|
||||
writer.write_packet(&pkt).unwrap();
|
||||
if let Some(ref mut writer) = output {
|
||||
let pcpkt = PcapPacket::new_owned(pkt.timestamp, pkt.orig_len, pkt.data);
|
||||
writer.write_packet(&pcpkt).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user