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.master
parent
9b0fb35ed5
commit
8b0ce4c5be
|
@ -13,9 +13,13 @@ impl MagicPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&self) -> io::Result<usize> {
|
pub fn send(&self) -> io::Result<usize> {
|
||||||
|
self.send_to("255.255.255.255:9")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_to<A: net::ToSocketAddrs>(&self, addr: A) -> io::Result<usize> {
|
||||||
let socket = net::UdpSocket::bind("0.0.0.0:0")?;
|
let socket = net::UdpSocket::bind("0.0.0.0:0")?;
|
||||||
socket.set_broadcast(true)?;
|
socket.set_broadcast(true)?;
|
||||||
socket.connect("255.255.255.255:9")?;
|
socket.connect(addr)?;
|
||||||
let buf: Vec<u8> = self.iter().collect();
|
let buf: Vec<u8> = self.iter().collect();
|
||||||
socket.send(&buf[..102])
|
socket.send(&buf[..102])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue