1
1
use crate :: IpAddr ;
2
2
use embedded_nal:: AddrType ;
3
- use heapless:: String ;
4
3
5
4
/// This trait is an extension trait for [`TcpStack`] and [`UdpStack`] for dns
6
5
/// resolutions. It does not handle every DNS record type, but is meant as an
@@ -24,13 +23,22 @@ pub trait Dns {
24
23
addr_type : AddrType ,
25
24
) -> Result < IpAddr , Self :: Error > ;
26
25
27
- /// Resolve the hostname of a host, given its ip address
26
+ /// Resolve the hostname of a host, given its ip address.
27
+ ///
28
+ /// The hostname is stored at the beginning of `result`, the length is returned.
29
+ ///
30
+ /// If the buffer is too small to hold the domain name, an error should be returned.
28
31
///
29
32
/// **Note**: A fully qualified domain name (FQDN), has a maximum length of
30
- /// 255 bytes [`rfc1035`]
33
+ /// 255 bytes according to [`rfc1035`]. Therefore, you can pass a 255-byte long
34
+ /// buffer to guarantee it'll always be large enough.
31
35
///
32
36
/// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
33
- async fn get_host_by_address ( & self , addr : IpAddr ) -> Result < String < 256 > , Self :: Error > ;
37
+ async fn get_host_by_address (
38
+ & self ,
39
+ addr : IpAddr ,
40
+ result : & mut [ u8 ] ,
41
+ ) -> Result < usize , Self :: Error > ;
34
42
}
35
43
36
44
impl < T : Dns > Dns for & T {
@@ -44,7 +52,11 @@ impl<T: Dns> Dns for &T {
44
52
T :: get_host_by_name ( self , host, addr_type) . await
45
53
}
46
54
47
- async fn get_host_by_address ( & self , addr : IpAddr ) -> Result < String < 256 > , Self :: Error > {
48
- T :: get_host_by_address ( self , addr) . await
55
+ async fn get_host_by_address (
56
+ & self ,
57
+ addr : IpAddr ,
58
+ result : & mut [ u8 ] ,
59
+ ) -> Result < usize , Self :: Error > {
60
+ T :: get_host_by_address ( self , addr, result) . await
49
61
}
50
62
}
0 commit comments