diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-03-08 12:31:35 +0100 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-03-08 12:31:35 +0100 |
commit | 15374e0491e75c961c7311f5933e5acd0855672b (patch) | |
tree | 3fcee5fe9b4e3300dcb3c9c67dc2225e3d6bdc7f | |
download | where-rs-15374e0491e75c961c7311f5933e5acd0855672b.tar.gz where-rs-15374e0491e75c961c7311f5933e5acd0855672b.tar.bz2 where-rs-15374e0491e75c961c7311f5933e5acd0855672b.zip |
Added 13 files (automated)
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .idea/.gitignore | 8 | ||||
-rw-r--r-- | .idea/modules.xml | 8 | ||||
-rw-r--r-- | .idea/vcs.xml | 6 | ||||
-rw-r--r-- | .idea/where-rs.iml | 14 | ||||
-rw-r--r-- | Cargo.lock | 464 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | where-rs/Cargo.toml | 14 | ||||
-rw-r--r-- | where-rs/src/main.rs | 15 | ||||
-rw-r--r-- | where-shared/Cargo.toml | 9 | ||||
-rw-r--r-- | where-shared/src/lib.rs | 121 | ||||
-rw-r--r-- | whered/Cargo.toml | 9 | ||||
-rw-r--r-- | whered/src/main.rs | 23 |
13 files changed, 695 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d2b0049 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/where-rs.iml" filepath="$PROJECT_DIR$/.idea/where-rs.iml" /> + </modules> + </component> +</project>
\ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project>
\ No newline at end of file diff --git a/.idea/where-rs.iml b/.idea/where-rs.iml new file mode 100644 index 0000000..b37ad1d --- /dev/null +++ b/.idea/where-rs.iml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="EMPTY_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/where-rs/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/where-shared/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/whered/src" isTestSource="false" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..86d2aea --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,464 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata 0.1.10", +] + +[[package]] +name = "bumpalo" +version = "3.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + +[[package]] +name = "coreutils_core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d8005352bd31280d624a3fb5f0dca74023256bab70d31c1556ea6a37e66f3a" +dependencies = [ + "bstr", + "libc", + "regex", + "time", +] + +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.6", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "serde_json" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn 1.0.109", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn 1.0.109", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +dependencies = [ + "const_fn", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", +] + +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn 1.0.109", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.52", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "where-rs" +version = "0.1.0" +dependencies = [ + "coreutils_core", + "where-shared", +] + +[[package]] +name = "where-shared" +version = "0.1.0" +dependencies = [ + "coreutils_core", +] + +[[package]] +name = "whered" +version = "0.1.0" +dependencies = [ + "where-shared", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0af0e97 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +members = [ "where-rs", "whered", "where-shared"] +resolver = "2"
\ No newline at end of file diff --git a/where-rs/Cargo.toml b/where-rs/Cargo.toml new file mode 100644 index 0000000..a2722d8 --- /dev/null +++ b/where-rs/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "where-rs" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[[bin]] +name = "where" +path = "src/main.rs" + +[dependencies] +where-shared = { path = "../where-shared" } +coreutils_core = "0.1.1"
\ No newline at end of file diff --git a/where-rs/src/main.rs b/where-rs/src/main.rs new file mode 100644 index 0000000..0e23482 --- /dev/null +++ b/where-rs/src/main.rs @@ -0,0 +1,15 @@ +use std::net::UdpSocket; +use coreutils_core::ByteSlice; +use where_shared::*; + +fn main() { + let socket = UdpSocket::bind("0.0.0.0:0").expect("Could not start a UDP socket."); + socket.send_to(&WHERED_MAGIC, "127.0.0.1:15").expect("Could not send data to the server."); + + let mut buf = [0; 1024]; + socket.recv_from(&mut buf).expect("No data to receive from the server."); + + /*let list = SessionCollection::from_bytes(buf.to_vec()); + println!("{:?}", list);*/ + println!("{}", String::from_utf8_lossy(&buf)); +}
\ No newline at end of file diff --git a/where-shared/Cargo.toml b/where-shared/Cargo.toml new file mode 100644 index 0000000..1f5507b --- /dev/null +++ b/where-shared/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "where-shared" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +coreutils_core = "0.1.1"
\ No newline at end of file diff --git a/where-shared/src/lib.rs b/where-shared/src/lib.rs new file mode 100644 index 0000000..1ea21a7 --- /dev/null +++ b/where-shared/src/lib.rs @@ -0,0 +1,121 @@ +use coreutils_core::ByteSlice; +use coreutils_core::os::utmpx::UtmpxKind; + +pub const WHERED_MAGIC: [u8; 4] = *b"WHRD"; + +#[derive(Debug)] +pub struct Session { + user: String, + pid: i32, + tty: String, + remote: Option<String>, + active: bool, + login: i64 +} + +#[derive(Debug)] +pub struct SessionCollection<Session> { + inner: Vec<Session> +} + +impl SessionCollection<Session> { + pub fn fetch() -> SessionCollection<Session> { + let mut output: SessionCollection<Session> = SessionCollection { + inner: vec![] + }; + let utmp = coreutils_core::os::utmpx::UtmpxSet::system(); + + for item in utmp { + if item.entry_type() != UtmpxKind::UserProcess && item.entry_type() != UtmpxKind::DeadProcess { + continue; + } + + let host = item.host().to_string(); + + output.inner.push(Session { + user: item.user().to_string(), + pid: item.process_id(), + tty: item.device_name().to_string(), + remote: if &host == "" { + None + } else { + Some(host) + }, + active: item.entry_type() == UtmpxKind::UserProcess, + login: item.timeval().tv_sec + }); + } + + output + } + + pub fn into_bytes(self) -> Vec<u8> { + let mut bytes: Vec<u8> = vec![]; + + for item in self.inner { + bytes.append(&mut item.into_bytes().to_vec()); + bytes.append(&mut vec![0, 0, 0, 0]); + } + + bytes + } + + /*pub fn from_bytes(bytes: Vec<u8>) -> SessionCollection<Session> { + let entries = bytes.split([0, 0]); + let mut final_entries: Vec<Session> = vec![]; + + for item in entries { + let parts: Vec<&[u8]> = item.split(0).collect(); + if item.split(0).count() == 0 { + continue; + } + + /*final_entries.push(Session { + //pid: i32::from_be_bytes(parts[0].as_bytes()), + //login: i64::from_be_bytes(parts[1].as_bytes()), + pid: 0, + login: 0, + user: parts[2].to_string(), + tty: parts[3].to_string(), + remote: if parts[4] == b"\xff".to_str().unwrap() { + None + } else { + Some(parts[4].to_string()) + }, + active: parts[5] == b"\xff".to_str().unwrap() + });*/ + } + + SessionCollection { + inner: final_entries + } + }*/ +} + +impl Session { + pub fn into_bytes(self) -> Vec<u8> { + let mut bytes: Vec<u8> = vec![]; + let mut host_bytes = self.remote.clone().unwrap_or(String::from("!")).as_bytes().to_vec(); + let mut full = vec![255]; + + bytes.append(&mut self.pid.to_be_bytes().to_vec()); + bytes.append(&mut self.login.to_be_bytes().to_vec()); + bytes.append(&mut (self.user.len() as u32).to_be_bytes().to_vec()); + bytes.append(&mut self.user.as_bytes().to_vec()); + bytes.append(&mut (self.tty.len() as u32).to_be_bytes().to_vec()); + bytes.append(&mut self.tty.as_bytes().to_vec()); + bytes.append(&mut (host_bytes.len() as u32).to_be_bytes().to_vec()); + bytes.append(if let Some(_) = self.remote { + &mut host_bytes + } else { + &mut full + }); + bytes.push(if self.active { + 1 + } else { + 0 + }); + + bytes + } +}
\ No newline at end of file diff --git a/whered/Cargo.toml b/whered/Cargo.toml new file mode 100644 index 0000000..5e9d438 --- /dev/null +++ b/whered/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "whered" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +where-shared = { path = "../where-shared" }
\ No newline at end of file diff --git a/whered/src/main.rs b/whered/src/main.rs new file mode 100644 index 0000000..efc3fcc --- /dev/null +++ b/whered/src/main.rs @@ -0,0 +1,23 @@ +use std::net::UdpSocket; +use where_shared::*; + +fn main() { + let socket = UdpSocket::bind("0.0.0.0:15").expect("Could not bind to port 15, is another instance of whered running?"); + + loop { + let mut buf = [0; WHERED_MAGIC.len()]; + let Ok((_, src)) = socket.recv_from(&mut buf) else { + eprintln!("Failed to receive data from the client, ignoring"); + continue + }; + + println!("{src}: New client!"); + + let sessions = SessionCollection::fetch(); + if let Err(_) = socket.send_to(&*sessions.into_bytes(), src) { + eprintln!("{src}: Failed to send data back to the client, ignoring"); + } else { + println!("{src}: Completed request"); + } + } +}
\ No newline at end of file |