forked from n6cta/baecun
Send simple UDP stuff.
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -1,6 +1,7 @@
|
|||||||
use clap::{Parser, ArgGroup};
|
use clap::{Parser, ArgGroup};
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::net::{IpAddr, TcpStream};
|
use std::net::{IpAddr, TcpStream};
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
|
||||||
/// Validate IP address.
|
/// Validate IP address.
|
||||||
fn validate_ip(ip: &str) -> Result<IpAddr, String> {
|
fn validate_ip(ip: &str) -> Result<IpAddr, String> {
|
||||||
@@ -108,8 +109,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Send the frame.
|
// Send the frame.
|
||||||
send_frame(&frame, &cli.ip.to_string(), cli.port)?;
|
//send_frame(&frame, &cli.ip.to_string(), cli.port)?;
|
||||||
|
//Ok(())
|
||||||
|
|
||||||
|
// Bind a UDP socket to an address; here, "0.0.0.0:0" finds a free port automatically
|
||||||
|
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||||
|
|
||||||
|
// Define the target address and port
|
||||||
|
let target_address = "report.pskreporter.info:14739";
|
||||||
|
|
||||||
|
// Send the message
|
||||||
|
socket.send_to(&frame, target_address)?;
|
||||||
|
println!("Message sent successfully.");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build 'M' frame (unproto without digipeaters).
|
/// Build 'M' frame (unproto without digipeaters).
|
||||||
@@ -175,3 +189,4 @@ fn send_frame(frame: &[u8], host: &str, port: u16) -> io::Result<()> {
|
|||||||
stream.write_all(frame)?;
|
stream.write_all(frame)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user