From 8b0ce4c5be044608083ada2d305bb1f17c562d5e Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 16 Aug 2018 23:00:47 -0500 Subject: [PATCH] magic: Add MagicPacket.send_to method On the off chance that the magic packet needs to be sent to a destination other than port 9 on the subnet-directed broadcast address, the `send_to` method is now available on the `MagicPacket` structure. The `send` method is retained, and now simply delegates to the `send_to` method with a hard-coded socket address. --- src/magic.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/magic.rs b/src/magic.rs index d9b3cff..0d729e8 100644 --- a/src/magic.rs +++ b/src/magic.rs @@ -13,9 +13,13 @@ impl MagicPacket { } pub fn send(&self) -> io::Result { + self.send_to("255.255.255.255:9") + } + + pub fn send_to(&self, addr: A) -> io::Result { let socket = net::UdpSocket::bind("0.0.0.0:0")?; socket.set_broadcast(true)?; - socket.connect("255.255.255.255:9")?; + socket.connect(addr)?; let buf: Vec = self.iter().collect(); socket.send(&buf[..102]) }