diff --git a/Cargo.lock b/Cargo.lock index 4a1db80..e828ff0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "c_linked_list" version = "1.1.1" @@ -182,6 +188,12 @@ dependencies = [ "vec_map", ] +[[package]] +name = "const-sha1" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d" + [[package]] name = "const_fn" version = "0.4.8" @@ -859,6 +871,19 @@ version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +[[package]] +name = "local-ip-address" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b143c6ef86e36328caa40a7578e95d1544aca8a1740235fd2b416a69441a5c7" +dependencies = [ + "libc", + "memalloc", + "neli", + "thiserror", + "windows", +] + [[package]] name = "log" version = "0.4.14" @@ -886,6 +911,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" +[[package]] +name = "memalloc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1" + [[package]] name = "memchr" version = "2.4.1" @@ -907,6 +938,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5136edda114182728ccdedb9f5eda882781f35fa6e80cc360af12a8932507f3" +[[package]] +name = "neli" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508" +dependencies = [ + "byteorder", + "libc", +] + [[package]] name = "neolink" version = "0.4.0" @@ -957,6 +998,7 @@ dependencies = [ "get_if_addrs", "indoc", "lazy_static", + "local-ip-address", "log", "md5", "nom", @@ -1753,6 +1795,33 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68088239696c06152844eadc03d262f088932cce50c67e4ace86e19d95e976fe" +dependencies = [ + "const-sha1", + "windows_gen", + "windows_macros", +] + +[[package]] +name = "windows_gen" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf583322dc423ee021035b358e535015f7fd163058a31e2d37b99a939141121d" + +[[package]] +name = "windows_macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58acfb8832e9f707f8997bd161e537a1c1f603e60a5bd9c3cf53484fdcc998f3" +dependencies = [ + "syn", + "windows_gen", +] + [[package]] name = "wyz" version = "0.2.0" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 8410ad6..37b4465 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -14,6 +14,7 @@ crossbeam-channel = "0.5.1" err-derive = "0.2" get_if_addrs = "0.5.3" lazy_static = "1.4" +local-ip-address = "0.4.4" log = { version = "0.4" } md5 = "0.7" nom = "6.1.2" diff --git a/crates/core/src/bc_protocol/connection/udpconn/discover.rs b/crates/core/src/bc_protocol/connection/udpconn/discover.rs index 44dee46..f17c805 100644 --- a/crates/core/src/bc_protocol/connection/udpconn/discover.rs +++ b/crates/core/src/bc_protocol/connection/udpconn/discover.rs @@ -1,5 +1,6 @@ use super::{aborthandle::AbortHandle, Error, Result, MTU, P2P_RELAY_HOSTNAMES, WAIT_TIME}; use crate::bcudp::{model::*, xml::*}; +use local_ip_address::local_ip; use log::*; use rand::{seq::SliceRandom, thread_rng, Rng}; use std::io::{Error as IoError, ErrorKind, Result as IoResult}; @@ -272,7 +273,7 @@ impl UdpDiscover { // It has the following stages // - Contact the p2p register: This will get the register, relay and log server ip addresses // - Register the client ip address to the register (This can probably be used for NAT holepunching if the camera - // tries to connect to us using this data, currently we don't register a real address though, just `0.0.0.0`) + // tries to connect to us using this data) // - The register will return the camera ip/port and SID // - Connect to the camera using register's provided ip/port and negotiate a cid and did // - Send a message to the reolink log server that we will connect locally @@ -300,8 +301,9 @@ impl UdpDiscover { let log_address = m2c_q_r.log; // let device_address = m2c_q_r.t; + let default_local_address = local_ip().expect("There to be a local ip"); debug!("Register address found: {:?}", register_address); - debug!("Registering this address: {:?}", local_addr); + debug!("Registering this address: {:?}", default_local_address); let local_family = if local_addr.ip().is_ipv4() { 4 } else { 6 }; let msg = BcUdp::Discovery(UdpDiscovery { @@ -310,7 +312,7 @@ impl UdpDiscover { c2r_c: Some(C2rC { uid: uid.to_string(), cli: IpPort { - ip: "10.251.254.10".to_string(), + ip: default_local_address.to_string(), port: local_port, }, relay: relay_address,