From 0ba5230d078530fe4daa79b6269675a581fda7f5 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 11 Apr 2024 15:42:55 +0200 Subject: revert removal of `create_buffer` --- src/routes/start.rs | 6 +++--- src/wol.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/routes/start.rs b/src/routes/start.rs index ae2b384..bbc6ab8 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -1,7 +1,7 @@ use crate::storage::Device; use crate::error::Error; use crate::services::ping::Value as PingValue; -use crate::wol::send_packet; +use crate::wol::{create_buffer, send_packet}; use axum::extract::{Path, State}; use axum::Json; use serde::{Deserialize, Serialize}; @@ -61,10 +61,10 @@ fn send_wol( let bind_addr = "0.0.0.0:0"; - let _ = send_packet( + send_packet( bind_addr, &device.broadcast_addr.to_string(), - &device.mac.bytes() + &create_buffer(&device.mac.to_string())? )?; let dev_id = device.id.clone(); let uuid = if let Some(pl) = payload { diff --git a/src/wol.rs b/src/wol.rs index 6392366..1176b28 100644 --- a/src/wol.rs +++ b/src/wol.rs @@ -1,7 +1,29 @@ use std::net::{ToSocketAddrs, UdpSocket}; +use tracing::trace; + use crate::error::Error; +/// Creates the magic packet from a mac address +/// +/// # Panics +/// +/// Panics if `mac_addr` is an invalid mac +pub fn create_buffer(mac_addr: &str) -> Result, Error> { + let mut mac = Vec::new(); + let sp = mac_addr.split(':'); + for f in sp { + mac.push(u8::from_str_radix(f, 16)?); + } + let mut buf = vec![255; 6]; + for _ in 0..16 { + for i in &mac { + buf.push(*i); + } + } + Ok(buf) +} + /// Sends a buffer on UDP broadcast pub fn send_packet( bind_addr: A, @@ -10,5 +32,6 @@ pub fn send_packet( ) -> Result { let socket = UdpSocket::bind(bind_addr)?; socket.set_broadcast(true)?; + trace!(?buffer ,"start with"); Ok(socket.send_to(buffer, broadcast_addr)?) } -- cgit v1.2.3 From 1777c5c91c7b37ad458b62930f20fc518ca76777 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 11 Apr 2024 15:44:08 +0200 Subject: Closes #33. logs added to example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 88f786a..03779a1 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,6 @@ services: restart: unless-stopped volumes: - ./devices:/devices + - ./logs:/logs network_mode: host ``` -- cgit v1.2.3