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"
|
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]
|
||||||
|
21
src/main.rs
21
src/main.rs
@@ -7,9 +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::UdpSocket;
|
||||||
use std::net::Ipv4Addr;
|
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> {
|
||||||
@@ -395,11 +396,19 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send UDP
|
// Send UDP
|
||||||
let uaddr = format!("{}:{}", cli.uip, cli.uport);
|
if cli.uport != 55555 {
|
||||||
let socket = UdpSocket::bind("0.0.0.0:0");
|
let uaddr = format!("{}:{}", cli.uip, cli.uport);
|
||||||
//let message = "Packet received";
|
let socket = UdpSocket::bind("0.0.0.0:0");
|
||||||
let message = &text;
|
|
||||||
let _ = socket.expect("REASON").send_to(message.as_bytes(), uaddr);
|
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.
|
// In non-debug mode, print the session line and any additional lines.
|
||||||
if !cli.debug {
|
if !cli.debug {
|
||||||
|
Reference in New Issue
Block a user