nex_socket/udp/
config.rs

1use std::net::SocketAddr;
2
3/// Configuration options for a UDP socket.
4#[derive(Debug, Clone)]
5pub struct UdpConfig {
6    /// Address to bind. If `None`, the operating system chooses the address.
7    pub bind_addr: Option<SocketAddr>,
8
9    /// Enable address reuse (`SO_REUSEADDR`).
10    pub reuseaddr: Option<bool>,
11
12    /// Allow broadcast (`SO_BROADCAST`).
13    pub broadcast: Option<bool>,
14
15    /// Time to live value.
16    pub ttl: Option<u32>,
17
18    /// Bind to a specific interface (Linux only).
19    pub bind_device: Option<String>,
20}
21
22impl Default for UdpConfig {
23    fn default() -> Self {
24        Self {
25            bind_addr: None,
26            reuseaddr: None,
27            broadcast: None,
28            ttl: None,
29            bind_device: None,
30        }
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn udp_config_default_values() {
40        let cfg = UdpConfig::default();
41        assert!(cfg.bind_addr.is_none());
42        assert!(cfg.reuseaddr.is_none());
43        assert!(cfg.broadcast.is_none());
44        assert!(cfg.ttl.is_none());
45        assert!(cfg.bind_device.is_none());
46    }
47}