forked from n6cta/mwtchahrd
Pass data as JSON over UDP.
This commit is contained in:
@@ -8,6 +8,7 @@ authors = ["Chris, N6CTA <mail@n6cta.com>"]
|
||||
anyhow = "1.0"
|
||||
chrono = "0.4"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
serde_json = "1.0.145"
|
||||
socket2 = "0.5"
|
||||
|
||||
[profile.release]
|
||||
|
21
src/main.rs
21
src/main.rs
@@ -7,9 +7,10 @@ use std::convert::TryInto;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
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.
|
||||
fn validate_port(port: &str) -> Result<u16, String> {
|
||||
@@ -395,11 +396,19 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
||||
}
|
||||
|
||||
// Send UDP
|
||||
let uaddr = format!("{}:{}", cli.uip, cli.uport);
|
||||
let socket = UdpSocket::bind("0.0.0.0:0");
|
||||
//let message = "Packet received";
|
||||
let message = &text;
|
||||
let _ = socket.expect("REASON").send_to(message.as_bytes(), uaddr);
|
||||
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(),
|
||||
});
|
||||
let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr);
|
||||
}
|
||||
|
||||
// In non-debug mode, print the session line and any additional lines.
|
||||
if !cli.debug {
|
||||
|
Reference in New Issue
Block a user