优化代码

This commit is contained in:
lubeilin
2023-03-19 20:11:51 +08:00
parent d7226d8522
commit 7840f30b64
14 changed files with 174 additions and 99 deletions
+9
View File
@@ -1,3 +1,4 @@
use std::io;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use parking_lot::Mutex;
@@ -6,6 +7,14 @@ use crate::proto::message::PunchNatType;
pub mod check;
use std::net::UdpSocket;
pub fn local_ip() -> io::Result<IpAddr> {
let socket = UdpSocket::bind("0.0.0.0:0")?;
socket.connect("8.8.8.8:80")?;
let addr = socket.local_addr()?;
Ok(addr.ip())
}
#[derive(Clone)]
pub struct NatTest {