feat: Make bind ip configurable through cli
This commit is contained in:
+5
-4
@@ -1,5 +1,5 @@
|
||||
use std::io;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::time::Duration;
|
||||
|
||||
use socket_pktinfo::{PktInfo, PktInfoUdpSocket};
|
||||
@@ -150,7 +150,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn serve<F, Fut>(callback: F) -> Result<!, Error>
|
||||
pub async fn serve<F, Fut>(ip: IpAddr, callback: F) -> Result<!, Error>
|
||||
where
|
||||
F: Fn(&str, IpAddr) -> Fut + Clone + Send + 'static,
|
||||
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
|
||||
@@ -158,12 +158,13 @@ where
|
||||
let socket = PktInfoUdpSocket::new(Domain::IPV4)?;
|
||||
socket.set_nonblocking(true)?;
|
||||
|
||||
socket.bind(&SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 69).into())?;
|
||||
let addr: SocketAddr = (ip, 69).into();
|
||||
socket.bind(&addr.into())?;
|
||||
|
||||
let async_fd = AsyncFd::new(socket)?;
|
||||
let mut buf = [0u8; PACKET_SIZE];
|
||||
|
||||
println!("Server started");
|
||||
println!("Tftp server started on {addr}");
|
||||
loop {
|
||||
let mut guard = async_fd.readable().await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user