Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
98da8b95d5 | ||
![]() |
7957fa7c2c | ||
![]() |
6101932b0d | ||
![]() |
8065fcc24e | ||
![]() |
3aa395dc4e |
@@ -8,6 +8,7 @@ authors = ["Chris, N6CTA <mail@n6cta.com>"]
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
serde_json = "1.0.145"
|
||||||
socket2 = "0.5"
|
socket2 = "0.5"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
44
src/main.rs
44
src/main.rs
@@ -7,7 +7,10 @@ use std::convert::TryInto;
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
/// Validate that the provided port string can be parsed into a u16 and is nonzero.
|
/// Validate that the provided port string can be parsed into a u16 and is nonzero.
|
||||||
fn validate_port(port: &str) -> Result<u16, String> {
|
fn validate_port(port: &str) -> Result<u16, String> {
|
||||||
@@ -47,6 +50,14 @@ struct Cli {
|
|||||||
/// Only monitor UI frames
|
/// Only monitor UI frames
|
||||||
#[arg(short = 'u', long, default_value_t = false)]
|
#[arg(short = 'u', long, default_value_t = false)]
|
||||||
ui_only: bool,
|
ui_only: bool,
|
||||||
|
|
||||||
|
// Send UDP to what IP address (e.g. 127.0.0.1)
|
||||||
|
#[arg(short = 'b', long, default_value_t = std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))]
|
||||||
|
uip: std::net::IpAddr,
|
||||||
|
|
||||||
|
// Send UDP to what port (e.g. 8000)
|
||||||
|
#[arg(short = 'k', long, value_parser = validate_port, default_value_t = 55555)]
|
||||||
|
uport: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a byte slice into a hex-dump string for debugging purposes.
|
/// Convert a byte slice into a hex-dump string for debugging purposes.
|
||||||
@@ -384,6 +395,22 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send UDP
|
||||||
|
if cli.uport != 55555 {
|
||||||
|
let uaddr = format!("{}:{}", cli.uip, cli.uport);
|
||||||
|
let socket = UdpSocket::bind("0.0.0.0:0");
|
||||||
|
|
||||||
|
let packet = json!({
|
||||||
|
"final_destination": &final_destination,
|
||||||
|
"source": &source,
|
||||||
|
"summary": &summary,
|
||||||
|
"text": &text,
|
||||||
|
"timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
|
||||||
|
"type": "data"
|
||||||
|
});
|
||||||
|
let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr);
|
||||||
|
}
|
||||||
|
|
||||||
// In non-debug mode, print the session line and any additional lines.
|
// In non-debug mode, print the session line and any additional lines.
|
||||||
if !cli.debug {
|
if !cli.debug {
|
||||||
print_session_line(×tamp, &source, &final_destination, &summary);
|
print_session_line(×tamp, &source, &final_destination, &summary);
|
||||||
@@ -403,7 +430,22 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
|||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let addr = format!("{}:{}", cli.ip, cli.port);
|
let addr = format!("{}:{}", cli.ip, cli.port);
|
||||||
|
let uaddr = format!("{}:{}", cli.uip, cli.uport);
|
||||||
let reconnect_delay_ms = 5000;
|
let reconnect_delay_ms = 5000;
|
||||||
|
|
||||||
|
if cli.uport != 55555 {
|
||||||
|
// Bind the client socket to any available address and port
|
||||||
|
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||||
|
println!("UDP client started at {}:{}", cli.uip, cli.uport);
|
||||||
|
// Send a message to the server
|
||||||
|
let packet = json!({
|
||||||
|
"text": "UDP client connected",
|
||||||
|
"timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
|
||||||
|
"type": "status"
|
||||||
|
});
|
||||||
|
//let message = "UDP client connected";
|
||||||
|
socket.send_to(packet.to_string().as_bytes(), uaddr)?;
|
||||||
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Connecting to AGWPE server at {addr}");
|
println!("Connecting to AGWPE server at {addr}");
|
||||||
|
Reference in New Issue
Block a user