aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-04-11 15:48:20 +0200
committerGitHub <[email protected]>2024-04-11 15:48:20 +0200
commitb615f6e34e084d520dcc301058b5926074188500 (patch)
treecd19ad3355949b682485f720339a856b9de3396a
parent6b05d1a437a49db98056de7b029923e8aedf1a5a (diff)
parent1777c5c91c7b37ad458b62930f20fc518ca76777 (diff)
downloadwebol-0.4.0.tar
webol-0.4.0.tar.gz
webol-0.4.0.zip
Merge pull request #34 from FxQnLr/nostartv0.4.0
Fix devices not starting
-rw-r--r--README.md1
-rw-r--r--src/routes/start.rs6
-rw-r--r--src/wol.rs23
3 files changed, 27 insertions, 3 deletions
diff --git a/README.md b/README.md
index 88f786a..03779a1 100644
--- a/README.md
+++ b/README.md
@@ -24,5 +24,6 @@ services:
24 restart: unless-stopped 24 restart: unless-stopped
25 volumes: 25 volumes:
26 - ./devices:/devices 26 - ./devices:/devices
27 - ./logs:/logs
27 network_mode: host 28 network_mode: host
28``` 29```
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 @@
1use crate::storage::Device; 1use crate::storage::Device;
2use crate::error::Error; 2use crate::error::Error;
3use crate::services::ping::Value as PingValue; 3use crate::services::ping::Value as PingValue;
4use crate::wol::send_packet; 4use crate::wol::{create_buffer, send_packet};
5use axum::extract::{Path, State}; 5use axum::extract::{Path, State};
6use axum::Json; 6use axum::Json;
7use serde::{Deserialize, Serialize}; 7use serde::{Deserialize, Serialize};
@@ -61,10 +61,10 @@ fn send_wol(
61 61
62 let bind_addr = "0.0.0.0:0"; 62 let bind_addr = "0.0.0.0:0";
63 63
64 let _ = send_packet( 64 send_packet(
65 bind_addr, 65 bind_addr,
66 &device.broadcast_addr.to_string(), 66 &device.broadcast_addr.to_string(),
67 &device.mac.bytes() 67 &create_buffer(&device.mac.to_string())?
68 )?; 68 )?;
69 let dev_id = device.id.clone(); 69 let dev_id = device.id.clone();
70 let uuid = if let Some(pl) = payload { 70 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 @@
1use std::net::{ToSocketAddrs, UdpSocket}; 1use std::net::{ToSocketAddrs, UdpSocket};
2 2
3use tracing::trace;
4
3use crate::error::Error; 5use crate::error::Error;
4 6
7/// Creates the magic packet from a mac address
8///
9/// # Panics
10///
11/// Panics if `mac_addr` is an invalid mac
12pub fn create_buffer(mac_addr: &str) -> Result<Vec<u8>, Error> {
13 let mut mac = Vec::new();
14 let sp = mac_addr.split(':');
15 for f in sp {
16 mac.push(u8::from_str_radix(f, 16)?);
17 }
18 let mut buf = vec![255; 6];
19 for _ in 0..16 {
20 for i in &mac {
21 buf.push(*i);
22 }
23 }
24 Ok(buf)
25}
26
5/// Sends a buffer on UDP broadcast 27/// Sends a buffer on UDP broadcast
6pub fn send_packet<A: ToSocketAddrs>( 28pub fn send_packet<A: ToSocketAddrs>(
7 bind_addr: A, 29 bind_addr: A,
@@ -10,5 +32,6 @@ pub fn send_packet<A: ToSocketAddrs>(
10) -> Result<usize, Error> { 32) -> Result<usize, Error> {
11 let socket = UdpSocket::bind(bind_addr)?; 33 let socket = UdpSocket::bind(bind_addr)?;
12 socket.set_broadcast(true)?; 34 socket.set_broadcast(true)?;
35 trace!(?buffer ,"start with");
13 Ok(socket.send_to(buffer, broadcast_addr)?) 36 Ok(socket.send_to(buffer, broadcast_addr)?)
14} 37}