add windows crosscompilation
This commit is contained in:
parent
bc17ffac68
commit
8e9d179d49
12
Cargo.toml
12
Cargo.toml
@ -28,13 +28,23 @@ rayon = "1.10.0"
|
|||||||
readonly = "0.2.13"
|
readonly = "0.2.13"
|
||||||
sha2 = "0.10.9"
|
sha2 = "0.10.9"
|
||||||
smol = "2.0.2"
|
smol = "2.0.2"
|
||||||
tappers = "0.4.2"
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["winsock2", "mswsock", "minwindef"] }
|
winapi = { version = "0.3", features = ["winsock2", "mswsock", "minwindef"] }
|
||||||
|
tappers = { version = "0.4.2", features = ["wintun"] }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
tappers = "0.4.2"
|
||||||
|
|
||||||
|
[target.x86_64-pc-windows-gnu]
|
||||||
|
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
|
||||||
|
ar = "/usr/bin/x86_64-w64-mingw32-ar"
|
||||||
|
|
||||||
|
[target.i686-pc-windows-gnu]
|
||||||
|
linker = "/usr/bin/i686-w64-mingw32-gcc"
|
||||||
|
ar = "/usr/bin/i686-w64-mingw32-ar"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use std::sync::{Arc, RwLock};
|
|
||||||
|
|
||||||
use pea_2_pea::*;
|
use pea_2_pea::*;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
use tappers::Interface;
|
||||||
|
|
||||||
use crate::types::Network;
|
use crate::types::Network;
|
||||||
|
|
||||||
@ -11,15 +11,36 @@ pub fn create_tun_interface(
|
|||||||
private_ip: std::net::Ipv4Addr,
|
private_ip: std::net::Ipv4Addr,
|
||||||
if_name: Option<String>,
|
if_name: Option<String>,
|
||||||
) -> Result<tappers::Tun, std::io::Error> {
|
) -> Result<tappers::Tun, std::io::Error> {
|
||||||
let mut tun_iface: tappers::Tun = tappers::Tun::new_named(tappers::Interface::new(
|
#[cfg(not(target_os = "windows"))]
|
||||||
if_name.unwrap_or("pea0".to_owned()),
|
let mut tun_iface: tappers::Tun = tappers::Tun::new_named(Interface::new(
|
||||||
|
&if_name.unwrap_or(DEFAULT_INTERFACE_NAME.to_owned()),
|
||||||
)?)?;
|
)?)?;
|
||||||
let mut addr_req = tappers::AddAddressV4::new(private_ip);
|
#[cfg(target_os = "windows")]
|
||||||
addr_req.set_netmask(24);
|
let mut tun_iface: tappers::Tun = tappers::Tun::new()?;
|
||||||
let mut broadcast_addr_oct = private_ip.octets();
|
#[cfg(not(target_os = "windows"))]
|
||||||
broadcast_addr_oct[3] = 255;
|
{
|
||||||
addr_req.set_broadcast(std::net::Ipv4Addr::from(broadcast_addr_oct));
|
let mut addr_req = tappers::AddAddressV4::new(private_ip);
|
||||||
tun_iface.add_addr(addr_req)?;
|
addr_req.set_netmask(24);
|
||||||
|
let mut broadcast_addr_oct = private_ip.octets();
|
||||||
|
broadcast_addr_oct[3] = 255;
|
||||||
|
addr_req.set_broadcast(std::net::Ipv4Addr::from(broadcast_addr_oct));
|
||||||
|
tun_iface.add_addr(addr_req)?;
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
std::process::Command::new("netsh").args([
|
||||||
|
"interface",
|
||||||
|
"ipv4",
|
||||||
|
"set",
|
||||||
|
"address",
|
||||||
|
&format!(
|
||||||
|
"name=\"{}\"",
|
||||||
|
tun_iface.name()?.name().into_string().unwrap()
|
||||||
|
),
|
||||||
|
"static",
|
||||||
|
&private_ip.to_string(),
|
||||||
|
"255.255.255.0",
|
||||||
|
]);
|
||||||
|
|
||||||
tun_iface.set_up()?;
|
tun_iface.set_up()?;
|
||||||
return Ok(tun_iface);
|
return Ok(tun_iface);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ pub const MAPPING_SHOT_COUNT: u8 = 5;
|
|||||||
|
|
||||||
pub const DEFAULT_NETWORK_PREFIX: [u8; 3] = [172, 22, 44];
|
pub const DEFAULT_NETWORK_PREFIX: [u8; 3] = [172, 22, 44];
|
||||||
|
|
||||||
|
pub const DEFAULT_INTERFACE_NAME: &str = "pea0";
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum ServerMethods {
|
pub enum ServerMethods {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user