Compare commits

...

3 commits

Author SHA1 Message Date
f232b157ef fix 2025-05-24 12:25:48 +02:00
b7eca51206 hardcode mac address 2025-05-24 12:16:30 +02:00
75ebc4907b cc 2025-04-21 20:53:44 +02:00
2 changed files with 14 additions and 20 deletions

View file

@ -6,7 +6,7 @@ COPY . .
RUN cargo build --release
FROM gcr.io/distroless/static-debian12
FROM gcr.io/distroless/cc-debian12
COPY --from=build /build/target/release/wakeonlan /app/wakeonlan

View file

@ -6,7 +6,7 @@ use axum::{
routing::{get, post},
Router,
};
use eyre::{bail, Context, ContextCompat};
use eyre::{bail, Context};
use std::net::{Ipv4Addr, ToSocketAddrs, UdpSocket};
use tracing_subscriber::EnvFilter;
@ -47,18 +47,9 @@ async fn wake() -> Response {
fn wake_inner() -> eyre::Result<()> {
let hosts = load_possible_hosts()?;
let host = hosts
.iter()
.into_iter()
.find(|(host, _)| host.contains("PC-Nora"))
.wrap_err_with(|| {
format!(
"failed to find host, found: {}",
hosts
.iter()
.map(|(host, _)| host.clone())
.collect::<Vec<_>>()
.join(",")
)
})?;
.unwrap_or_else(|| ("PC-Nora".into(), parse_mac_addr("00:d8:61:ca:3a:18")));
let magic_packet = MagicPacket::new(&host.1);
magic_packet.send().wrap_err("failed to send packet")?;
@ -67,6 +58,15 @@ fn wake_inner() -> eyre::Result<()> {
Ok(())
}
fn parse_mac_addr(addr: &str) -> [u8; 6] {
addr.split(":")
.map(|part| u8::from_str_radix(part, 16).expect("invalid mac address"))
.collect::<Vec<_>>()
.as_slice()
.try_into()
.expect("invalid mac address")
}
fn load_possible_hosts() -> eyre::Result<Vec<(String, [u8; 6])>> {
// TODO: It would be very cool to instead read /proc/net/arp and then call getnameinfo but that's annoying...
let arp = std::process::Command::new("arp")
@ -81,13 +81,7 @@ fn load_possible_hosts() -> eyre::Result<Vec<(String, [u8; 6])>> {
.skip(1)
.map(|line| line.split_whitespace().collect::<Vec<_>>())
.map(|line_parts| {
let mac = line_parts[2]
.split(":")
.map(|part| u8::from_str_radix(part, 16).expect("invalid mac address"))
.collect::<Vec<_>>()
.as_slice()
.try_into()
.expect("invalid mac address");
let mac = parse_mac_addr(line_parts[2]);
(line_parts[0].to_owned(), mac)
})
.collect())