stun_rs/attributes/discovery/response_port.rs
1const RESPONSE_PORT: u16 = 0x0027;
2
3crate::common::integer_attribute!(
4 /// The response port attribute contains a port. This attribute can be
5 /// present in the Binding Request and indicates which port the Binding
6 /// Response will be sent to. For servers which support the response
7 /// port attribute, the Binding Response MUST be transmitted to the
8 /// source IP address of the Binding Request and the port contained in
9 /// response port.
10 ///
11 /// # Examples
12 ///```rust
13 /// # use stun_rs::attributes::discovery::ResponsePort;
14 /// let attr = ResponsePort::from(1234);
15 /// assert_eq!(attr, 1234);
16 ///```
17 ResponsePort,
18 RESPONSE_PORT,
19 u16,
20);
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25 use crate::StunAttribute;
26
27 #[test]
28 fn response_port_stunt_attribute() {
29 let attr = StunAttribute::ResponsePort(ResponsePort::from(1234));
30 assert!(attr.is_response_port());
31 assert!(attr.as_response_port().is_ok());
32 assert!(attr.as_error_code().is_err());
33
34 assert!(attr.attribute_type().is_comprehension_required());
35 assert!(!attr.attribute_type().is_comprehension_optional());
36
37 let dbg_fmt = format!("{:?}", attr);
38 assert_eq!("ResponsePort(ResponsePort(1234))", dbg_fmt);
39 }
40}