回调增加网络路由
This commit is contained in:
@@ -68,10 +68,10 @@ pub fn out_ips_parse(ips: &Vec<String>) -> Result<Vec<(u32, u32)>, String> {
|
||||
|
||||
pub fn to_ip(mask: &str) -> Result<u32, String> {
|
||||
if let Ok(m) = mask.parse::<u32>() {
|
||||
if m >= 32 {
|
||||
if m > 32 {
|
||||
return Err("not netmask".to_string());
|
||||
}
|
||||
let mut mask = 0 as u32;
|
||||
let mut mask = 0u32;
|
||||
for i in 0..m {
|
||||
mask = mask | (1 << (31 - i));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@ package top.wherewego.vnt.jni;
|
||||
* @author https://github.com/lbl8603/vnt
|
||||
*/
|
||||
public class IpUtils {
|
||||
/**
|
||||
* 将整数的ip地址转成字符串,例如 0 转成 "0.0.0.0"
|
||||
*
|
||||
* @param ipAddress
|
||||
* @return
|
||||
*/
|
||||
public static String intToIpAddress(int ipAddress) {
|
||||
|
||||
return ((ipAddress & 0xFF000000) >>> 24) + "." +
|
||||
@@ -13,6 +19,13 @@ public class IpUtils {
|
||||
((ipAddress & 0x0000FF00) >>> 8) + "." +
|
||||
(ipAddress & 0x000000FF);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回掩码的长度
|
||||
*
|
||||
* @param subnetMask
|
||||
* @return
|
||||
*/
|
||||
public static int subnetMaskToPrefixLength(int subnetMask) {
|
||||
int prefixLength = 0;
|
||||
int bit = 1 << 31;
|
||||
|
||||
@@ -176,6 +176,17 @@ impl CallBack {
|
||||
fn generate_tun0(&self, info: DeviceConfig) -> jni::errors::Result<u32> {
|
||||
let mut env = self.jvm.attach_current_thread_as_daemon()?;
|
||||
let class = unsafe { JClass::from_raw(self.device_config_class.as_raw()) };
|
||||
|
||||
let object_array = env.new_object_array(
|
||||
info.external_route.len() as _,
|
||||
"java/lang/String",
|
||||
JObject::null(),
|
||||
)?;
|
||||
for (index, (network, mask)) in info.external_route.into_iter().enumerate() {
|
||||
let param =
|
||||
env.new_string(format!("{}/{}", network, u32::from(mask).leading_ones()))?;
|
||||
env.set_object_array_element(&object_array, index as _, ¶m)?;
|
||||
}
|
||||
let param = env.new_object(
|
||||
class,
|
||||
"(IIII)V",
|
||||
@@ -184,6 +195,7 @@ impl CallBack {
|
||||
JValue::Int(Into::<u32>::into(info.virtual_netmask) as _),
|
||||
JValue::Int(Into::<u32>::into(info.virtual_gateway) as _),
|
||||
JValue::Int(Into::<u32>::into(info.virtual_network) as _),
|
||||
JValue::Object(&object_array),
|
||||
],
|
||||
)?;
|
||||
let rs = env.call_method(
|
||||
|
||||
Reference in New Issue
Block a user