blob: 63923665ea79f7c6cfe01eee63ab3cf6ebced2db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
use std::net::{ToSocketAddrs, UdpSocket};
use crate::error::Error;
/// Sends a buffer on UDP broadcast
pub fn send_packet<A: ToSocketAddrs>(
bind_addr: A,
broadcast_addr: A,
buffer: &[u8],
) -> Result<usize, Error> {
let socket = UdpSocket::bind(bind_addr)?;
socket.set_broadcast(true)?;
Ok(socket.send_to(buffer, broadcast_addr)?)
}
|