From fa4cfcd7b8ae558208bb6d4e7ef3a0e7cbcb5e98 Mon Sep 17 00:00:00 2001 From: "0m.ax" Date: Sun, 20 Jul 2025 15:57:55 +0200 Subject: [PATCH] multicast --- Cargo.lock | 33 +++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 8 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 68f3f8c..09fb07b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,7 @@ dependencies = [ "libc", "nix", "png", + "socket2", ] [[package]] @@ -131,3 +132,35 @@ name = "simd-adler32" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + +[[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 index 2a394d9..5afe95d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" png = "0.17" libc = "0.2" nix = { version = "0.29", features = ["socket", "uio"] } +socket2 = "0.4.7" diff --git a/src/main.rs b/src/main.rs index 5ae3f78..b677ada 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ use std::net::{ToSocketAddrs, UdpSocket}; use std::time::Duration; use std::thread; use std::sync::{Mutex,Arc}; +use socket2::{Domain, Socket, Type}; +use std::net::{Ipv4Addr, SocketAddr}; mod color; // Constants from the C code const QUEUE_LEN: usize = 1000; @@ -323,7 +325,11 @@ fn main() { let mut frame_counter: u32 = 0; thread::spawn(move || { let bind_address = format!("0.0.0.0:12345"); - + let socket = Socket::new(Domain::IPV4, Type::DGRAM, None).unwrap(); + socket.set_reuse_address(true).unwrap(); + socket.set_nonblocking(true).unwrap(); + socket.join_multicast_v4(&Ipv4Addr::new(239, 1, 1, 1), &Ipv4Addr::new(0, 0, 0, 0)).unwrap(); + socket.bind(&"0.0.0.0:12345".parse::().unwrap().into()).unwrap(); // Bind the UDP socket to the specified address and port. let socket = match UdpSocket::bind(&bind_address) { Ok(s) => s,