mirror of
				https://gitea.farpn.net/w1cdn/mwtchahrd.git
				synced 2025-11-04 05:46:36 -06:00 
			
		
		
		
	Pass data as JSON over UDP.
This commit is contained in:
		
							
								
								
									
										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